diff --git a/data/export/initscript/master.erb b/data/export/initscript/master.erb index edb9f0c..bb1bdeb 100644 --- a/data/export/initscript/master.erb +++ b/data/export/initscript/master.erb @@ -18,7 +18,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Runs <%= app %>" NAME=<%= app %> -PIDFILE=/var/run/$NAME.pid +PIDDIR=/var/run/$NAME SCRIPTNAME=/etc/init.d/$NAME # Read configuration variable file if it is present @@ -37,67 +37,35 @@ SCRIPTNAME=/etc/init.d/$NAME # do_start() { - # Return - # 0 if daemon has been started - # 1 if daemon was already running - # 2 if daemon could not be started - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ - || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ - $DAEMON_ARGS \ - || return 2 - # Add code here, if necessary, that waits for the process to be ready - # to handle requests from services started subsequently which depend - # on this one. As a last resort, sleep for some time. -} - -### START EACH PROCESS -<% engine.procfile.entries.each do |process| %> - <% 1.upto(concurrency[process.name]) do |num| %> - do_start_<%= process.name %>_<%= num %>() - { - # This starts the process - } + mkdir -p $PIDDIR + # START APPLICATION: <%= app %> + <% engine.procfile.entries.each do |process| %> + # START PROCESS: <%= process.name %> + <% 1.upto(concurrency[process.name]) do |num| %> + # START CONCURRENT: <%= num %> + # Code here to start: <%= app %>.<%= process.name %>.<%= num %> + # (Create $PIDDIR/<%= process.name %>.<%= num %>.pid) + <% end %> <% end %> -<% end %> -### + +} # # Function that stops the daemon/service # do_stop() { - # Return - # 0 if daemon has been stopped - # 1 if daemon was already stopped - # 2 if daemon could not be stopped - # other if a failure occurred - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME - RETVAL="$?" - [ "$RETVAL" = 2 ] && return 2 - # Wait for children to finish too if this is a daemon that forks - # and if the daemon is only ever run from this initscript. - # If the above conditions are not satisfied then add some other code - # that waits for the process to drop all resources that could be - # needed by services started subsequently. A last resort is to - # sleep for some time. - start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON - [ "$?" = 2 ] && return 2 - # Many daemons don't delete their pidfiles when they exit. - rm -f $PIDFILE - return "$RETVAL" -} - -### STOP EACH PROCESS -<% engine.procfile.entries.each do |process| %> - <% 1.upto(concurrency[process.name]) do |num| %> - do_stop_<%= process.name %>_<%= num %>() - { - # This starts the process - } + # STOP APPLICATION: <%= app %> + <% engine.procfile.entries.each do |process| %> + # STOP PROCESS: <%= process.name %> + <% 1.upto(concurrency[process.name]) do |num| %> + # STOP CONCURRENT: <%= num %> + # Code here to stop: <%= app %>.<%= process.name %>.<%= num %> + # (Kill $PIDDIR/<%= process.name %>.<%= num %>.pid) + <% end %> <% end %> -<% end %> -### + rmdir $PIDDIR +} case "$1" in start) diff --git a/lib/foreman/export/.initscript.rb.swp b/lib/foreman/export/.initscript.rb.swp deleted file mode 100644 index b2f0d15..0000000 Binary files a/lib/foreman/export/.initscript.rb.swp and /dev/null differ diff --git a/spec/resources/export/initscript/app b/spec/resources/export/initscript/app index 15b3466..4c50558 100644 --- a/spec/resources/export/initscript/app +++ b/spec/resources/export/initscript/app @@ -18,7 +18,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="Runs app" NAME=app -PIDFILE=/var/run/$NAME.pid +PIDDIR=/var/run/$NAME SCRIPTNAME=/etc/init.d/$NAME # Read configuration variable file if it is present @@ -52,14 +52,14 @@ do_start() } ### START EACH PROCESS - do_start_alpha_1() - { - # This starts the process - } - do_start_bravo_1() - { - # This starts the process - } +do_start_alpha_1() +{ + # This starts the process +} +do_start_bravo_1() +{ + # This starts the process +} ### #