2015-01-22 22:29:11 +00:00
|
|
|
#! /usr/bin/env bash
|
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: influxd
|
|
|
|
# Required-Start: $all
|
|
|
|
# Required-Stop: $remote_fs $syslog
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Start influxd at boot time
|
|
|
|
### END INIT INFO
|
|
|
|
|
2015-05-02 12:25:22 +00:00
|
|
|
# If you modify this, please make sure to also edit influxdb.service
|
2015-01-22 22:29:11 +00:00
|
|
|
# this init script supports three different variations:
|
|
|
|
# 1. New lsb that define start-stop-daemon
|
|
|
|
# 2. Old lsb that don't have start-stop-daemon but define, log, pidofproc and killproc
|
|
|
|
# 3. Centos installations without lsb-core installed
|
|
|
|
#
|
|
|
|
# In the third case we have to define our own functions which are very dumb
|
|
|
|
# and expect the args to be positioned correctly.
|
|
|
|
|
2015-04-08 17:24:34 +00:00
|
|
|
# Command-line options that can be set in /etc/default/influxdb. These will override
|
|
|
|
# any config file values. Example: "-join http://1.2.3.4:8086"
|
2015-06-23 22:59:07 +00:00
|
|
|
DEFAULT=/etc/default/influxdb
|
|
|
|
|
|
|
|
# Daemon options
|
2015-04-08 17:24:34 +00:00
|
|
|
INFLUXD_OPTS=
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
# Process name ( For display )
|
|
|
|
NAME=influxdb
|
|
|
|
|
|
|
|
# User and group
|
2015-04-15 20:05:08 +00:00
|
|
|
USER=influxdb
|
|
|
|
GROUP=influxdb
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
# Daemon name, where is the actual executable
|
|
|
|
# If the daemon is not there, then exit.
|
2015-11-06 16:52:04 +00:00
|
|
|
DAEMON=/usr/bin/influxd
|
2015-06-23 22:59:07 +00:00
|
|
|
[ -x $DAEMON ] || exit 5
|
|
|
|
|
|
|
|
# Configuration file
|
2015-11-06 16:52:04 +00:00
|
|
|
CONFIG=/etc/influxdb/influxdb.conf
|
2015-06-23 22:59:07 +00:00
|
|
|
|
|
|
|
# PID file for the daemon
|
|
|
|
PIDFILE=/var/run/influxdb/influxd.pid
|
|
|
|
PIDDIR=`dirname $PIDFILE`
|
|
|
|
if [ ! -d "$PIDDIR" ]; then
|
|
|
|
mkdir -p $PIDDIR
|
2015-08-23 00:20:53 +00:00
|
|
|
chown $USER:$GROUP $PIDDIR
|
2015-01-22 22:29:11 +00:00
|
|
|
fi
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
# Max open files
|
|
|
|
OPEN_FILE_LIMIT=65536
|
2015-01-22 22:29:11 +00:00
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
if [ -r /lib/lsb/init-functions ]; then
|
|
|
|
source /lib/lsb/init-functions
|
2015-01-22 22:29:11 +00:00
|
|
|
fi
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
# Logging
|
2015-03-25 22:54:25 +00:00
|
|
|
if [ -z "$STDOUT" ]; then
|
2015-01-22 22:29:11 +00:00
|
|
|
STDOUT=/dev/null
|
|
|
|
fi
|
2015-06-23 22:59:07 +00:00
|
|
|
|
2015-03-25 22:54:25 +00:00
|
|
|
if [ ! -f "$STDOUT" ]; then
|
2015-06-25 13:11:51 +00:00
|
|
|
mkdir -p $(dirname $STDOUT)
|
2015-03-25 22:54:25 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$STDERR" ]; then
|
|
|
|
STDERR=/var/log/influxdb/influxd.log
|
|
|
|
fi
|
2015-06-23 22:59:07 +00:00
|
|
|
|
2015-03-25 22:54:25 +00:00
|
|
|
if [ ! -f "$STDERR" ]; then
|
2015-06-25 13:11:51 +00:00
|
|
|
mkdir -p $(dirname $STDERR)
|
2015-03-25 22:54:25 +00:00
|
|
|
fi
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
# Overwrite init script variables with /etc/default/influxdb values
|
|
|
|
if [ -r $DEFAULT ]; then
|
|
|
|
source $DEFAULT
|
|
|
|
fi
|
2015-01-29 20:54:00 +00:00
|
|
|
|
2015-01-22 22:29:11 +00:00
|
|
|
function pidofproc() {
|
|
|
|
if [ $# -ne 3 ]; then
|
|
|
|
echo "Expected three arguments, e.g. $0 -p pidfile daemon-name"
|
|
|
|
fi
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
PID=`pgrep -f $3`
|
|
|
|
local PIDFILE=`cat $2`
|
2015-01-22 22:29:11 +00:00
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
if [ "x$PIDFILE" == "x" ]; then
|
2015-01-22 22:29:11 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
if [ "x$PID" != "x" -a "$PIDFILE" == "$PID" ]; then
|
2015-01-22 22:29:11 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function killproc() {
|
|
|
|
if [ $# -ne 3 ]; then
|
|
|
|
echo "Expected three arguments, e.g. $0 -p pidfile signal"
|
|
|
|
fi
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
PID=`cat $2`
|
2015-01-22 22:29:11 +00:00
|
|
|
|
2015-09-05 07:18:54 +00:00
|
|
|
/bin/kill -s $3 $PID
|
2015-09-03 23:18:52 +00:00
|
|
|
while true; do
|
2015-09-05 06:49:47 +00:00
|
|
|
pidof `basename $DAEMON` >/dev/null
|
2015-09-03 23:18:52 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
n=$(expr $n + 1)
|
|
|
|
if [ $n -eq 30 ]; then
|
2015-09-05 07:18:54 +00:00
|
|
|
/bin/kill -s SIGKILL $PID
|
2015-09-03 23:18:52 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
2015-01-22 22:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function log_failure_msg() {
|
|
|
|
echo "$@" "[ FAILED ]"
|
|
|
|
}
|
|
|
|
|
|
|
|
function log_success_msg() {
|
|
|
|
echo "$@" "[ OK ]"
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
case $1 in
|
|
|
|
start)
|
|
|
|
# Check if config file exist
|
|
|
|
if [ ! -r $CONFIG ]; then
|
2015-11-06 16:52:04 +00:00
|
|
|
log_failure_msg "config file doesn't exist (or you don't have permission to view)"
|
2015-06-23 22:59:07 +00:00
|
|
|
exit 4
|
2015-06-25 13:11:51 +00:00
|
|
|
fi
|
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
# Checked the PID file exists and check the actual status of process
|
|
|
|
if [ -e $PIDFILE ]; then
|
2015-11-06 16:52:04 +00:00
|
|
|
PID="$(pgrep -f $PIDFILE)"
|
|
|
|
if test ! -z $PID && kill -0 "$PID" &>/dev/null; then
|
|
|
|
# If the status is SUCCESS then don't need to start again.
|
2015-06-23 22:59:07 +00:00
|
|
|
log_failure_msg "$NAME process is running"
|
|
|
|
exit 0 # Exit
|
|
|
|
fi
|
|
|
|
# if PID file does not exist, check if writable
|
2015-06-25 13:11:51 +00:00
|
|
|
else
|
2015-10-01 20:30:14 +00:00
|
|
|
su -s /bin/sh -c "touch $PIDFILE" $USER > /dev/null 2>&1
|
2015-06-23 22:59:07 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
log_failure_msg "$PIDFILE not writable, check permissions"
|
|
|
|
exit 5
|
|
|
|
fi
|
2015-01-22 22:29:11 +00:00
|
|
|
fi
|
2015-01-29 20:54:00 +00:00
|
|
|
|
|
|
|
# Bump the file limits, before launching the daemon. These will carry over to
|
|
|
|
# launched processes.
|
|
|
|
ulimit -n $OPEN_FILE_LIMIT
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
log_failure_msg "set open file limit to $OPEN_FILE_LIMIT"
|
2015-06-25 13:11:51 +00:00
|
|
|
exit 1
|
2015-01-22 22:29:11 +00:00
|
|
|
fi
|
2015-01-27 02:45:33 +00:00
|
|
|
|
2015-06-23 22:59:07 +00:00
|
|
|
log_success_msg "Starting the process" "$NAME"
|
2015-01-29 20:54:00 +00:00
|
|
|
if which start-stop-daemon > /dev/null 2>&1; then
|
2015-06-23 22:59:07 +00:00
|
|
|
start-stop-daemon --chuid $GROUP:$USER --start --quiet --pidfile $PIDFILE --exec $DAEMON -- -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &
|
2015-01-29 20:54:00 +00:00
|
|
|
else
|
2015-08-27 13:32:05 +00:00
|
|
|
su -s /bin/sh -c "nohup $DAEMON -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &" $USER
|
2015-06-25 13:11:51 +00:00
|
|
|
fi
|
2015-06-23 22:59:07 +00:00
|
|
|
log_success_msg "$NAME process was started"
|
2015-01-22 22:29:11 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
stop)
|
|
|
|
# Stop the daemon.
|
2015-06-23 22:59:07 +00:00
|
|
|
if [ -e $PIDFILE ]; then
|
2015-11-06 16:52:04 +00:00
|
|
|
PID="$(pgrep -f $PIDFILE)"
|
|
|
|
if test ! -z $PID && kill -0 "$PID" &>/dev/null; then
|
2015-06-23 22:59:07 +00:00
|
|
|
if killproc -p $PIDFILE SIGTERM && /bin/rm -rf $PIDFILE; then
|
|
|
|
log_success_msg "$NAME process was stopped"
|
|
|
|
else
|
|
|
|
log_failure_msg "$NAME failed to stop service"
|
|
|
|
fi
|
2015-06-25 13:11:51 +00:00
|
|
|
fi
|
2015-06-23 22:59:07 +00:00
|
|
|
else
|
|
|
|
log_failure_msg "$NAME process is not running"
|
2015-01-22 22:29:11 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
restart)
|
|
|
|
# Restart the daemon.
|
|
|
|
$0 stop && sleep 2 && $0 start
|
|
|
|
;;
|
|
|
|
|
|
|
|
status)
|
|
|
|
# Check the status of the process.
|
2015-06-23 22:59:07 +00:00
|
|
|
if [ -e $PIDFILE ]; then
|
2015-11-06 16:52:04 +00:00
|
|
|
PID="$(pgrep -f $PIDFILE)"
|
|
|
|
if test ! -z $PID && test -d "/proc/$PID" &>/dev/null; then
|
2015-06-23 22:59:07 +00:00
|
|
|
log_success_msg "$NAME Process is running"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
log_failure_msg "$NAME Process is not running"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-22 22:29:11 +00:00
|
|
|
else
|
2015-06-23 22:59:07 +00:00
|
|
|
log_failure_msg "$NAME Process is not running"
|
2015-01-22 22:29:11 +00:00
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
2015-03-24 06:41:32 +00:00
|
|
|
version)
|
2015-06-23 22:59:07 +00:00
|
|
|
$DAEMON version
|
2015-03-24 06:41:32 +00:00
|
|
|
;;
|
|
|
|
|
2015-01-22 22:29:11 +00:00
|
|
|
*)
|
|
|
|
# For invalid arguments, print the usage message.
|
2015-03-24 06:41:32 +00:00
|
|
|
echo "Usage: $0 {start|stop|restart|status|version}"
|
2015-01-22 22:29:11 +00:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|