Skip to content

Instantly share code, notes, and snippets.

@wallyqs
Last active June 25, 2018 10:41
Show Gist options
  • Save wallyqs/c96d56e735c74ee4cc1f to your computer and use it in GitHub Desktop.
Save wallyqs/c96d56e735c74ee4cc1f to your computer and use it in GitHub Desktop.
gnatsd init script
#!/bin/sh
### BEGIN INIT INFO
# Provides: gnatsd
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Should-Start: gnatsd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: High Performance Golang Server for NATS.
# Description: Starts a gnatsd server with monitoring port.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/gnatsd
NAME="gnatsd"
DESC="gnatsd"
GNATSD_PORT=4222
GNATSD_MONITORING_PORT=8222
PIDFILE="/var/run/gnatsd/${NAME}.pid"
test -x $DAEMON || exit 0
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMON_OPTS=" -p $GNATSD_PORT -m $GNATSD_MONITORING_PORT -P $PIDFILE -s"
. /lib/lsb/init-functions
start_gnatsd() {
start-stop-daemon --start --background --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $DAEMON_OPTS
}
stop_gnatsd() {
start-stop-daemon --stop --retry TERM/10/KILL/5 --quiet --oknodo --pidfile $PIDFILE
}
status_gnatsd() {
status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}"
}
case "$1" in
start)
log_begin_msg "Starting $DESC"
start_gnatsd
log_end_msg $?
;;
stop)
log_begin_msg "Stopping $DESC"
stop_gnatsd
log_end_msg $?
;;
status)
status_gnatsd
;;
restart)
log_begin_msg "Restarting $DESC"
stop_gnatsd
start_gnatsd
log_end_msg $?
;;
*)
echo "Usage: $0 {start|stop|status|restart}" >&2
exit 1
;;
esac
@derekcollison
Copy link

LGTM

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