From 811f7a594e7bb695aed0583a19d454dbe516d9f6 Mon Sep 17 00:00:00 2001 From: ptoohill1 Date: Sat, 3 Oct 2015 21:54:44 -0500 Subject: [PATCH] Adding init.d script For booting on systems where upstart isnt used, such as Debian, an init.d script can be used. Change-Id: I2fadc32dc73f31d733c424591d64448059de89e3 Closes-Bug: #1502542 --- etc/initd/amphora-agent | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 etc/initd/amphora-agent diff --git a/etc/initd/amphora-agent b/etc/initd/amphora-agent new file mode 100644 index 0000000000..d191874bb5 --- /dev/null +++ b/etc/initd/amphora-agent @@ -0,0 +1,67 @@ +### BEGIN INIT INFO +# Provides: amphora-agent +# Required-Start: $remote_fs $syslog $network +# Required-Stop: $remote_fs $syslog $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Runs the Amphora Agent processes +# Description: This script runs Octavia Amphora Agent processes. +# This script will start the Amphora Agent services +# and kill them. +### END INIT INFO + +# Using the lsb functions to perform the operations. +. /lib/lsb/init-functions +# Process name ( For display ) +NAME=amphora-agent +# Daemon name, where is the actual executable +DAEMON=/usr/local/bin/amphora-agent +# pid file for the daemon +PIDFILE=/var/run/amphora-agent.pid + +# If the daemon is not there, then exit. +test -x $DAEMON || exit 5 + +case $1 in + start) + # Checked the PID file exists and check the actual status of process + if [ -e $PIDFILE ]; then + status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?" + # If the status is SUCCESS then don't need to start again. + if [ $status = "0" ]; then + exit # Exit + fi + fi + # Start the daemon. + log_daemon_msg "Starting the process" "$NAME" + # Start the daemon with the help of start-stop-daemon + # Log the message appropriately + if start-stop-daemon --start -m --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- --config-file /etc/octavia/amphora-agent.conf ; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + stop) + # Stop the daemon. + if [ -e $PIDFILE ]; then + status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?" + if [ "$status" = 0 ]; then + start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE + /bin/rm -rf $PIDFILE + fi + else + log_daemon_msg "$NAME process is not running" + log_end_msg 0 + fi + ;; + restart) + # Restart the daemon. + $0 stop && sleep 2 && $0 start + ;; + *) + # For invalid arguments, print the usage message. + echo "Usage: $0 {start|stop|restart|reload|status}" + exit 2 + ;; +esac