Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,42 @@ | ||
#!/bin/bash | ||
# Start a Catalyst app under FastCGI | ||
# Copyright (c) 2009-2010, Andrew Rodland | ||
# See LICENSE for redistribution conditions. | ||
### BEGIN INIT INFO | ||
# Provides: soundgarden | ||
# Required-Start: $local_fs $network $named | ||
# Required-Stop: $local_fs $network $named | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Soundgarden Catalyst Application | ||
### END INIT INFO | ||
|
||
. /lib/lsb/init-functions | ||
|
||
PERL=/opt/perlbrew/perls/perl-5.14.2/bin/perl | ||
APPNAME=Soundgarden | ||
APPDIR=/var/www/Soundgarden | ||
UNIXNAME=$(echo $APPNAME | perl -pe 's/::/_/;$_=lc') | ||
PROCS=2 | ||
SOCKET=/tmp/soundgarden.socket | ||
# Leave these unset and we won't try to setuid/setgid. | ||
USER=www-data | ||
GROUP=www-data | ||
# Set this if you have more than one instance of the app and you don't want | ||
# them to step on each other's pidfile. | ||
PIDSUFFIX= | ||
|
||
# local::lib path, if you want to use it. | ||
LOCALLIB= | ||
|
||
if [ -f "/etc/default/"$UNIXNAME ]; then | ||
. "/etc/default/"$UNIXNAME | ||
fi | ||
|
||
if [ $(id -u) -eq 0 ] ; then | ||
PIDDIR=/var/run/$UNIXNAME | ||
mkdir $PIDDIR >/dev/null 2>&1 | ||
chown $USER:$GROUP $PIDDIR | ||
chmod 775 $PIDDIR | ||
else | ||
PIDDIR=/tmp | ||
fi | ||
|
||
PIDFILE=$PIDDIR/$UNIXNAME${PIDSUFFIX:+"-$PIDSUFFIX"}.pid | ||
|
||
if [ -n "$LOCALLIB" ] ; then | ||
eval `perl -I"$LOCALLIB/lib/perl5" -Mlocal::lib="$LOCALLIB"` | ||
fi | ||
|
||
check_running() { | ||
[ -s $PIDFILE ] && kill -0 $(cat $PIDFILE) >/dev/null 2>&1 | ||
} | ||
|
||
check_compile() { | ||
if [ -n "$USER" ] ; then | ||
if su - $USER -c "cd $APPDIR ; $PERL -Ilib -M$APPNAME -ce1" ; then | ||
return 0 | ||
fi | ||
return 1 | ||
else | ||
if ( cd $APPDIR ; $PERL -Ilib -M$APPNAME -ce1 ) ; then | ||
return 0 | ||
fi | ||
return 1 | ||
fi | ||
} | ||
|
||
_start() { | ||
start-stop-daemon --start --quiet --pidfile $PIDFILE --chdir $APPDIR \ | ||
${USER:+"--chuid"} $USER ${GROUP:+"--group"} $GROUP --background \ | ||
--startas $PERL $APPDIR/script/${UNIXNAME}_fastcgi.pl -- -n $PROCS -l $SOCKET -p $PIDFILE | ||
|
||
for i in 1 2 3 4 5 6 7 8 9 10; do | ||
sleep 1 | ||
if check_running ; then | ||
return 0 | ||
fi | ||
done | ||
return 1 | ||
} | ||
|
||
start() { | ||
log_daemon_msg "Starting $APPNAME" $UNIXNAME | ||
if check_running; then | ||
log_progress_msg "already running" | ||
log_end_msg 0 | ||
exit 0 | ||
fi | ||
|
||
rm -f $PIDFILE 2>/dev/null | ||
|
||
_start | ||
log_end_msg $? | ||
return $? | ||
} | ||
|
||
_stop() { | ||
start-stop-daemon --stop --user $USER --quiet --oknodo --pidfile $PIDFILE \ | ||
--retry TERM/5/TERM/30/KILL/30 \ | ||
|| log_failure_message "It won't die!" | ||
} | ||
|
||
stop() { | ||
log_daemon_msg "Stopping $APPNAME" $UNIXNAME | ||
|
||
_stop | ||
log_end_msg $? | ||
return $? | ||
} | ||
|
||
restart() { | ||
log_daemon_msg "Restarting $APPNAME" $UNIXNAME | ||
|
||
check_compile && _stop && _start | ||
log_end_msg $? | ||
return $? | ||
} | ||
|
||
# See how we were called. | ||
case "$1" in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
restart|force-reload) | ||
restart | ||
;; | ||
check|check-compile) | ||
check_compile | ||
;; | ||
*) | ||
echo $"Usage: $0 {start|stop|restart|check}" | ||
exit 1 | ||
esac | ||
exit $? | ||
#!/usr/bin/env perl | ||
use warnings; | ||
use strict; | ||
use Daemon::Control; | ||
|
||
# 1) create initd file | ||
# ./soundgarden.starman.initd get_init_file > foo | ||
# | ||
# 2) copy to /etc/init.d/cat-soundgarden | ||
# cp foo /etc/init.d/cat-soundgarden | ||
# | ||
# 3) install to runlevels | ||
# update-rc.d cat-soundgarden defaults | ||
|
||
|
||
my $app_home = '/var/www/Soundgarden'; | ||
my $perl = '/var/www/perl5/perlbrew/perls/perl-5.16.2/bin/perl'; | ||
my $program = $app_home . '/script/soundgarden_fastcgi.pl'; | ||
my $name = 'Soundgarden'; | ||
my $workers = 1; | ||
my $pid_file = $app_home . '/soundgarden.pid'; | ||
my $socket = $app_home . '/soundgarden.socket'; | ||
|
||
Daemon::Control->new({ | ||
name => $name, | ||
lsb_start => '$nginx', | ||
lsb_stop => '$nginx', | ||
lsb_sdesc => $name, | ||
lsb_desc => $name, | ||
path => $app_home . '/soundgarden.fastcgi.initd', | ||
|
||
user => 'www-data', | ||
group => 'www-data', | ||
directory => $app_home, | ||
program => "$perl $program --nproc $workers --listen $socket", | ||
|
||
pid_file => $pid_file, | ||
stderr_file => $app_home . '/soundgarden.out', | ||
stdout_file => $app_home . '/soundgarden.out', | ||
|
||
fork => 2, | ||
})->run; |