Changed the template a bit

This commit is contained in:
Emile Cantin 2012-04-18 00:59:28 -04:00
parent 58557b9d66
commit 43668425b4
3 changed files with 31 additions and 63 deletions

View File

@ -18,7 +18,7 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Runs <%= app %>" DESC="Runs <%= app %>"
NAME=<%= app %> NAME=<%= app %>
PIDFILE=/var/run/$NAME.pid PIDDIR=/var/run/$NAME
SCRIPTNAME=/etc/init.d/$NAME SCRIPTNAME=/etc/init.d/$NAME
# Read configuration variable file if it is present # Read configuration variable file if it is present
@ -37,67 +37,35 @@ SCRIPTNAME=/etc/init.d/$NAME
# #
do_start() do_start()
{ {
# Return mkdir -p $PIDDIR
# 0 if daemon has been started # START APPLICATION: <%= app %>
# 1 if daemon was already running <% engine.procfile.entries.each do |process| %>
# 2 if daemon could not be started # START PROCESS: <%= process.name %>
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ <% 1.upto(concurrency[process.name]) do |num| %>
|| return 1 # START CONCURRENT: <%= num %>
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ # Code here to start: <%= app %>.<%= process.name %>.<%= num %>
$DAEMON_ARGS \ # (Create $PIDDIR/<%= process.name %>.<%= num %>.pid)
|| return 2 <% end %>
# 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
}
<% end %> <% end %>
<% end %>
### }
# #
# Function that stops the daemon/service # Function that stops the daemon/service
# #
do_stop() do_stop()
{ {
# Return # STOP APPLICATION: <%= app %>
# 0 if daemon has been stopped <% engine.procfile.entries.each do |process| %>
# 1 if daemon was already stopped # STOP PROCESS: <%= process.name %>
# 2 if daemon could not be stopped <% 1.upto(concurrency[process.name]) do |num| %>
# other if a failure occurred # STOP CONCURRENT: <%= num %>
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME # Code here to stop: <%= app %>.<%= process.name %>.<%= num %>
RETVAL="$?" # (Kill $PIDDIR/<%= process.name %>.<%= num %>.pid)
[ "$RETVAL" = 2 ] && return 2 <% end %>
# 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
}
<% end %> <% end %>
<% end %> rmdir $PIDDIR
### }
case "$1" in case "$1" in
start) start)

View File

@ -18,7 +18,7 @@
PATH=/sbin:/usr/sbin:/bin:/usr/bin PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Runs app" DESC="Runs app"
NAME=app NAME=app
PIDFILE=/var/run/$NAME.pid PIDDIR=/var/run/$NAME
SCRIPTNAME=/etc/init.d/$NAME SCRIPTNAME=/etc/init.d/$NAME
# Read configuration variable file if it is present # Read configuration variable file if it is present
@ -52,14 +52,14 @@ do_start()
} }
### START EACH PROCESS ### START EACH PROCESS
do_start_alpha_1() do_start_alpha_1()
{ {
# This starts the process # This starts the process
} }
do_start_bravo_1() do_start_bravo_1()
{ {
# This starts the process # This starts the process
} }
### ###
# #