Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sysvinit-tools as an RPM package dependency #6965

Merged
merged 1 commit into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ With this release the systemd configuration files for InfluxDB will use the syst
- [#6708](https://github.com/influxdata/influxdb/issues/6708): Drop writes from before the retention policy time window.
- [#6968](https://github.com/influxdata/influxdb/issues/6968): Always use the demo config when outputting a new config.
- [#6986](https://github.com/influxdata/influxdb/pull/6986): update connection settings when changing hosts in cli.
- [#6965](https://github.com/influxdata/influxdb/pull/6965): Minor improvements to init script. Removes sysvinit-utils as package dependency.

## v0.13.0 [2016-05-12]

Expand Down
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def package(build_output, pkg_name, version, nightly=False, iteration=1, static=
package_build_root,
current_location)
if package_type == "rpm":
fpm_command += "--depends coreutils --depends sysvinit-tools --rpm-posttrans {}".format(POSTINST_SCRIPT)
fpm_command += "--depends coreutils --rpm-posttrans {}".format(POSTINST_SCRIPT)
out = run(fpm_command, shell=True)
matches = re.search(':path=>"(.*)"', out)
outfile = None
Expand Down
200 changes: 95 additions & 105 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
#!/usr/bin/env bash

#!/bin/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
# Short-Description: Start the InfluxDB process
### END INIT INFO

# If you modify this, please make sure to also edit influxdb.service
# 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.

# 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"
# any config file values.
DEFAULT=/etc/default/influxdb

# Daemon options
Expand All @@ -32,10 +24,19 @@ NAME=influxdb
USER=influxdb
GROUP=influxdb

# Daemon name, where is the actual executable
# If the daemon is not there, then exit.
# Check for sudo or root privileges before continuing
if [ "$UID" != "0" ]; then
echo "You must be root to run this script"
exit 1
fi

# Daemon name, where is the actual executable If the daemon is not
# there, then exit.
DAEMON=/usr/bin/influxd
[ -x $DAEMON ] || exit 5
if [ ! -x $DAEMON ]; then
echo "Executable $DAEMON does not exist!"
exit 5
fi

# Configuration file
CONFIG=/etc/influxdb/influxdb.conf
Expand Down Expand Up @@ -72,53 +73,11 @@ if [ ! -f "$STDERR" ]; then
mkdir -p $(dirname $STDERR)
fi

# Overwrite init script variables with /etc/default/influxdb values
# Override init script variables with DEFAULT values
if [ -r $DEFAULT ]; then
source $DEFAULT
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`

/bin/kill -s $3 $PID
while true; do
pidof `basename $DAEMON` >/dev/null
if [ $? -ne 0 ]; then
return 0
fi

sleep 1
n=$(expr $n + 1)
if [ $n -eq 30 ]; then
/bin/kill -s SIGKILL $PID
return 0
fi
done
}

function log_failure_msg() {
echo "$@" "[ FAILED ]"
}
Expand All @@ -130,104 +89,135 @@ function log_success_msg() {
function start() {
# Check if config file exist
if [ ! -r $CONFIG ]; then
log_failure_msg "config file doesn't exist (or you don't have permission to view)"
log_failure_msg "config file $CONFIG doesn't exist (or you don't have permission to view)"
exit 4
fi

# Checked the PID file exists and check the actual status of process
if [ -e $PIDFILE ]; then
PID="$(pgrep -f $PIDFILE)"
if test -n "$PID" && kill -0 "$PID" &>/dev/null; then
# If the status is SUCCESS then don't need to start again.
log_failure_msg "$NAME process is running"
exit 0 # Exit
# Check that the PID file exists, and check the actual status of process
if [ -f $PIDFILE ]; then
PID="$(cat $PIDFILE)"
if kill -0 "$PID" &>/dev/null; then
# Process is already up
log_success_msg "$NAME process is already running"
return 0
fi
# if PID file does not exist, check if writable
else
su -s /bin/sh -c "touch $PIDFILE" $USER > /dev/null 2>&1
su -s /bin/sh -c "touch $PIDFILE" $USER &>/dev/null
if [ $? -ne 0 ]; then
log_failure_msg "$PIDFILE not writable, check permissions"
exit 5
fi
fi

# Bump the file limits, before launching the daemon. These will carry over to
# launched processes.
# 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"
log_failure_msg "Unable to set ulimit to $OPEN_FILE_LIMIT"
exit 1
fi

log_success_msg "Starting the process" "$NAME"
if which start-stop-daemon > /dev/null 2>&1; then
start-stop-daemon --chuid $GROUP:$USER --start --quiet --pidfile $PIDFILE --exec $DAEMON -- -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &
# Launch process
echo "Starting $NAME..."
if which start-stop-daemon &>/dev/null; then
start-stop-daemon \
--chuid $GROUP:$USER \
--start \
--quiet \
--pidfile $PIDFILE \
--exec $DAEMON \
-- \
-pidfile $PIDFILE \
-config $CONFIG \
$INFLUXD_OPTS >>$STDOUT 2>>$STDERR &
else
su -s /bin/sh -c "nohup $DAEMON -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &" $USER
local CMD="$DAEMON -pidfile $PIDFILE -config $CONFIG $INFLUXD_OPTS >>$STDOUT 2>>$STDERR &"
su -s /bin/sh -c "$CMD" $USER
fi
log_success_msg "$NAME process was started"

# Sleep to verify process is still up
sleep 1
if [ -f $PIDFILE ]; then
# PIDFILE exists
if kill -0 $(cat $PIDFILE) &>/dev/null; then
# PID up, service running
log_success_msg "$NAME process was started"
return 0
fi
fi
log_failure_msg "$NAME process was unable to start"
exit 1
}

function stop() {
# Stop the daemon.
if [ -e $PIDFILE ]; then
PID="$(pgrep -f $PIDFILE)"
if test -n "$PID" && kill -0 "$PID" &>/dev/null; then
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
if [ -f $PIDFILE ]; then
local PID="$(cat $PIDFILE)"
if kill -0 $PID &>/dev/null; then
echo "Stopping $NAME..."
# Process still up, send SIGTERM and remove PIDFILE
kill -s SIGTERM $PID &>/dev/null && rm -f "$PIDFILE" &>/dev/null
while true; do
# Enter loop to ensure process is stopped
kill -0 $PID &>/dev/null
if [ "$?" != "0" ]; then
# Process stopped, break from loop
log_success_msg "$NAME process was stopped"
return 0
fi

# Process still up after signal, sleep and wait
sleep 1
n=$(expr $n + 1)
if [ $n -eq 30 ]; then
# After 30 seconds, send SIGKILL
echo "Timeout exceeded, sending SIGKILL..."
kill -s SIGKILL $PID &>/dev/null
elif [ $? -eq 40 ]; then
# After 40 seconds, error out
log_failure_msg "could not stop $NAME process"
exit 1
fi
done
fi
else
log_failure_msg "$NAME process is not running"
fi
log_success_msg "$NAME process already stopped"
}

function restart() {
# Restart the daemon.
PID="$(pgrep -f $PIDFILE)"
stop
while test -n "$PID" && test -d "/proc/$PID" &>/dev/null
do
echo "Process $PID is still running..."
sleep 1
done
start
}

function status() {
# Check the status of the process.
if [ -e $PIDFILE ]; then
PID="$(pgrep -f $PIDFILE)"
if test -n "$PID" && test -d "/proc/$PID" &>/dev/null; then
log_success_msg "$NAME Process is running"
if [ -f $PIDFILE ]; then
PID="$(cat $PIDFILE)"
if kill -0 $PID &>/dev/null; then
log_success_msg "$NAME process is running"
exit 0
else
log_failure_msg "$NAME Process is not running"
exit 1
fi
else
log_failure_msg "$NAME Process is not running"
exit 3
fi
log_failure_msg "$NAME process is not running"
exit 1
}

case $1 in
start)
start
start
;;

stop)
stop
stop
;;

restart)
restart
restart
;;

status)
status
status
;;

version)
Expand Down