-
-
Save dhoss/1980554 to your computer and use it in GitHub Desktop.
Managing start_server with start-stop-daemon and graceful restarting.
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
#!/bin/bash | |
PORT=5000 | |
# This should be the directory name/app name | |
APP="TDP" | |
PIDFILE="$HOME/$APP.pid" | |
STATUS="$HOME/$APP.status" | |
# The actual path on disk to the application. | |
APP_HOME="$HOME/$APP" | |
# How many workers | |
WORKERS=4 | |
# This is only relevant if using Catalyst | |
TDP_HOME="$HOME/$APP" | |
export TDP_HOME | |
ERROR_LOG="$HOME/logs/$APP.error.log" | |
STARMAN="starman --workers $WORKERS --error-log $ERROR_LOG $APP_HOME/script/app.psgi" | |
DAEMON="$HOME/perl5/perlbrew/perls/current/bin/start_server" | |
DAEMON_OPTS="--pid-file=$PIDFILE --status-file=$STATUS --port 127.0.0.1:$PORT -- $STARMAN" | |
. $HOME/perl5/perlbrew/etc/bashrc | |
cd $APP_HOME | |
# Here you could even do something like this to ensure deps are there: | |
# cpanm --installdeps . | |
$DAEMON --restart $DAEMON_OPTS | |
# If the restart failed (2 or 3) then try again. We could put in a kill. | |
if [ $? -gt 0 ]; then | |
echo "Restart failed, application likely not running. Starting..." | |
# Rely on start-stop-daemon to run start_server in the background | |
# The PID will be written by start_server | |
/sbin/start-stop-daemon --start --background \ | |
--exec $DAEMON -- $DAEMON_OPTS | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment