mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
More deb & rpm work, systemd testing
This commit is contained in:
parent
96ee1c17a3
commit
9c2040aa9b
43
build.go
43
build.go
@ -28,10 +28,6 @@ var (
|
|||||||
version string = "v1"
|
version string = "v1"
|
||||||
race bool
|
race bool
|
||||||
workingDir string
|
workingDir string
|
||||||
|
|
||||||
installRoot = "/opt/grafana"
|
|
||||||
configRoot = "/etc/grafana"
|
|
||||||
grafanaLogDir = "/var/log/grafana"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const minGoVersion = 1.3
|
const minGoVersion = 1.3
|
||||||
@ -74,7 +70,8 @@ func main() {
|
|||||||
case "package":
|
case "package":
|
||||||
//verifyGitRepoIsClean()
|
//verifyGitRepoIsClean()
|
||||||
//grunt("release", "--pkgVer="+version)
|
//grunt("release", "--pkgVer="+version)
|
||||||
createRpmAndDeb()
|
createPackage("deb", "default")
|
||||||
|
createPackage("rpm", "sysconfig")
|
||||||
|
|
||||||
case "latest":
|
case "latest":
|
||||||
makeLatestDistCopies()
|
makeLatestDistCopies()
|
||||||
@ -112,11 +109,17 @@ func readVersionFromPackageJson() {
|
|||||||
version = jsonObj["version"].(string)
|
version = jsonObj["version"].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRpmAndDeb() {
|
func createPackage(packageType string, defaultPath string) {
|
||||||
|
installRoot := "/opt/grafana"
|
||||||
|
configRoot := "/etc/grafana"
|
||||||
|
|
||||||
packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack")
|
packageRoot, _ := ioutil.TempDir("", "grafana-linux-pack")
|
||||||
afterInstallScript, _ := filepath.Abs("./packaging/deb/control/postinst")
|
packageConfDir := filepath.Join("packaging", packageType)
|
||||||
initdscript, _ := filepath.Abs("./packaging/deb/init.d/grafana")
|
|
||||||
defaultScript, _ := filepath.Abs("./packaging/deb/default/grafana")
|
afterInstallScript := filepath.Join(packageConfDir, "control/postinst")
|
||||||
|
initdscript := filepath.Join(packageConfDir, "init.d/grafana")
|
||||||
|
defaultScript := filepath.Join(packageConfDir, defaultPath, "grafana")
|
||||||
|
systemdServiceFile := filepath.Join(packageConfDir, "systemd/grafana.service")
|
||||||
|
|
||||||
packageInstallRoot := filepath.Join(packageRoot, installRoot)
|
packageInstallRoot := filepath.Join(packageRoot, installRoot)
|
||||||
configDir := filepath.Join(packageRoot, configRoot)
|
configDir := filepath.Join(packageRoot, configRoot)
|
||||||
@ -124,17 +127,20 @@ func createRpmAndDeb() {
|
|||||||
runError("mkdir", "-p", packageInstallRoot)
|
runError("mkdir", "-p", packageInstallRoot)
|
||||||
runError("mkdir", "-p", configDir)
|
runError("mkdir", "-p", configDir)
|
||||||
runError("mkdir", "-p", filepath.Join(packageRoot, "/etc/init.d"))
|
runError("mkdir", "-p", filepath.Join(packageRoot, "/etc/init.d"))
|
||||||
runError("mkdir", "-p", filepath.Join(packageRoot, "/etc/default"))
|
runError("mkdir", "-p", filepath.Join(packageRoot, "/etc/", defaultPath))
|
||||||
|
runError("mkdir", "-p", filepath.Join(packageRoot, "/usr/lib/systemd/system"))
|
||||||
// copy sample ini file to /etc/opt/grafana
|
|
||||||
configFile := filepath.Join(configDir, "grafana.ini")
|
|
||||||
runError("cp", "conf/sample.ini", configFile)
|
|
||||||
|
|
||||||
// copy init.d script
|
// copy init.d script
|
||||||
runError("cp", "-p", initdscript, filepath.Join(packageRoot, "/etc/init.d/grafana"))
|
runError("cp", "-p", initdscript, filepath.Join(packageRoot, "/etc/init.d/grafana"))
|
||||||
runError("cp", "-p", defaultScript, filepath.Join(packageRoot, "/etc/default/grafana"))
|
// copy environment file
|
||||||
|
runError("cp", "-p", defaultScript, filepath.Join(packageRoot, "etc", defaultPath, "grafana"))
|
||||||
|
// copy systemd file
|
||||||
|
runError("cp", "-p", systemdServiceFile, filepath.Join(packageRoot, "/usr/lib/systemd/system/grafana.service"))
|
||||||
// copy release files
|
// copy release files
|
||||||
runError("cp", "-a", filepath.Join(workingDir, "tmp")+"/.", packageInstallRoot)
|
runError("cp", "-a", filepath.Join(workingDir, "tmp")+"/.", packageInstallRoot)
|
||||||
|
// copy sample ini file to /etc/opt/grafana
|
||||||
|
configFile := filepath.Join(configDir, "grafana.ini")
|
||||||
|
runError("cp", "conf/sample.ini", configFile)
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-s", "dir",
|
"-s", "dir",
|
||||||
@ -153,11 +159,8 @@ func createRpmAndDeb() {
|
|||||||
".",
|
".",
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Creating debian package")
|
fmt.Println("Creating package: ", packageType)
|
||||||
runPrint("fpm", append([]string{"-t", "deb"}, args...)...)
|
runPrint("fpm", append([]string{"-t", packageType}, args...)...)
|
||||||
|
|
||||||
fmt.Println("Creating redhat/centos package")
|
|
||||||
runPrint("fpm", append([]string{"-t", "rpm"}, args...)...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyGitRepoIsClean() {
|
func verifyGitRepoIsClean() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM centos:6.6
|
FROM centos:7.0
|
||||||
|
|
||||||
RUN yum install -y initscripts
|
RUN yum install -y initscripts
|
||||||
|
|
||||||
|
@ -5,21 +5,16 @@ Wants=network-online.target
|
|||||||
After=network-online.target
|
After=network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
EnvironmentFile=/etc/default/elasticsearch
|
EnvironmentFile=/etc/default/grafana
|
||||||
User=elasticsearch
|
User=grafana
|
||||||
Group=elasticsearch
|
Group=grafana
|
||||||
ExecStart=/usr/share/elasticsearch/bin/elasticsearch \
|
Type=simple
|
||||||
-Des.default.config=$CONF_FILE \
|
ExecStart=/opt/grafana/bin/grafana \
|
||||||
-Des.default.path.home=$ES_HOME \
|
--config=$CONF_FILE \
|
||||||
-Des.default.path.logs=$LOG_DIR \
|
--default-log-path=$LOG_DIR \
|
||||||
-Des.default.path.data=$DATA_DIR \
|
--default-path-data=$DATA_DIR \
|
||||||
-Des.default.path.work=$WORK_DIR \
|
|
||||||
-Des.default.path.conf=$CONF_DIR
|
LimitNOFILE=10000
|
||||||
# See MAX_OPEN_FILES in sysconfig
|
|
||||||
LimitNOFILE=65535
|
|
||||||
# See MAX_LOCKED_MEMORY in sysconfig, use "infinity" when MAX_LOCKED_MEMORY=unlimited and using bootstrap.mlockall: true
|
|
||||||
#LimitMEMLOCK=infinity
|
|
||||||
# Shutdown delay in seconds, before process is tried to be killed with KILL (if configured)
|
|
||||||
TimeoutStopSec=20
|
TimeoutStopSec=20
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
0
packaging/rpm/control/postinst
Normal file
0
packaging/rpm/control/postinst
Normal file
158
packaging/rpm/init.d/grafana
Executable file
158
packaging/rpm/init.d/grafana
Executable file
@ -0,0 +1,158 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
# chkconfig: 2345 80 05
|
||||||
|
# description: Grafana web server & backend
|
||||||
|
# processname: grafana
|
||||||
|
# config: /etc/grafana/grafana.ini
|
||||||
|
# pidfile: /var/run/grafana.pid
|
||||||
|
|
||||||
|
### BEGIN INIT INFO
|
||||||
|
# Provides: grafana
|
||||||
|
# Required-Start: $all
|
||||||
|
# Required-Stop: $remote_fs $syslog
|
||||||
|
# Default-Start: 2 3 4 5
|
||||||
|
# Default-Stop: 0 1 6
|
||||||
|
# Short-Description: Start grafana at boot time
|
||||||
|
### END INIT INFO
|
||||||
|
|
||||||
|
# tested on
|
||||||
|
# 1. New lsb that define start-stop-daemon
|
||||||
|
# 3. Centos with initscripts package installed
|
||||||
|
|
||||||
|
PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
||||||
|
NAME=grafana
|
||||||
|
DESC="Grafana Server"
|
||||||
|
|
||||||
|
#
|
||||||
|
# init.d / servicectl compatibility (openSUSE)
|
||||||
|
#
|
||||||
|
if [ -f /etc/rc.status ]; then
|
||||||
|
. /etc/rc.status
|
||||||
|
rc_reset
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Source function library.
|
||||||
|
#
|
||||||
|
if [ -f /etc/rc.d/init.d/functions ]; then
|
||||||
|
. /etc/rc.d/init.d/functions
|
||||||
|
fi
|
||||||
|
|
||||||
|
GRAFANA_USER=grafana
|
||||||
|
GRAFANA_GROUP=grafana
|
||||||
|
GRAFANA_HOME=/opt/$NAME
|
||||||
|
CONF_DIR=/etc/$NAME
|
||||||
|
WORK_DIR=$GRAFANA_HOME
|
||||||
|
DATA_DIR=$GRAFANA_HOME/data
|
||||||
|
LOG_DIR=/var/log/$NAME
|
||||||
|
CONF_FILE=$CONF_DIR/grafana.ini
|
||||||
|
MAX_OPEN_FILES=65535
|
||||||
|
|
||||||
|
# overwrite settings from default file
|
||||||
|
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
||||||
|
|
||||||
|
PID_FILE=/var/run/$NAME.pid
|
||||||
|
DAEMON=$GRAFANA_HOME/bin/grafana
|
||||||
|
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} --default-data-path=${DATA_DIR} --default-log-path=${LOG_DIR} web"
|
||||||
|
|
||||||
|
# Check DAEMON exists
|
||||||
|
test -x $DAEMON || exit 0
|
||||||
|
|
||||||
|
function pidofproc() {
|
||||||
|
if [ $# -ne 3 ]; then
|
||||||
|
echo "Expected three arguments, e.g. $0 -p pidfile daemon-name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
pid=`pgrep -f $3`
|
||||||
|
local pidfile=`cat $2`
|
||||||
|
|
||||||
|
if [ "x$pidfile" == "x" ]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "x$pid" != "x" -a "$pidfile" == "$pid" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
echo -n $"Starting $DESC: .... "
|
||||||
|
|
||||||
|
pid=`pidofproc -p $PID_FILE grafana`
|
||||||
|
if [ -n "$pid" ] ; then
|
||||||
|
echo "Already running."
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prepare environment
|
||||||
|
mkdir -p "$LOG_DIR" "$DATA_DIR" "$WORK_DIR" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$LOG_DIR" "$DATA_DIR" "$WORK_DIR"
|
||||||
|
touch "$PID_FILE" && chown "$GRAFANA_USER":"$GRAFANA_GROUP" "$PID_FILE"
|
||||||
|
|
||||||
|
if [ -n "$MAX_OPEN_FILES" ]; then
|
||||||
|
ulimit -n $MAX_OPEN_FILES
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start Daemon
|
||||||
|
su -s /bin/sh -c "nohup ${DAEMON_PATH} --pidfile=${DAEMON_PID} ${DAEMON_OPTS} >> $STDOUT 3>&1 &" $DAEMON_USER
|
||||||
|
return=$?
|
||||||
|
if [ $return -eq 0 ]
|
||||||
|
then
|
||||||
|
sleep 1
|
||||||
|
# check if pid file has been written two
|
||||||
|
if ! [[ -s $PID_FILE ]]; then
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
i=0
|
||||||
|
timeout=10
|
||||||
|
# Wait for the process to be properly started before exiting
|
||||||
|
until { cat "$PID_FILE" | xargs kill -0; } >/dev/null 2>&1
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
i=$(($i + 1))
|
||||||
|
[ $i -gt $timeout ] && exit 4
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "OK"
|
||||||
|
exit $return
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
echo -n "Stopping $DESC ..."
|
||||||
|
|
||||||
|
if [ -f "$PID_FILE" ]; then
|
||||||
|
killproc -p $PID_FILE -d 20 $NAME
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
echo -n "$DESC is not running but pid file exists, cleaning up"
|
||||||
|
elif [ $? -eq 3 ]; then
|
||||||
|
PID="`cat $PID_FILE`"
|
||||||
|
echo -n "Failed to stop $DESC (pid $PID)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
rm -f "$PID_FILE"
|
||||||
|
echo "OK"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo -n "(not running)"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
status -p $PID_FILE $NAME
|
||||||
|
;;
|
||||||
|
restart|force-reload)
|
||||||
|
if [ -f "$PID_FILE" ]; then
|
||||||
|
$0 stop
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
$0 start
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -n "Usage: $0 {start|stop|restart|force-reload|status}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
15
packaging/rpm/sysconfig/grafana
Normal file
15
packaging/rpm/sysconfig/grafana
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
#GRAFANA_USER=grafana
|
||||||
|
|
||||||
|
#GRAFANA_GROUP=grafana
|
||||||
|
|
||||||
|
#LOG_DIR=/var/log/grafana
|
||||||
|
|
||||||
|
#GRAFANA_HOME=/opt/grafana
|
||||||
|
#DATA_DIR=/opt/data/grafana
|
||||||
|
#WORK_DIR=/opt/grafana
|
||||||
|
|
||||||
|
#CONF_DIR=/etc/grafana
|
||||||
|
#CONF_FILE=/etc/grafana/grafana.ini
|
||||||
|
|
||||||
|
#RESTART_ON_UPGRADE=true
|
Loading…
Reference in New Issue
Block a user