diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..adae94a --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,67 @@ +# Maintainer: Carsten Feuls +# Contributor: Gilles Hamel + +pkgname=grafana +pkgver=2.6.0 +pkgrel=2 +pkgdesc="A general purpose dashboard and graph composer. It supports graphite, influxdb or opentsdb" +url="http://grafana.org" +arch=('x86_64' 'i686' 'armv5h' 'armv6h' 'armv7h') +license=('APACHE') +depends=() +makedepends=("git" "go" "godep" "nodejs-grunt-cli" "npm" "phantomjs") +install=${pkgname}.install +backup=("etc/${pkgname}/${pkgname}.ini") +source=("${pkgname}-${pkgver}.tar.gz::https://github.com/${pkgname}/${pkgname}/archive/v${pkgver}.tar.gz" + "config.patch" + "suburl.patch" + "grafana.service") +sha512sums=('1690e690fceb3107fc9f88b9da732a6ebea43e404c94afa12fab5c186c06161f09bb3f93ca7f6dee15ac1129baca8c40fd822a090178b468cae2fa0e062ef267' + 'e2359ecbc64ba6e54a261101f9fdf05f364a9df4fe60ba6658f3cf75ea86b80da7b159d4f9e7e3f8f8b64a5d89b36daa6024b82e3ca2097177670838868caedb' + '2e40d48689eb63a6003fa9ca506835cce90e90b01dabd4f39b39e007e327539516e11793ab32bc47772fa2a6eb8c43959f8d9c44084f7347e9d783e41b1c24fa' + '2fdb8eda4671a81cc7674f471a20f37cd2078123838a80c3906777da3b6a8602caf5bcb65a23038a67b70f556d43cd8db7982a8dc7f3ee317ce1634e4c7409f7') + +prepare () { + cd "${pkgname}-${pkgver}" + patch -p1 -i "${srcdir}"/config.patch + patch -p1 -i "${srcdir}"/suburl.patch +} + +build() { + export GOPATH="${srcdir}"/${pkgname}-${pkgver} + export PATH="$PATH:$GOPATH/bin" + cd "$GOPATH" + go run build.go setup + godep restore + mkdir -p "$GOPATH/src/github.com/grafana/grafana/" + if [[ -h "$GOPATH/pkg" ]] ; then + ln -s "$GOPATH/pkg" "$GOPATH/src/github.com/grafana/grafana/" + fi + + # Build frontend assets + npm install + # Install phantomjs in this directory as well for some reason. Can be removed after next patch: https://github.com/grafana/grafana/issues/2999 + cd node_modules/karma-phantomjs-launcher + npm install + cd "$GOPATH" + grunt --force + grunt build --force + grunt build-post-process --force + + # build the backend + # no longer doing package build since this just kicks off rpm/deb builds at the end. + #go run build.go build package + go run build.go build +} + +package() { + install -Dm644 "${srcdir}/grafana.service" "$pkgdir/usr/lib/systemd/system/grafana.service" + cd "${srcdir}/${pkgname}-${pkgver}" + install -dm755 "${pkgdir}/var/lib/grafana" + install -dm755 "${pkgdir}/var/log/grafana" + install -Dsm755 bin/grafana-server "$pkgdir/usr/bin/grafana-server" + install -Dm644 conf/sample.ini "$pkgdir/etc/${pkgname}/${pkgname}.ini" + install -Dm644 conf/defaults.ini "$pkgdir/usr/share/grafana/conf/defaults.ini" + cp -r vendor "$pkgdir/usr/share/grafana/" + cp -r public_gen "$pkgdir/usr/share/grafana/public" +} diff --git a/config.patch b/config.patch new file mode 100644 index 0000000..5a757d4 --- /dev/null +++ b/config.patch @@ -0,0 +1,49 @@ +diff --git a/conf/defaults.ini b/conf/defaults.ini +index 258a019..6a7bd6b 100644 +--- a/conf/defaults.ini ++++ b/conf/defaults.ini +@@ -9,11 +9,11 @@ app_mode = production + [paths] + # Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used) + # +-data = data ++data = /var/lib/grafana + # + # Directory where grafana can store logs + # +-logs = data/log ++logs = /var/log/grafana + + #################################### Server #################################### + [server] +@@ -40,7 +40,7 @@ root_url = %(protocol)s://%(domain)s:%(http_port)s/ + router_logging = false + + # the path relative working path +-static_root_path = public ++static_root_path = /usr/share/grafana/public + + # enable gzip + enable_gzip = false +@@ -62,7 +62,7 @@ password = + ssl_mode = disable + + # For "sqlite3" only, path relative to data_path setting +-path = grafana.db ++path = /var/lib/grafana/grafana.db + + #################################### Session #################################### + [session] +diff --git a/pkg/components/renderer/renderer.go b/pkg/components/renderer/renderer.go +index 9d5ddd0..aa0aa9e 100644 +--- a/pkg/components/renderer/renderer.go ++++ b/pkg/components/renderer/renderer.go +@@ -21,7 +21,7 @@ type RenderOpts struct { + + func RenderToPng(params *RenderOpts) (string, error) { + log.Info("PhantomRenderer::renderToPng url %v", params.Url) +- binPath, _ := filepath.Abs(filepath.Join(setting.PhantomDir, "phantomjs")) ++ binPath := "/usr/bin/phantomjs" + scriptPath, _ := filepath.Abs(filepath.Join(setting.PhantomDir, "render.js")) + pngPath, _ := filepath.Abs(filepath.Join(setting.ImagesDir, util.GetRandomString(20))) + pngPath = pngPath + ".png" diff --git a/grafana.install b/grafana.install new file mode 100644 index 0000000..f6ef82a --- /dev/null +++ b/grafana.install @@ -0,0 +1,13 @@ +post_install() { + getent group grafana >/dev/null || groupadd -r grafana + getent passwd grafana >/dev/null || useradd -d /var/lib/grafana -g grafana -r -M -s /bin/false grafana + chown grafana:grafana /var/{lib,log}/grafana +} + +post_upgrade() { + post_install +} + +post_remove() { + userdel grafana +} diff --git a/grafana.service b/grafana.service new file mode 100644 index 0000000..38e720f --- /dev/null +++ b/grafana.service @@ -0,0 +1,15 @@ +[Unit] +Description=Grafana service +After=network.target + +[Service] +User=grafana +Group=grafana +WorkingDirectory=/usr/share/grafana +ExecStart=/usr/bin/grafana-server --config=/etc/grafana/grafana.ini +LimitNOFILE=10000 +TimeoutStopSec=20 +SuccessExitStatus=0 2 + +[Install] +WantedBy=multi-user.target diff --git a/suburl.patch b/suburl.patch new file mode 100644 index 0000000..a2731cb --- /dev/null +++ b/suburl.patch @@ -0,0 +1,12 @@ +diff --git a/pkg/cmd/web.go b/pkg/cmd/web.go +--- a/pkg/cmd/web.go 2016-03-01 22:46:57.283660234 +0900 ++++ b/pkg/cmd/web.go 2016-03-01 22:48:51.946372386 +0900 +@@ -20,7 +20,7 @@ + func newMacaron() *macaron.Macaron { + macaron.Env = setting.Env + m := macaron.New() +- ++ m.SetURLPrefix(setting.AppSubUrl) + m.Use(middleware.Logger()) + m.Use(macaron.Recovery()) +