Created
February 15, 2016 11:51
-
-
Save WildGenie/df614b906de8a606a52e to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
#/etc/init.d/MyMonoApp | |
# | |
APP_NAME="MyMonoApp" | |
APP_PATH="/home/mono/MyMonoApp" | |
APP_USER=mono | |
case "$1" in | |
start) | |
echo "Starting $APP_NAME" | |
start-stop-daemon --start \ | |
--background \ | |
--make-pidfile \ | |
--pidfile /var/run/$APP_NAME.pid \ | |
--chuid $APP_USER \ | |
--exec "$APP_PATH/$APP_NAME" | |
;; | |
stop) | |
echo "Stopping $APP_NAME" | |
start-stop-daemon -o --stop \ | |
--pidfile /var/run/$APP_NAME.pid | |
;; | |
*) | |
echo "Usage: /etc/init.d/$APP_NAME {start|stop}" | |
exit 1 | |
;; | |
esac | |
exit 0 |
This file contains hidden or 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/sh | |
#!/home/mono/MyMonoApp | |
APP_NAME=`basename $0` | |
APP_DIR=`dirname $0` | |
HOSTNAME=`hostname` | |
cd $APP_DIR | |
tail --lines=300 output.log | mail -s "MyMonoApp $HOSTNAME:$APP_NAME STARTED" "[email protected]" | |
exitcode=0 | |
until [ $exitcode -eq 9 ] | |
do | |
startdate="$(date +%s)" | |
/usr/local/bin/mono MyMonoApp.exe $HOSTNAME:$APP_NAME > output.log | |
exitcode=$? | |
enddate="$(date +%s)" | |
echo "EXIT CODE = $exitcode" >> output.log | |
cp -f output.log output.log.1 | |
elapsed_seconds="$(expr $enddate - $startdate)" | |
echo "Elapsed seconds $elapsed_seconds" | |
subject="EXIT CODE: $exitcode" | |
echo "BASH: Exit Code = $exitcode" | |
if [ $exitcode -eq 6 ] #Restart | |
then | |
subject="RESTART" | |
elif [ $exitcode -eq 7 ] #Previous version | |
then | |
subject="PREVIOUS VERSION" | |
cp -fv MyMonoApp.exe_previous MyMonoApp.exe | |
elif [ $exitcode -eq 8 ] #Update | |
then | |
subject="SOFTWARE UPDATE" | |
cp -fv MyMonoApp.exe MyMonoApp.exe_previous | |
mv -fv MyMonoApp.exe_new MyMonoApp.exe | |
elif [ $exitcode -eq 9 ] #Shutdown | |
then | |
subject="SHUTDOWN" | |
fi | |
if [ $elapsed_seconds -ge 10 ] #been running for longer than 10 seconds | |
then | |
tail --lines=300 output.log | mail -s "MyMonoApp $HOSTNAME:$APP_NAME $subject" "[email protected]" | |
sleep 1 # tiny delay to let things settle | |
else | |
sleep 5 # delay to protect against eating the CPU resourses | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment