Skip to content

Instantly share code, notes, and snippets.

@noda-sin
Last active August 29, 2015 14:10
Show Gist options
  • Save noda-sin/4df09dc314450a8e9736 to your computer and use it in GitHub Desktop.
Save noda-sin/4df09dc314450a8e9736 to your computer and use it in GitHub Desktop.
Serf Init Script
#!/bin/sh
#
# chkconfig: - 89 11
# description: serf daemon
# processname: serf
# config: /etc/serf/serf.conf
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Description: serf agent daemon
# Source function library.
. /etc/rc.d/init.d/functions
export PATH=$PATH:/usr/bin/
exec=/usr/bin/serf
prog=${exec##*/}
conf=/etc/serf/serf.conf
lockfile=/var/lock/subsys/serf
logfile=/var/log/serf.log
start ()
{
echo -n $"Starting Serf:"
if [ -f $conf ]; then
$exec agent -config-file=$conf >> $logfile 2>&1 &
else
$exec agent >> $logfile 2>&1 &
fi
stat=$?
echo
[ $stat -eq 0 ] && touch $lockfile
return $stat
}
stop()
{
echo -n $"Shutting down Serf:"
killproc $prog
stat=$?
echo
[ $stat -eq 0 ] && rm -f $lockfile
return $stat
}
restart()
{
stop
start
}
monitor ()
{
echo -n $"Monitoring Serf:"
$exec monitor &
return
}
leave()
{
echo -n $"Force-leave Serf:"
$exec force-leave node &
stat=$?
echo
[ $stat -eq 0 ] && rm -f $lockfile
return $stat
}
case "$1" in
start|stop|restart|monitor|leave)
$1
;;
force-reload)
restart
;;
status)
status $prog
;;
*)
echo $"Usage: $0 {start|stop|status|restart|monitor|leave}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment