Forked from josephspurrier/etc-init.d-hello-world
Created
September 27, 2016 09:10
-
-
Save tsdtsdtsd/bf65a5dd99a1757735de4ec5642dd721 to your computer and use it in GitHub Desktop.
/etc/init.d Script for Go Application
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 | |
# | |
# chkconfig: 35 95 05 | |
# description: Hello world application. | |
# Run at startup: sudo chkconfig hello-world on | |
# Load functions from library | |
. /etc/init.d/functions | |
# Name of the application | |
app="hello-world" | |
# Start the service | |
start() { | |
# If the application is currently running | |
if [ -f /var/lock/subsys/$app ] && ps -p `cat /var/lock/subsys/$app` > /dev/null 2>&1; then | |
status $app | |
exit 1 | |
else | |
echo -n $"Starting $app:" | |
cd /home/ec2-user/workspace/bin/$app | |
./$app > log.out 2> log.err < /dev/null & | |
# Store PID in lock file | |
echo $! > /var/lock/subsys/$app | |
success | |
echo | |
fi | |
} | |
# Restart the service | |
stop() { | |
echo -n "Stopping $app: " | |
killproc $app | |
rm -f /var/lock/subsys/$app | |
echo | |
} | |
# Main logic | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
status $app | |
;; | |
restart|reload) | |
stop | |
start | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|reload|status}" | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment