Created
April 25, 2018 11:10
-
-
Save olegbuevich/83fb1ade8ff84244c12ffcf0973d4bae to your computer and use it in GitHub Desktop.
ubuntu 14.04 play framework init.d template
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 | |
### BEGIN INIT INFO | |
# Provides: ${{app_name}} | |
# Required-Start: ${{start_facilities}} | |
# Required-Stop: ${{stop_facilities}} | |
# Default-Start: ${{start_runlevels}} | |
# Default-Stop: ${{stop_runlevels}} | |
# Short-Description: ${{descr}} | |
### END INIT INFO | |
source /lib/init/vars.sh | |
source /lib/lsb/init-functions | |
# Source from package defined config. Defaults to, | |
# bashScriptEnvConfigLocation := Some("/etc/default/" + (packageName in Linux).value) | |
[[ -f ${{env_config}} ]] && . ${{env_config}} | |
# $JAVA_OPTS used in $RUN_CMD wrapper | |
export JAVA_OPTS | |
export PIDFILE | |
# If program manages its own PID file then it | |
# should declare its location in PIDFILE | |
if [ -z "$PIDFILE" ]; then | |
create_pidfile=true | |
PIDFILE=/var/run/${{app_name}}/play.pid | |
fi | |
if [ -z "$DAEMON_USER" ]; then | |
DAEMON_USER=${{daemon_user}} | |
fi | |
if [ -z "$DAEMON_GROUP" ]; then | |
DAEMON_GROUP=${{daemon_group}} | |
fi | |
RUN_CMD="bin/${{exec}}" | |
RUN_OPTS="> /var/log/${{app_name}}/daemon.log 2>&1" | |
start_daemon() { | |
log_daemon_msg "Starting" "${{app_name}}" | |
[ -d "/var/run/${{app_name}}" ] || install -d -o "$DAEMON_USER" -g "$DAEMON_GROUP" -m755 "/var/run/${{app_name}}" | |
start-stop-daemon --background --chdir ${{chdir}} --chuid "$DAEMON_USER" --pidfile "$PIDFILE" --startas /bin/bash --start -- -c "exec $RUN_CMD $RUN_OPTS" | |
log_end_msg $? | |
} | |
stop_daemon() { | |
log_daemon_msg "Stopping" "${{app_name}}" | |
start-stop-daemon --stop --quiet --oknodo --pidfile "$PIDFILE" --retry=TERM/${{term_timeout}}/KILL/${{kill_timeout}} | |
log_end_msg $? | |
if [ "$create_pidfile" = true ]; then | |
rm -f "$PIDFILE" | |
fi | |
} | |
case "$1" in | |
start) | |
start_daemon | |
exit $? | |
;; | |
stop) | |
stop_daemon | |
exit $? | |
;; | |
restart|force-reload) | |
stop_daemon | |
start_daemon | |
exit $? | |
;; | |
status) | |
status_of_proc -p "$PIDFILE" "$RUN_CMD" ${{app_name}} && exit 0 || exit $? | |
;; | |
*) | |
log_daemon_msg "Usage: /etc/init.d/${{app_name}} {start|stop|restart|status}" | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment