mirror of https://github.com/grafana/grafana
parent
6911572fa1
commit
96ee1c17a3
@ -1,4 +1,4 @@ |
||||
FROM debian |
||||
FROM debian:jessie |
||||
|
||||
ADD *.deb /tmp/ |
||||
|
||||
|
@ -0,0 +1,64 @@ |
||||
#!/bin/sh |
||||
|
||||
set -e |
||||
|
||||
[ -f /etc/default/grafana ] && . /etc/default/grafana |
||||
|
||||
startGrafana() { |
||||
if [ -x /bin/systemctl ] ; then |
||||
/bin/systemctl daemon-reload |
||||
/bin/systemctl start grafana.service |
||||
elif [ -x "/etc/init.d/grafana" ]; then |
||||
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then |
||||
invoke-rc.d grafana start || true |
||||
else |
||||
/etc/init.d/grafana start || true |
||||
fi |
||||
fi |
||||
} |
||||
|
||||
case "$1" in |
||||
configure) |
||||
[ -z "$GRAFANA_USER" ] && GRAFANA_USER="grafana" |
||||
[ -z "$GRAFANA_GROUP" ] && GRAFANA_GROUP="grafana" |
||||
if ! getent group "$GRAFANA_GROUP" > /dev/null 2>&1 ; then |
||||
addgroup --system "$GRAFANA_GROUP" --quiet |
||||
fi |
||||
if ! id $GRAFANA_USER > /dev/null 2>&1 ; then |
||||
adduser --system --home /usr/share/grafana --no-create-home \ |
||||
--ingroup "$GRAFANA_GROUP" --disabled-password --shell /bin/false \ |
||||
"$GRAFANA_USER" |
||||
fi |
||||
|
||||
# Set user permissions on /var/log/grafana, /opt/grafana/data |
||||
mkdir -p /var/log/grafana /opt/grafana/data |
||||
chown -R $GRAFANA_USER:$GRAFANA_GROUP /var/log/grafana /opt/grafana/data |
||||
chmod 755 /var/log/grafana /opt/grafana/data |
||||
|
||||
# configuration files should not be modifiable by elasticsearch user, as this can be a security issue |
||||
chown -Rh root:root /etc/grafana/* |
||||
chmod 755 /etc/grafana |
||||
find /etc/grafana -type f -exec chmod 644 {} ';' |
||||
find /etc/grafana -type d -exec chmod 755 {} ';' |
||||
|
||||
# if $2 is set, this is an upgrade |
||||
if ( [ -n $2 ] && [ "$RESTART_ON_UPGRADE" = "true" ] ) ; then |
||||
startGrafana |
||||
# this is a fresh installation |
||||
elif [ -z $2 ] ; then |
||||
if [ -x /bin/systemctl ] ; then |
||||
echo "### NOT starting on installation, please execute the following statements to configure elasticsearch to start automatically using systemd" |
||||
echo " sudo /bin/systemctl daemon-reload" |
||||
echo " sudo /bin/systemctl enable grafana.service" |
||||
echo "### You can start grafana by executing" |
||||
echo " sudo /bin/systemctl start grafana.service" |
||||
|
||||
elif [ -x /usr/sbin/update-rc.d ] ; then |
||||
echo "### NOT starting grafana by default on bootup, please execute" |
||||
echo " sudo update-rc.d grafana defaults 95 10" |
||||
echo "### In order to start grafana, execute" |
||||
echo " sudo /etc/init.d/grafana start" |
||||
fi |
||||
fi |
||||
;; |
||||
esac |
@ -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 |
@ -0,0 +1,140 @@ |
||||
#! /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" |
||||
DEFAULT=/etc/default/$NAME |
||||
|
||||
if [ `id -u` -ne 0 ]; then |
||||
echo "You need root privileges to run this script" |
||||
exit 1 |
||||
fi |
||||
|
||||
. /lib/lsb/init-functions |
||||
|
||||
if [ -r /etc/default/rcS ]; then |
||||
. /etc/default/rcS |
||||
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 |
||||
if [ -f "$DEFAULT" ]; then |
||||
. "$DEFAULT" |
||||
fi |
||||
|
||||
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 |
||||
|
||||
case "$1" in |
||||
start) |
||||
|
||||
log_daemon_msg "Starting $DESC" |
||||
|
||||
pid=`pidofproc -p $PID_FILE grafana` |
||||
if [ -n "$pid" ] ; then |
||||
log_begin_msg "Already running." |
||||
log_end_msg 0 |
||||
exit 0 |
||||
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 |
||||
start-stop-daemon --start -b --chdir "$WORK_DIR" --user "$GRAFANA_USER" -c "$GRAFANA_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS |
||||
return=$? |
||||
if [ $return -eq 0 ] |
||||
then |
||||
sleep 1 |
||||
|
||||
# check if pid file has been written two |
||||
if ! [[ -s $PID_FILE ]]; then |
||||
log_end_msg 1 |
||||
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 ] && log_end_msg 1 |
||||
done |
||||
fi |
||||
log_end_msg $return |
||||
;; |
||||
stop) |
||||
log_daemon_msg "Stopping $DESC" |
||||
|
||||
if [ -f "$PID_FILE" ]; then |
||||
start-stop-daemon --stop --pidfile "$PID_FILE" \ |
||||
--user "$GRAFANA_USER" \ |
||||
--retry=TERM/20/KILL/5 >/dev/null |
||||
if [ $? -eq 1 ]; then |
||||
log_progress_msg "$DESC is not running but pid file exists, cleaning up" |
||||
elif [ $? -eq 3 ]; then |
||||
PID="`cat $PID_FILE`" |
||||
log_failure_msg "Failed to stop $DESC (pid $PID)" |
||||
exit 1 |
||||
fi |
||||
rm -f "$PID_FILE" |
||||
else |
||||
log_progress_msg "(not running)" |
||||
fi |
||||
log_end_msg 0 |
||||
;; |
||||
status) |
||||
status_of_proc -p $PID_FILE grafana grafana && exit 0 || exit $? |
||||
;; |
||||
restart|force-reload) |
||||
if [ -f "$PID_FILE" ]; then |
||||
$0 stop |
||||
sleep 1 |
||||
fi |
||||
$0 start |
||||
;; |
||||
*) |
||||
log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}" |
||||
exit 1 |
||||
;; |
||||
esac |
||||
|
||||
exit 0 |
@ -0,0 +1,26 @@ |
||||
[Unit] |
||||
Description=Starts and stops a single grafana instance on this system |
||||
Documentation=http://docs.grafana.org |
||||
Wants=network-online.target |
||||
After=network-online.target |
||||
|
||||
[Service] |
||||
EnvironmentFile=/etc/default/elasticsearch |
||||
User=elasticsearch |
||||
Group=elasticsearch |
||||
ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ |
||||
-Des.default.config=$CONF_FILE \ |
||||
-Des.default.path.home=$ES_HOME \ |
||||
-Des.default.path.logs=$LOG_DIR \ |
||||
-Des.default.path.data=$DATA_DIR \ |
||||
-Des.default.path.work=$WORK_DIR \ |
||||
-Des.default.path.conf=$CONF_DIR |
||||
# 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 |
||||
|
||||
[Install] |
||||
WantedBy=multi-user.target |
@ -1,174 +0,0 @@ |
||||
#! /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 |
||||
|
||||
if [ -r /lib/lsb/init-functions ]; then |
||||
source /lib/lsb/init-functions |
||||
fi |
||||
|
||||
DAEMON_NAME="grafana" |
||||
DAEMON_USER="grafana" |
||||
DAEMON_PATH="/opt/grafana/current/grafana" |
||||
DAEMON_OPTS="--config=/etc/grafana/grafana.ini web" |
||||
DAEMON_PWD="/opt/grafana/current" |
||||
DAEMON_PID="/var/run/${DAEMON_NAME}.pid" |
||||
DAEMON_NICE=0 |
||||
DAEMON_LOG='/var/log/grafana/grafana.log' |
||||
|
||||
# If the daemon is not there, then exit. |
||||
[ -x $DAEMON_PATH ] || exit 5 |
||||
|
||||
if [ "x$STDOUT" == "x" ]; then |
||||
STDOUT=/tmp/grafana.log |
||||
fi |
||||
|
||||
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 |
||||
} |
||||
|
||||
function killproc() { |
||||
if [ $# -ne 3 ]; then |
||||
echo "Expected three arguments, e.g. $0 -p pidfile signal" |
||||
fi |
||||
|
||||
pid=`cat $2` |
||||
|
||||
kill -s $3 $pid |
||||
} |
||||
|
||||
function log_failure_msg() { |
||||
echo "$@" "[ FAILED ]" |
||||
} |
||||
|
||||
function log_success_msg() { |
||||
echo "$@" "[ OK ]" |
||||
} |
||||
|
||||
do_start() { |
||||
cd $DAEMON_PWD |
||||
|
||||
# Checked the PID file exists and check the actual status of process |
||||
if [ -e $DAEMON_PID ]; then |
||||
pidofproc -p $DAEMON_PID $DAEMON_PATH > /dev/null 2>&1 && status="0" || status="$?" |
||||
# If the status is SUCCESS then don't need to start again. |
||||
if [ "x$status" = "x0" ]; then |
||||
log_failure_msg "$DAEMON_NAME process is running" |
||||
exit 1 # Exit |
||||
fi |
||||
fi |
||||
# Start the daemon. |
||||
log_success_msg "Starting the process" "$DAEMON_NAME" |
||||
|
||||
# Start the daemon with the help of start-stop-daemon |
||||
# Log the message appropriately |
||||
if which start-stop-daemon > /dev/null 2>&1; then |
||||
start-stop-daemon \ |
||||
--start --quiet --oknodo --background \ |
||||
--nicelevel $DAEMON_NICE \ |
||||
--chdir "${DAEMON_PWD}" \ |
||||
--pidfile "${DAEMON_PID}" --make-pidfile \ |
||||
--chuid "${DAEMON_USER}" \ |
||||
--exec "${DAEMON_PATH}" -- $DAEMON_OPTS |
||||
result=$? |
||||
else |
||||
touch ${DAEMON_PID} |
||||
chown $DAEMON_USER "${DAEMON_PID}" |
||||
#daemon --user $DAEMON_USER --pidfile $DAEMON_PID nohup $DAEMON_PATH $DAEMON_OPTS |
||||
su -s /bin/sh -c "nohup ${DAEMON_PATH} --pidfile=${DAEMON_PID} ${DAEMON_OPTS} >> $STDOUT 3>&1 &" $DAEMON_USER |
||||
fi |
||||
|
||||
log_success_msg "$DAEMON_NAME process was started" |
||||
} |
||||
|
||||
do_stop() { |
||||
local result |
||||
|
||||
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null |
||||
if [ $? -ne 0 ]; then |
||||
log_failure_msg "${DAEMON_NAME} is not started" |
||||
result=0 |
||||
else |
||||
log_success_msg "Stopping ${DAEMON_NAME}" |
||||
killproc -p "${DAEMON_PID}" SIGTERM |
||||
result=$? |
||||
if [ $result = 0 ]; then |
||||
log_success_msg "Stopped ${DAEMON_NAME}" |
||||
rm "${DAEMON_PID}" |
||||
fi |
||||
fi |
||||
|
||||
return $result |
||||
} |
||||
|
||||
do_restart() { |
||||
local result |
||||
do_stop |
||||
result=$? |
||||
sleep 2 |
||||
if [ $result = 0 ]; then |
||||
do_start |
||||
result=$? |
||||
fi |
||||
return $result |
||||
} |
||||
|
||||
do_status() { |
||||
if [ -e $DEAMON_PID ]; then |
||||
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null |
||||
if [ $? -ne 0 ]; then |
||||
log_failure_msg "$DAEMON_NAME Process is not running" |
||||
exit 1 |
||||
else |
||||
log_success_msg "$DAEMON_NAME Process is running" |
||||
exit 0 |
||||
fi |
||||
else |
||||
log_failure_msg "$DAEMON_NAME Process is not running" |
||||
exit 3 |
||||
fi |
||||
} |
||||
|
||||
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 |
Loading…
Reference in new issue