Skip to content

Instantly share code, notes, and snippets.

@adionditsak
Created January 30, 2017 10:26
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 adionditsak/d21c11639b4c5c07be487b448ca53892 to your computer and use it in GitHub Desktop.
Save adionditsak/d21c11639b4c5c07be487b448ca53892 to your computer and use it in GitHub Desktop.
consul startup/service script (ubuntu 14)
#
# Daemon for consul
#
# chkconfig: 345 98 20
# description: Daemon for consul
# processname: consul
### BEGIN INIT INFO
# Provides: consul
# Required-Start: $network
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop consul
# Description: Daemon for consul
### END INIT INFO
CONSUL_PATH="/usr/local/bin/consul"
CONSUL_CONFIG="/etc/consul.d"
CONSUL_STARTUP_LOG="/var/log/consul_startup.log"
start() {
$CONSUL_PATH agent -config-dir=$CONSUL_CONFIG 2>&1 > $CONSUL_STARTUP_LOG &
return $?
}
stop() {
# Get the process number and kill the process
kill $(ps -C consul|awk 'END {print $1}')
return $?
}
status() {
if [ -z $(ps -C consul|awk 'END {print $1}'|grep -v PID) ]; then
echo "Consul is not running."
return 3
else
echo "Consul is running."
fi
return 0
}
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
*)
echo "Usage: consul {start|stop|status}"
RETVAL=2
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment