Skip to content

Instantly share code, notes, and snippets.

@jimrollenhagen
Created October 21, 2014 14:33
Show Gist options
  • Save jimrollenhagen/16904f939120ccca71f0 to your computer and use it in GitHub Desktop.
Save jimrollenhagen/16904f939120ccca71f0 to your computer and use it in GitHub Desktop.
#! /bin/bash
### BEGIN INIT INFO
# Provides: ironic-api
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ironic-api server
# Description: frontend API server for Ironic
### END INIT INFO
set -e
# These lines are the only ones you should edit between services
DAEMON=ironic-api
DAEMON_ARGS="--config-file=/etc/ironic/ironic.conf"
PIDFILE=/var/run/ironic/${DAEMON}.pid
USER=ironic
GROUP=$USER
DESC="ironic-api (standalone)"
# Prepare the paths for the virtual environment
VIRTUALENV_PATH=/path/to/ironic/venv
DAEMON_PATH=${VIRTUALENV_PATH}/bin
# Set some defaults that may be updated below
ENABLED=true
RETVAL=0
if test -f /etc/default/${DAEMON}; then
. /etc/default/${DAEMON}
fi
. /lib/lsb/init-functions
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin:${VIRTUALENV_LOCATION}/bin"
test "$ENABLED" = "true" || exit 0
check_pid_directory()
{
# Wheezy uses tmpfs for `/var/run`, so the `ironic` subdirectory will not be
# present on reboot
if [ ! -d /var/run/ironic ]; then
mkdir /var/run/ironic
chmod 0755 /var/run/ironic
fi
}
start()
{
check_pid_directory
# Start the daemon backgrounded and check status after one second.
# This is quite janky but there isn't a way to get exit statuses from a
# process that is immediately backgrounded by start-stop-daemon. -MH
log_daemon_msg "Starting ${DESC}... " ${DAEMON}
. ${VIRTUALENV_PATH}/bin/activate
start-stop-daemon --start --name ${DAEMON} --chdir /var/run --chuid ${USER}:${GROUP} --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON_PATH}/${DAEMON} -- ${DAEMON_ARGS}
log_end_msg $?
sleep 5
status
}
stop() {
# Stop the daemon and allow it 30 seconds to stop gracefully. It will get a
# SIGKILL after 30 seconds.
log_daemon_msg "Stopping ${DESC}... " ${DAEMON}
start-stop-daemon --stop --oknodo --pidfile ${PIDFILE} --retry=TERM/30/KILL/5
log_end_msg $?
}
status() {
status_of_proc -p ${PIDFILE} ${DAEMON_PATH}/${DAEMON} ${DAEMON}
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop && start
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment