Commit 6850a4d2 by Torkel Ödegaard

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

parent ad2065af
......@@ -5,6 +5,7 @@ package main
import (
"bytes"
"crypto/md5"
"encoding/json"
"flag"
"fmt"
"io"
......@@ -24,7 +25,7 @@ var (
versionRe = regexp.MustCompile(`-[0-9]{1,3}-g[0-9a-f]{5,10}`)
goarch string
goos string
version string = "2.0.0-alpha"
version string = "v1"
race bool
workingDir string
......@@ -40,6 +41,9 @@ func main() {
log.SetFlags(0)
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")))
......@@ -69,10 +73,10 @@ func main() {
test("./pkg/...")
case "package":
//checkCleanTree()
//test("./pkg/...")
//build(".", []string{})
//buildFrontend()
checkCleanTree()
test("./pkg/...")
build(".", []string{})
buildFrontend()
createRpmAndDeb()
case "build-ui":
......@@ -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() {
packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack")
postInstallScriptPath, _ := ioutil.TempFile("", "postinstall")
......@@ -122,22 +144,23 @@ func createRpmAndDeb() {
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
rm -f $INSTALL_ROOT_DIR/current
ln -s $INSTALL_ROOT_DIR/versions/$VERSION/ $INSTALL_ROOT_DIR/current
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
ln -sfn $INSTALL_ROOT_DIR/current/scripts/init.sh /etc/init.d/grafana
fi
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
if ! id grafana >/dev/null 2>&1; then
useradd --system -U -M grafana
useradd --system -U -M grafana
fi
chown -R -L grafana:grafana $INSTALL_ROOT_DIR
chmod -R a+rX $INSTALL_ROOT_DIR
......
......@@ -4,7 +4,7 @@
"company": "Coding Instinct AB"
},
"name": "grafana",
"version": "2.0.0-alpha",
"version": "2.0.2-alpha",
"repository": {
"type": "git",
"url": "http://github.com/torkelo/grafana.git"
......
......@@ -17,9 +17,9 @@
DAEMON_NAME="grafana"
DAEMON_USER="grafana"
DAEMON_PATH="%BIN_PATH%"
DAEMON_PATH="/opt/grafana/current/grafana"
DAEMON_OPTS="web"
DAEMON_PWD="/opt/grafana"
DAEMON_PWD="/opt/grafana/current"
DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
DAEMON_NICE=0
DAEMON_LOG='/var/log/grafana/grafana.log'
......@@ -43,7 +43,7 @@ do_start() {
--nicelevel $DAEMON_NICE \
--chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \
--exec "${DAEMON_PATH}" -- -c $DAEMON_OPTS
--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$?
else
start-stop-daemon --start --quiet --oknodo --background \
......@@ -51,7 +51,7 @@ do_start() {
--chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \
--chuid "${DAEMON_USER}" \
--exec "${DAEMON_PATH}" -- -c ${DAEMON_OPTS}
--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$?
fi
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