Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: application-catalyst-foo
- # Required-Start: $local_fs $network
- # Required-Stop: $local_fs $network
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Starts the FastCGI app server for the "Myapp" site
- # Description: The FastCGI application server for the "Myapp" site
- ### END INIT INFO
- PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
- SITE_HOME=/home/user/myapp
- DAEMON=$SITE_HOME/script/myapp_fastcgi.pl
- NAME=myapp_fastcgi
- DESC="'myapp' app server"
- USER=user
- #new stuff
- MAX_PORT=8999
- MIN_PORT=8000
- PORT_FILE=/root/ports/$NAME.port
- NGINX_CONF=/etc/nginx/nginx.conf
- NGINX_PID=`cat /var/run/nginx.pid`
- test -f $DAEMON || exit 0
- #get port
- if [[ -f $PORT_FILE ]]; then
- LAST_PORT=`cat $PORT_FILE`
- PORT_TO_USE=$(($LAST_PORT + 1))
- else
- echo "Must create $PORT_FILE with current port used for FastCGI in $NGINX_CONF"
- echo "Port must be between $MIN_PORT and $MAX_PORT"
- exit
- fi
- # Reset so me don't go up forever
- if [[ $PORT_TO_USE -gt $MAX_PORT ]]; then
- PORT_TO_USE=$MIN_PORT
- fi
- OPTS="-l :$PORT_TO_USE -n 6"
- NEW_PID_FILE="/var/run/$NAME.$PORT_TO_USE.pid"
- OLD_PID_FILE="/var/run/$NAME.$LAST_PORT.pid"
- if [[ -f $OLD_PID_FILE ]]; then
- OLD_PID=`cat $OLD_PID_FILE`
- fi
- set -e
- start_daemon()
- {
- echo "Starting $DESC: $NAME"
- if [[ ! -f $OLD_PID_FILE || $RELOAD -eq 1 ]]; then
- echo "IN HERE DAWG"
- sed -i "s/$LAST_PORT/$PORT_TO_USE/g" $NGINX_CONF
- start-stop-daemon --start --quiet --pidfile $NEW_PID_FILE -d $SITE_HOME \
- --exec /usr/bin/perl --startas $DAEMON --chuid $USER --background --make-pid -- $OPTS
- echo $PORT_TO_USE > $PORT_FILE
- fi
- if [[ $RELOAD -eq 1 ]]; then
- sleep 5
- fi
- echo "Reloading nginx with pid $NGINX_PID."
- kill -HUP $NGINX_PID
- }
- stop_daemon()
- {
- echo -n "Stopping $DESC: "
- if [[ -f $OLD_PID_FILE ]]; then
- start-stop-daemon --stop --signal TERM --pidfile $OLD_PID_FILE
- rm $OLD_PID_FILE
- fi
- echo "$NAME."
- }
- reload_daemon()
- {
- RELOAD=1
- echo "Reloading $DESC: $NAME."
- start_daemon
- stop_daemon
- }
- case "$1" in
- start)
- start_daemon
- ;;
- stop)
- stop_daemon
- ;;
- reload)
- reload_daemon
- ;;
- restart|force-reload)
- stop_daemon
- sleep 5
- start_daemon
- ;;
- *)
- N=/etc/init.d/$NAME
- echo "Usage: $N {start|stop|reload|restart|force-reload}" >&2
- exit 1
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement