-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restart option added to sysvinit script #89
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,71 @@ | ||
#! /bin/sh | ||
#! /bin/bash | ||
|
||
### BEGIN INIT INFO | ||
# Provides: ${{app_name}} | ||
# Required-Start: $syslog | ||
# Required-Stop: $syslog | ||
# Default-Start: 2 3 4 5 | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: | ||
# Short-Description: ${{descr}} | ||
### END INIT INFO | ||
|
||
PIDFILE=/var/run/${{app_name}}.pid | ||
DAEMON_USER=${{daemon_user}} | ||
|
||
. /lib/init/vars.sh | ||
. /lib/lsb/init-functions | ||
test -e /etc/default/${{app_name}} && source /etc/default/${{app_name}} | ||
source /lib/init/vars.sh | ||
source /lib/lsb/init-functions | ||
|
||
get_java_cmd() { | ||
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then | ||
if [ -x "$JAVA_HOME/bin/java" ]; then | ||
echo "$JAVA_HOME/bin/java" | ||
else | ||
echo "java" | ||
echo `which java` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, I always prefer the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll use $(which java) next time. Thanks! Regards, Alexey
|
||
fi | ||
} | ||
|
||
JAVA_CMD=$(get_java_cmd) | ||
PIDFILE=/var/run/${{app_name}}.pid | ||
|
||
RUN_CMD=$JAVA_CMD -cp ${{app_classpath}} ${{app_main_class}} | ||
if [ -z "$DAEMON_USER" ]; then | ||
DAEMON_USER=${{daemon_user}} | ||
fi | ||
|
||
case "$1" in | ||
if [ -z "$JAVA_CMD" ]; then | ||
JAVA_CMD=$(get_java_cmd) | ||
fi | ||
|
||
start) log_daemon_msg "Starting ${{app_name}}" | ||
# smb could define some additional options in $RUN_OPTS | ||
RUN_CMD="-cp ${{app_classpath}} ${{app_main_class}} $RUN_OPTS" | ||
|
||
start-stop-daemon --background --start --chuid $DAEMON_USER --make-pidfile --pidfile $PIDFILE --exec $RUN_CMD | ||
|
||
;; | ||
stop) log_daemon_msg "Stopping ${{app_name}}" | ||
start_daemon() { | ||
log_daemon_msg "Starting ${{app_name}}" | ||
start-stop-daemon --background --start --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$JAVA_CMD" --start -- $RUN_CMD | ||
} | ||
|
||
|
||
start-stop-daemon --stop --pidfile $PIDFILE --chuid $DAEMON_USER | ||
stop_daemon() { | ||
log_daemon_msg "Stopping ${{app_name}}" | ||
start-stop-daemon --stop --pidfile "$PIDFILE" --user "$DAEMON_USER" | ||
|
||
RETVAL=$? | ||
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE | ||
exit 2 | ||
RETVAL=$? | ||
[ $RETVAL -eq 0 ] && [ -e "$PIDFILE" ] && rm -f $PIDFILE | ||
exit 2 | ||
} | ||
|
||
|
||
case "$1" in | ||
|
||
start) | ||
start_daemon | ||
;; | ||
stop) | ||
stop_daemon | ||
;; | ||
*) log_daemon_msg "Usage: /etc/init.d/${{app_name}} {start|stop}" | ||
exit 2 | ||
;; | ||
restart) | ||
stop_daemon | ||
start_daemon | ||
;; | ||
*) | ||
log_daemon_msg "Usage: /etc/init.d/${{app_name}} {start|stop}" | ||
exit 2 | ||
;; | ||
esac | ||
exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So user configuration is under /etc/default/ for the runner of the script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be overwritten in /etc/defaults
Regards, Alexey
On Nov 26, 2013 6:50 PM, "Josh Suereth" [email protected] wrote: