diff --git a/templates/default/sysvinit.service.erb b/templates/default/sysvinit.service.erb index 5b3ddf32..c55c6fac 100755 --- a/templates/default/sysvinit.service.erb +++ b/templates/default/sysvinit.service.erb @@ -30,24 +30,27 @@ export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" . /lib/lsb/init-functions _start() { - touch $logfile - chown $user $logfile - start-stop-daemon --start --quiet --background \ - --pidfile $pidfile<% unless @pid_file_external %> --make-pidfile<% end %> \ - --chuid $user --chdir "<%= @directory %>" \ - --startas /bin/bash -- -c "exec $exec <%= @daemon_options %> >> $logfile 2>&1" + touch $logfile + chown $user $logfile + echo "Starting consul" + start-stop-daemon --start --quiet --background \ + --pidfile $pidfile<% unless @pid_file_external %> --make-pidfile<% end %> \ + --chuid $user --chdir "<%= @directory %>" \ + --startas /bin/bash -- -c "exec $exec <%= @daemon_options %> >> $logfile 2>&1" + + _wait_for_listening } _stop() { - start-stop-daemon --stop --quiet --pidfile $pidfile --user $user --retry="<%= @stop_signal %>"/30/KILL/5 + start-stop-daemon --stop --quiet --pidfile $pidfile --user $user --retry="<%= @stop_signal %>"/30/KILL/5 } _status() { - status_of_proc -p $pidfile $exec $prog + status_of_proc -p $pidfile $exec $prog } _reload() { - start-stop-daemon --stop --quiet --pidfile $pidfile --user $user --signal "<%= @reload_signal %>" + start-stop-daemon --stop --quiet --pidfile $pidfile --user $user --signal "<%= @reload_signal %>" } <%- else -%> @@ -62,9 +65,9 @@ _start() { echo -n $"Starting <%= @name %>: " daemon \ - --pidfile=$pidfile \ - --user=$user \ - " { $exec <%= @daemon_options %> >> $logfile 2>&1 & } ; echo \$! >| $pidfile " + --pidfile=$pidfile \ + --user=$user \ + " { $exec <%= @daemon_options %> >> $logfile 2>&1 & } ; echo \$! >| $pidfile " RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $lockfile @@ -106,6 +109,25 @@ _status_q() { _status >/dev/null 2>&1 } +_wait_for_listening() { + echo -n "Waiting for consul daemon to be listening..." + for i in `seq 1 30`; do + sleep 1 + # if ! start-stop-daemon --quiet --stop --test --pidfile $pidfile --user $user; then + if ! _status_q; then + echo " FAIL: consul process died" + return 2 + fi + if "$exec" info >/dev/null; then + echo " OK" + return 0 + fi + echo -n . + done + echo " FAIL: consul process is alive, but is not listening." + return 2 +} + case "$1" in start) _status_q && exit 0