[Catalyst] upstart script for Starman-based app?

Morad IGMIR migmir at alliancemca.com
Thu May 3 10:06:23 GMT 2012


So you're looking for an /etc/init.d/ init script ? 

If so, here's a generic version of mine I use, again, in conjunction with
Cx:S:S:Starman

#! /bin/bash
DAEMON_NAME="myapp"
DAEMON_SCRIPT="${DAEMON_NAME}_server"
DAEMON=$(which $DAEMON_SCRIPT)
DAEMON_USER="user"
DAEMON_RUN_DIR="/var/run/starman"
DAEMON_RUN_FILE="${DAEMON_RUN_DIR}/${DAEMON_NAME}.run"
PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

#starman
DAEMON_HOST="0.0.0.0"
DAEMON_PORT=21000
DAEMON_WORKERS=10
DAEMON_CMD="$DAEMON -h $DAEMON_HOST -p $DAEMON_PORT --pidfile
$DAEMON_RUN_FILE --background --workers $DAEMON_WORKERS 2>/dev/null"
#end

. /lib/lsb/init-functions

if [ -n "$DAEMON" -a -x "$DAEMON" ]
then
	echo ""
else
	log_daemon_msg "${DAEMON_SCRIPT} not found in path ${DAEMON}"
	exit
fi

d_start () {
	if [ ! -f  $DAEMON_RUN_FILE ]
	then
		if [ ! -d $DAEMON_RUN_DIR ]
		then
			mkdir $DAEMON_RUN_DIR
			chown $DAEMON_USER:root $DAEMON_RUN_DIR
			chmod 774 $DAEMON_RUN_DIR 
		fi
        	log_daemon_msg "Starting $DAEMON_NAME"
		su -l $DAEMON_USER -c "perl $DAEMON_CMD"
        	log_end_msg $?
	else
		log_daemon_msg "Error when starting $DAEMON_NAME :
$DAEMON_RUN_FILE found"
	fi
}

d_stop () {
	if [ -f  $DAEMON_RUN_FILE ]
	then
	        log_daemon_msg "Stopping system $DAEMON_NAME Daemon"
		RUN=$(head -n1 $DAEMON_RUN_FILE)
		if [ "x" != "x$RUN" ]
		then
		   kill $RUN
		fi
	        rm -rf $DAEMON_RUN_FILE
		log_end_msg $?
	else
		log_daemon_msg "Error when stopping $DAEMON_NAME :
$DAEMON_RUN_FILE not found"
	fi
}

case "$1" in

        start|stop)
                d_${1}
                ;;

        restart)
                        d_stop
                        d_start
                ;;
			
        status)
		if [ -f  $DAEMON_RUN_FILE ]
		then
			RUN=$(head -n1 $DAEMON_RUN_FILE)
			ps -p $RUN 1>/dev/null 2>&1
			if [ $? == 0 ]
			then
				echo "$DAEMON_NAME is running with PID
${RUN}."
			else
				echo "$DAEMON_NAME is not running but
$DAEMON_RUN_FILE subsist."
			fi
		else
			echo "$DAEMON_NAME is not running"
		fi
                ;;
        *)
                echo "Usage: /etc/init.d/$DAEMON_NAME
{start|stop|restart|status}"
                exit 1
                ;;
esac
exit 0

-----Message d'origine-----
De : Octavian Rasnita [mailto:orasnita at gmail.com] 
Envoyé : jeudi 3 mai 2012 11:47
À : The elegant MVC web framework
Objet : Re: [Catalyst] upstart script for Starman-based app?

From: "Morad IGMIR" <migmir at alliancemca.com>
Subject: RE: [Catalyst] upstart script for Starman-based app?


I'm currently using CatalystX::Script::Server::Starman to do just this, it
works fine so far, and you don't need to adapt your script, just use
myapp_server.pl

https://metacpan.org/module/CatalystX::Script::Server::Starman




Thanks. I know about it, but it doesn't solve what I want... to start the
web server automaticly when the computer starts after MySQL was started.

Octavian



_______________________________________________
List: Catalyst at lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list