Forked from josephspurrier/etc-init.d-hello-world
Created
September 27, 2016 04:29
-
-
Save smallnest/f34810d15392a50ba7c82fd2cee8da2d to your computer and use it in GitHub Desktop.
/etc/init.d Script for Go Application
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/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