Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the _start() method in the sysv initscript. Until now a sta… #433

Merged
merged 6 commits into from
May 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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