diff --git a/build.go b/build.go index fc46a9fd4d5..a4a1f0fa0f8 100644 --- a/build.go +++ b/build.go @@ -8,10 +8,10 @@ import ( "flag" "fmt" "io" + "io/ioutil" "log" "os" "os/exec" - "path" "path/filepath" "regexp" "runtime" @@ -27,6 +27,10 @@ var ( version string = "2.0.0-alpha" race bool workingDir string + + installRoot = "/opt/grafana" + configRoot = "/etc/grafana" + grafanaLogDir = "/var/log/grafana" ) const minGoVersion = 1.3 @@ -35,15 +39,7 @@ func main() { log.SetOutput(os.Stdout) log.SetFlags(0) - if os.Getenv("GOPATH") == "" { - cwd, err := os.Getwd() - if err != nil { - log.Fatal(err) - } - gopath := filepath.Clean(filepath.Join(cwd, "../../../../")) - log.Println("GOPATH is", gopath) - os.Setenv("GOPATH", gopath) - } + ensureGoPath() //os.Setenv("PATH", fmt.Sprintf("%s%cbin%c%s", os.Getenv("GOPATH"), os.PathSeparator, os.PathListSeparator, os.Getenv("PATH"))) @@ -73,8 +69,11 @@ func main() { test("./pkg/...") case "package": - test("./pkg/...") - build(".", []string{}) + //checkCleanTree() + //test("./pkg/...") + //build(".", []string{}) + //buildFrontend() + createRpmAndDeb() case "build-ui": buildFrontend() @@ -87,17 +86,102 @@ func main() { } } +func createRpmAndDeb() { + packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack") + postInstallScriptPath, _ := ioutil.TempFile("", "postinstall") + + versionFolder := filepath.Join(packageRoot, installRoot, "versions", version) + runError("mkdir", "-p", versionFolder) + runError("mkdir", "-p", filepath.Join(packageRoot, configRoot)) + + runError("cp", "-a", filepath.Join(workingDir, "tmp")+"/.", versionFolder) + + fmt.Printf("PackageDir: %v\n", versionFolder) + + GeneratePostInstallScript(postInstallScriptPath.Name()) + fmt.Printf("script_path: %v\n", postInstallScriptPath.Name()) + + args := []string{ + "-s", "dir", + "-t", "deb", + "--description", "Grafana", + "-C", packageRoot, + "--vendor", "Grafana", + "--url", "http://grafana.org", + "--license", "Apache 2.0", + "--maintainer", "contact@grafana.org", + "--after-install", postInstallScriptPath.Name(), + "--name", "grafana", + "--version", version, + "-p", "./dist", + ".", + } + + runPrint("fpm", args...) +} + +func GeneratePostInstallScript(path string) { + content := ` +rm -f $INSTALL_ROOT_DIR/grafana +rm -f $INSTALL_ROOT_DIR/init.sh +ln -s $INSTALL_ROOT_DIR/versions/$VERSION/grafana $INSTALL_ROOT_DIR/grafana +ln -s $INSTALL_ROOT_DIR/versions/$VERSION/scripts/init.sh $INSTALL_ROOT_DIR/init.sh +if [ ! -L /etc/init.d/grafana ]; then + ln -sfn $INSTALL_ROOT_DIR/init.sh /etc/init.d/grafana + chmod +x /etc/init.d/grafana + if which update-rc.d > /dev/null 2>&1 ; then + update-rc.d -f grafana remove + update-rc.d grafana defaults + else + chkconfig --add grafana + fi +fi +if ! id grafana >/dev/null 2>&1; then + useradd --system -U -M grafana +fi +chown -R -L grafana:grafana $INSTALL_ROOT_DIR +chmod -R a+rX $INSTALL_ROOT_DIR +mkdir -p $GRAFANA_LOG_DIR +chown -R -L grafana:grafana $GRAFANA_LOG_DIR +` + content = strings.Replace(content, "$INSTALL_ROOT_DIR", installRoot, -1) + content = strings.Replace(content, "$VERSION", version, -1) + content = strings.Replace(content, "$GRAFANA_LOG_DIR", grafanaLogDir, -1) + ioutil.WriteFile(path, []byte(content), 0644) +} + +func checkCleanTree() { + rs, err := runError("git", "ls-files", "--modified") + if err != nil { + log.Fatalf("Failed to check if git tree was clean, %v, %v\n", string(rs), err) + return + } + count := len(string(rs)) + if count > 0 { + log.Fatalf("Git repository has modified files, aborting") + } + + log.Fatalf("Git repository is clean") +} + +func ensureGoPath() { + if os.Getenv("GOPATH") == "" { + cwd, err := os.Getwd() + if err != nil { + log.Fatal(err) + } + gopath := filepath.Clean(filepath.Join(cwd, "../../../../")) + log.Println("GOPATH is", gopath) + os.Setenv("GOPATH", gopath) + } +} + func ChangeWorkingDir(dir string) { os.Chdir(dir) } func buildFrontend() { - ChangeWorkingDir(path.Join(workingDir, "grafana")) - defer func() { - ChangeWorkingDir(path.Join(workingDir, "../")) - }() - - runPrint("grunt") + runPrint("grunt", "release") } func setup() { diff --git a/docker/debtest/Dockerfile b/docker/debtest/Dockerfile new file mode 100644 index 00000000000..30c5f3d08c9 --- /dev/null +++ b/docker/debtest/Dockerfile @@ -0,0 +1,4 @@ +FROM debian:jessie + +ADD *.deb /tmp/ + diff --git a/docker/debtest/build.sh b/docker/debtest/build.sh new file mode 100755 index 00000000000..8c2a289de61 --- /dev/null +++ b/docker/debtest/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +cp Dockerfile ../../dist +cd ../../dist + +docker build --tag "grafana/debtest" . + +rm Dockerfile + +docker run -i -t grafana/debtest /bin/bash diff --git a/pkg/util/encoding_test.go b/pkg/util/encoding_test.go index 720d9f5be1a..afe299f9f92 100644 --- a/pkg/util/encoding_test.go +++ b/pkg/util/encoding_test.go @@ -11,6 +11,6 @@ func TestEncoding(t *testing.T) { Convey("When generating base64 header", t, func() { result := GetBasicAuthHeader("grafana", "1234") - So(result, ShouldEqual, "Z3JhZmFuYToxMjM0") + So(result, ShouldEqual, "Basic Z3JhZmFuYToxMjM0") }) } diff --git a/scripts/init.sh b/scripts/init.sh new file mode 100644 index 00000000000..dc0843ea5ac --- /dev/null +++ b/scripts/init.sh @@ -0,0 +1,108 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: grafana +# Required-Start: $local_fs $remote_fs $network +# Required-Stop: $local_fs $remote_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Starts grafana at startup +# Description: Starts grafana at startup +### END INIT INFO + + +# Documentation available at +# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html +# Debian provides some extra functions though +. /lib/lsb/init-functions + +DAEMON_NAME="grafana" +DAEMON_USER="grafana" +DAEMON_PATH="%BIN_PATH%" +DAEMON_OPTS="web" +DAEMON_PWD="/opt/grafana" +DAEMON_PID="/var/run/${DAEMON_NAME}.pid" +DAEMON_NICE=0 +DAEMON_LOG='/var/log/grafana/grafana.log' + +[ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}" + +do_start() { + local result + + pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null + if [ $? -eq 0 ]; then + log_warning_msg "${DAEMON_NAME} is already started" + result=0 + else + log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}" + touch "${DAEMON_LOG}" + chown $DAEMON_USER "${DAEMON_LOG}" + chmod u+rw "${DAEMON_LOG}" + if [ -z "${DAEMON_USER}" ]; then + start-stop-daemon --start --quiet --oknodo --background \ + --nicelevel $DAEMON_NICE \ + --chdir "${DAEMON_PWD}" \ + --pidfile "${DAEMON_PID}" --make-pidfile \ + --exec "${DAEMON_PATH}" -- -c $DAEMON_OPTS + result=$? + else + start-stop-daemon --start --quiet --oknodo --background \ + --nicelevel $DAEMON_NICE \ + --chdir "${DAEMON_PWD}" \ + --pidfile "${DAEMON_PID}" --make-pidfile \ + --chuid "${DAEMON_USER}" \ + --exec "${DAEMON_PATH}" -- -c ${DAEMON_OPTS} + result=$? + fi + log_end_msg $result + fi + return $result +} + +do_stop() { + local result + + pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null + if [ $? -ne 0 ]; then + log_warning_msg "${DAEMON_NAME} is not started" + result=0 + else + log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}" + killproc -p "${DAEMON_PID}" "${DAEMON_PATH}" + result=$? + log_end_msg $result + rm "${DAEMON_PID}" + fi + return $result +} + +do_restart() { + local result + do_stop + result=$? + if [ $result = 0 ]; then + do_start + result=$? + fi + return $result +} + +do_status() { + local result + status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}" + result=$? + return $result +} + +do_usage() { + echo $"Usage: $0 {start | stop | restart | status}" + exit 1 +} + +case "$1" in +start) do_start; exit $? ;; +stop) do_stop; exit $? ;; +restart) do_restart; exit $? ;; +status) do_status; exit $? ;; +*) do_usage; exit 1 ;; +esac diff --git a/src/app/plugins/datasource/influxdb_08/partials/config.html b/src/app/plugins/datasource/influxdb_08/partials/config.html index b261ae7f79c..d7c5d165044 100644 --- a/src/app/plugins/datasource/influxdb_08/partials/config.html +++ b/src/app/plugins/datasource/influxdb_08/partials/config.html @@ -1,4 +1,4 @@ -

InfluxDB Details

+
InfluxDB Details
-
-
-
-
@@ -25,10 +14,16 @@
diff --git a/tasks/build_task.js b/tasks/build_task.js index 1f6e072603a..e8c81ac8f82 100644 --- a/tasks/build_task.js +++ b/tasks/build_task.js @@ -43,7 +43,7 @@ module.exports = function(grunt) { }); grunt.config('copy.backend_files', { expand: true, - src: ['conf/grafana.ini', 'vendor/**/*'], + src: ['conf/grafana.ini', 'vendor/**/*', 'scripts/*'], options: { mode: true}, dest: '<%= tempDir %>' });