Skip to content

Instantly share code, notes, and snippets.

@lorentzca
Forked from yunano/consul
Last active February 1, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorentzca/98c7e00b3313155a53e2 to your computer and use it in GitHub Desktop.
Save lorentzca/98c7e00b3313155a53e2 to your computer and use it in GitHub Desktop.
/etc/init.d/consul for CentOS 5
#!/bin/sh
#
# consul - this script manages the consul agent
#
# chkconfig: 345 95 05
# description: consul_0.6.0
# processname: consul
### BEGIN INIT INFO
# Provides: consul
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Manage the consul agent
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
exec="/usr/local/sbin/consul"
prog=${exec##*/}
lockfile="/var/lock/subsys/$prog"
pidfile="/var/run/${prog}.pid"
logfile="/var/log/${prog}.log"
sysconfig="/etc/sysconfig/$prog"
confdir="/etc/${prog}.d/server"
[ -f $sysconfig ] && . $sysconfig
export GOMAXPROCS=${GOMAXPROCS:-2}
start() {
[ -x $exec ] || exit 5
[ -d $confdir ] || exit 6
echo -n $"Starting $prog: "
touch $logfile $pidfile
daemon "{ $exec agent $OPTIONS -config-dir=$confdir >> $logfile 2>&1 & }; echo \$! >| $pidfile"
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $lockfile
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $exec -INT 2>> $logfile
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f $pidfile $lockfile
echo
return $RETVAL
}
restart() {
stop
while :
do
ss -pl | fgrep "((\"$prog\"," > /dev/null
[ $? -ne 0 ] && break
sleep 0.1
done
start
}
reload() {
echo -n $"Reloading $prog: "
killproc -p $pidfile $exec -HUP
echo
}
force_reload() {
restart
}
configtest() {
$exec configtest -config-dir=$confdir
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload|force-reload)
rh_status_q || exit 7
$1
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;
configtest)
$1
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
exit $?
@lorentzca
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment