Skip to content

Instantly share code, notes, and snippets.

@aputs
Last active November 21, 2017 14:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save aputs/1daff678838441b5195d to your computer and use it in GitHub Desktop.
Save aputs/1daff678838441b5195d to your computer and use it in GitHub Desktop.
etcd init script
#!/bin/bash
# Startup script for etcd
#
# chkconfig: 2345 20 80
# description: Starts and stops etcd
. /etc/init.d/functions
prog="etcd"
ETCD_BIN=$(which etcd 2> /dev/null)
prog=$(basename "$ETCD_BIN")
desc="etcd shared configuration and service discovery daemon"
if [[ ! -e $ETCD_BIN ]]; then
echo "$prog binary not found."
exit 5
fi
ETCD_LOCKFILE="/var/lock/subsys/$prog"
ETCD_LOGFILE=/var/log/etcd/etcd.log
ETCD_PIDFILE=/var/run/etcd.pid
ETCD_CONFIG=/etc/etcd.conf
ETCD_EXEC="$ETCD_BIN -config $ETCD_CONFIG"
start() {
started=$(status -p "$ETCD_PIDFILE" "$ETCD_BIN")
[[ $started =~ running ]] && echo $started && return 1
echo -n $"Starting $prog: "
$ETCD_EXEC 3>&1 2>&1 1>&$ETCD_LOGFILE &
RETVAL=$?
echo $! > $ETCD_PIDFILE
[[ $RETVAL ]] && success || failure
[[ $RETVAL ]] && touch "$ETCD_LOCKFILE"
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p "$ETCD_PIDFILE" "$ETCD_BIN"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -fr "$ETCD_LOCKFILE"
return $RETVAL
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status "$ETCD_BIN"
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
RETVAL=1
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment