Skip to content

Instantly share code, notes, and snippets.

@mzsanford
Last active July 28, 2016 20:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mzsanford/27d28d71750edb95f485 to your computer and use it in GitHub Desktop.
Save mzsanford/27d28d71750edb95f485 to your computer and use it in GitHub Desktop.
Init script and defaults file for etcd on Ubuntu
# Set the pper listening address
# export ETCD_PEER_ADDR=127.0.0.1:7001
# Set other command line options like the name and discovery url
# from https://discovery.etcd.io/new
# export ETCD_OPTS="-name=name_here -discovery=https://discovery.etcd.io/token_here"
export ETCD_OPTS=""
#!/bin/sh
### BEGIN INIT INFO
# Provides: etcd
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Start etcd daemon
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /lib/lsb/init-functions
prog="etcd"
prog_bin="/usr/local/bin/$prog"
pidfile=/var/run/$prog.pid
desc="etcd shared configuration and service discovery daemon"
if ! [ -f $prog_bin ]; then
echo "$prog binary not found."
exit 5
fi
if [ -r /etc/default/$prog ]; then
. /etc/default/$prog
fi
start() {
log_daemon_msg "Starting etcd server" "$prog"
start-stop-daemon --start --quiet --oknodo --background --pidfile $pidfile --make-pidfile --exec $prog_bin -- $ETCD_OPTS
status=$?
log_end_msg $status
}
stop() {
log_begin_msg "Stopping etcd server"
start-stop-daemon --stop --pidfile "$pidfile"
status=$?
if [ -f $pidfile ]; then
rm $pidfile
fi
log_end_msg $status
}
restart() {
stop
start
}
status() {
status_of_proc -p "$pidfile" "$prog_bin" etcd
}
case "$1" in
start) start;;
stop) stop;;
restart) restart;;
status) status;;
*) echo "Usage: $0 {start|stop|restart|status}"
RETVAL=2;;
esac
exit $RETVAL
@erickeller
Copy link

thanks for the code snippet

@leeyiw
Copy link

leeyiw commented Apr 13, 2016

The first line of "defaults" has a typo: pper -> peer

@schigh
Copy link

schigh commented Jul 28, 2016

Shouldn't status=$? be RETVAL=$? ?

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