Commit 6850a4d2 by Torkel Ödegaard

Progress on deb and rpm packaging, init.d script etc, #1476

parent ad2065af
...@@ -5,6 +5,7 @@ package main ...@@ -5,6 +5,7 @@ package main
import ( import (
"bytes" "bytes"
"crypto/md5" "crypto/md5"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"io" "io"
...@@ -24,7 +25,7 @@ var ( ...@@ -24,7 +25,7 @@ var (
versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`) versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`)
goarch string goarch string
goos string goos string
version string = "2.0.0-alpha" version string = "v1"
race bool race bool
workingDir string workingDir string
...@@ -40,6 +41,9 @@ func main() { ...@@ -40,6 +41,9 @@ func main() {
log.SetFlags(0) log.SetFlags(0)
ensureGoPath() ensureGoPath()
readVersionFromPackageJson()
log.Printf("Version: %s\n", version)
//os.Setenv("PATH", fmt.Sprintf("%s%cbin%c%s", os.Getenv("GOPATH"), os.PathSeparator, os.PathListSeparator, os.Getenv("PATH"))) //os.Setenv("PATH", fmt.Sprintf("%s%cbin%c%s", os.Getenv("GOPATH"), os.PathSeparator, os.PathListSeparator, os.Getenv("PATH")))
...@@ -69,10 +73,10 @@ func main() { ...@@ -69,10 +73,10 @@ func main() {
test("./pkg/...") test("./pkg/...")
case "package": case "package":
//checkCleanTree() checkCleanTree()
//test("./pkg/...") test("./pkg/...")
//build(".", []string{}) build(".", []string{})
//buildFrontend() buildFrontend()
createRpmAndDeb() createRpmAndDeb()
case "build-ui": case "build-ui":
...@@ -86,6 +90,24 @@ func main() { ...@@ -86,6 +90,24 @@ func main() {
} }
} }
func readVersionFromPackageJson() {
reader, err := os.Open("package.json")
if err != nil {
log.Fatal("Failed to open package.json")
return
}
defer reader.Close()
jsonObj := map[string]interface{}{}
jsonParser := json.NewDecoder(reader)
if err := jsonParser.Decode(&jsonObj); err != nil {
log.Fatal("Failed to decode package.json")
}
version = jsonObj["version"].(string)
}
func createRpmAndDeb() { func createRpmAndDeb() {
packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack") packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack")
postInstallScriptPath, _ := ioutil.TempFile("", "postinstall") postInstallScriptPath, _ := ioutil.TempFile("", "postinstall")
...@@ -122,22 +144,23 @@ func createRpmAndDeb() { ...@@ -122,22 +144,23 @@ func createRpmAndDeb() {
func GeneratePostInstallScript(path string) { func GeneratePostInstallScript(path string) {
content := ` content := `
rm -f $INSTALL_ROOT_DIR/grafana rm -f $INSTALL_ROOT_DIR/current
rm -f $INSTALL_ROOT_DIR/init.sh ln -s $INSTALL_ROOT_DIR/versions/$VERSION/ $INSTALL_ROOT_DIR/current
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 if [ ! -L /etc/init.d/grafana ]; then
ln -sfn $INSTALL_ROOT_DIR/init.sh /etc/init.d/grafana ln -sfn $INSTALL_ROOT_DIR/current/scripts/init.sh /etc/init.d/grafana
chmod +x /etc/init.d/grafana fi
if which update-rc.d > /dev/null 2>&1 ; then
update-rc.d -f grafana remove chmod +x /etc/init.d/grafana
update-rc.d grafana defaults if which update-rc.d > /dev/null 2>&1 ; then
else update-rc.d -f grafana remove
chkconfig --add grafana update-rc.d grafana defaults
fi else
chkconfig --add grafana
fi fi
if ! id grafana >/dev/null 2>&1; then if ! id grafana >/dev/null 2>&1; then
useradd --system -U -M grafana useradd --system -U -M grafana
fi fi
chown -R -L grafana:grafana $INSTALL_ROOT_DIR chown -R -L grafana:grafana $INSTALL_ROOT_DIR
chmod -R a+rX $INSTALL_ROOT_DIR chmod -R a+rX $INSTALL_ROOT_DIR
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"company": "Coding Instinct AB" "company": "Coding Instinct AB"
}, },
"name": "grafana", "name": "grafana",
"version": "2.0.0-alpha", "version": "2.0.2-alpha",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "http://github.com/torkelo/grafana.git" "url": "http://github.com/torkelo/grafana.git"
......
...@@ -17,9 +17,9 @@ ...@@ -17,9 +17,9 @@
DAEMON_NAME="grafana" DAEMON_NAME="grafana"
DAEMON_USER="grafana" DAEMON_USER="grafana"
DAEMON_PATH="%BIN_PATH%" DAEMON_PATH="/opt/grafana/current/grafana"
DAEMON_OPTS="web" DAEMON_OPTS="web"
DAEMON_PWD="/opt/grafana" DAEMON_PWD="/opt/grafana/current"
DAEMON_PID="/var/run/${DAEMON_NAME}.pid" DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
DAEMON_NICE=0 DAEMON_NICE=0
DAEMON_LOG='/var/log/grafana/grafana.log' DAEMON_LOG='/var/log/grafana/grafana.log'
...@@ -43,7 +43,7 @@ do_start() { ...@@ -43,7 +43,7 @@ do_start() {
--nicelevel $DAEMON_NICE \ --nicelevel $DAEMON_NICE \
--chdir "${DAEMON_PWD}" \ --chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \ --pidfile "${DAEMON_PID}" --make-pidfile \
--exec "${DAEMON_PATH}" -- -c $DAEMON_OPTS --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$? result=$?
else else
start-stop-daemon --start --quiet --oknodo --background \ start-stop-daemon --start --quiet --oknodo --background \
...@@ -51,7 +51,7 @@ do_start() { ...@@ -51,7 +51,7 @@ do_start() {
--chdir "${DAEMON_PWD}" \ --chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \ --pidfile "${DAEMON_PID}" --make-pidfile \
--chuid "${DAEMON_USER}" \ --chuid "${DAEMON_USER}" \
--exec "${DAEMON_PATH}" -- -c ${DAEMON_OPTS} --exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$? result=$?
fi fi
log_end_msg $result log_end_msg $result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment