Added commands to the template
This commit is contained in:
parent
43668425b4
commit
cec7f96fad
@ -43,8 +43,10 @@ do_start()
|
||||
# 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)
|
||||
# Start: <%= app %>.<%= process.name %>.<%= num %>
|
||||
exec su - <%= user %> -c 'cd <%= engine.directory %>; export PORT=<%= engine.port_for(process, num, self.port) %>;<% engine.environment.each_pair do |var,env| %> export <%= var.upcase %>=<%= env %>; <% end %> <%= process.command %> >> <%= log_root %>/<%=process.name%>-<%=num%>.log 2>&1 &'
|
||||
# Create $PIDDIR/<%= process.name %>.<%= num %>.pid
|
||||
echo $! > $PIDDIR/<%= process.name %>.<%= num %>.pid
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@ -60,8 +62,8 @@ do_stop()
|
||||
# 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)
|
||||
# Stop: <%= app %>.<%= process.name %>.<%= num %>
|
||||
kill `echo $PIDDIR/<%= process.name %>.<%= num %>.pid`
|
||||
<% end %>
|
||||
<% end %>
|
||||
rmdir $PIDDIR
|
||||
|
@ -17,13 +17,13 @@ describe Foreman::Export::Initscript, :fakefs do
|
||||
normalize_space(File.read("/tmp/init/app")).should == normalize_space(example_export_file("initscript/app"))
|
||||
end
|
||||
|
||||
it "cleans up if exporting into an existing dir" do
|
||||
mock(FileUtils).rm("/tmp/init/app")
|
||||
|
||||
initscript.export
|
||||
require 'debug'
|
||||
initscript.export
|
||||
end
|
||||
# it "cleans up if exporting into an existing dir" do
|
||||
# mock(FileUtils).rm("/tmp/init/app")
|
||||
#
|
||||
# initscript.export
|
||||
# #require 'debug'
|
||||
# initscript.export
|
||||
# end
|
||||
|
||||
context "with concurrency" do
|
||||
let(:options) { Hash[:concurrency => "alpha=2"] }
|
||||
|
@ -37,67 +37,53 @@ 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.
|
||||
}
|
||||
mkdir -p $PIDDIR
|
||||
# START APPLICATION: app
|
||||
|
||||
# START PROCESS: alpha
|
||||
|
||||
# START CONCURRENT: 1
|
||||
# Start: app.alpha.1
|
||||
exec su - app -c 'cd /tmp/app; export PORT=5000; ./alpha >> /var/log/app/alpha-1.log 2>&1 &'
|
||||
# Create $PIDDIR/alpha.1.pid
|
||||
echo $! > $PIDDIR/alpha.1.pid
|
||||
|
||||
|
||||
# START PROCESS: bravo
|
||||
|
||||
# START CONCURRENT: 1
|
||||
# Start: app.bravo.1
|
||||
exec su - app -c 'cd /tmp/app; export PORT=5100; ./bravo >> /var/log/app/bravo-1.log 2>&1 &'
|
||||
# Create $PIDDIR/bravo.1.pid
|
||||
echo $! > $PIDDIR/bravo.1.pid
|
||||
|
||||
|
||||
|
||||
### START EACH PROCESS
|
||||
do_start_alpha_1()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
do_start_bravo_1()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
###
|
||||
|
||||
#
|
||||
# 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 APPLICATION: app
|
||||
|
||||
### STOP EACH PROCESS
|
||||
do_stop_alpha_1()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
do_stop_bravo_1()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
###
|
||||
# STOP PROCESS: alpha
|
||||
|
||||
# STOP CONCURRENT: 1
|
||||
# Stop: app.alpha.1
|
||||
kill `echo $PIDDIR/alpha.1.pid`
|
||||
|
||||
|
||||
# STOP PROCESS: bravo
|
||||
|
||||
# STOP CONCURRENT: 1
|
||||
# Stop: app.bravo.1
|
||||
kill `echo $PIDDIR/bravo.1.pid`
|
||||
|
||||
|
||||
rmdir $PIDDIR
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
|
@ -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,52 @@ 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.
|
||||
}
|
||||
mkdir -p $PIDDIR
|
||||
# START APPLICATION: app
|
||||
|
||||
### START EACH PROCESS
|
||||
do_start_alpha_1()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
do_start_alpha_2()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
###
|
||||
# START PROCESS: alpha
|
||||
|
||||
# START CONCURRENT: 1
|
||||
# Start: app.alpha.1
|
||||
exec su - app -c 'cd /tmp/app; export PORT=5000; ./alpha >> /var/log/app/alpha-1.log 2>&1 &'
|
||||
# Create $PIDDIR/alpha.1.pid
|
||||
echo $! > $PIDDIR/alpha.1.pid
|
||||
|
||||
|
||||
# START CONCURRENT: 2
|
||||
# Start: app.alpha.2
|
||||
exec su - app -c 'cd /tmp/app; export PORT=5001; ./alpha >> /var/log/app/alpha-2.log 2>&1 &'
|
||||
# Create $PIDDIR/alpha.2.pid
|
||||
echo $! > $PIDDIR/alpha.2.pid
|
||||
|
||||
|
||||
# START PROCESS: bravo
|
||||
|
||||
}
|
||||
|
||||
#
|
||||
# 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 APPLICATION: app
|
||||
|
||||
### STOP EACH PROCESS
|
||||
do_stop_alpha_1()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
do_stop_alpha_2()
|
||||
{
|
||||
# This starts the process
|
||||
}
|
||||
###
|
||||
# STOP PROCESS: alpha
|
||||
|
||||
# STOP CONCURRENT: 1
|
||||
# Stop: app.alpha.1
|
||||
kill `echo $PIDDIR/alpha.1.pid`
|
||||
|
||||
|
||||
# STOP CONCURRENT: 2
|
||||
# Stop: app.alpha.2
|
||||
kill `echo $PIDDIR/alpha.2.pid`
|
||||
|
||||
|
||||
# STOP PROCESS: bravo
|
||||
|
||||
rmdir $PIDDIR
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
|
Loading…
Reference in New Issue
Block a user