Skip to content

Commit

Permalink
Merge pull request sous-chefs#433 from zanox/master
Browse files Browse the repository at this point in the history
Improved the _start()  method in the sysv initscript. Until now a sta…
  • Loading branch information
legal90 authored May 19, 2017
2 parents b4c3c47 + 2df9715 commit a0595fb
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions templates/default/sysvinit.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a0595fb

Please sign in to comment.