Created
September 20, 2016 13:54
-
-
Save misterunknown/f0c6832f10f6599c4e506f78703da62a to your computer and use it in GitHub Desktop.
init script for jdownloader
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/sh | |
### BEGIN INIT INFO | |
# Provides: jdownloader | |
# Required-Start: $networking | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: JDownloader | |
### END INIT INFO | |
PROG_NICK="JDownloader" | |
PROG_NAME="JDownloader.jar" | |
PROG_HOME="/opt/jdownloader" | |
PROG_USER="jdownloader" | |
PROG_RUN="java -jar ${PROG_HOME}/${PROG_NAME}" | |
is_running() { | |
pgrep -f "${PROG_NAME}" >/dev/null | |
[ $? -gt 0 ] && return 1 || return 0 | |
} | |
do_start() { | |
if is_running; then | |
echo "${PROG_NICK} is already running." | |
else | |
echo -n "Start ${PROG_NICK}: " | |
su -l ${PROG_USER} -c "${PROG_RUN} &" >/dev/null 2>&1 | |
echo "done" | |
fi | |
} | |
do_stop() { | |
if ! is_running; then | |
echo "${PROG_NICK} is not running." | |
else | |
echo -n "Stop ${PROG_NICK}: " | |
for i in $(pgrep -f "${PROG_NAME}"); do | |
kill ${i} >/dev/null 2>&1 | |
if ps -p ${i} >/dev/null; then sleep 1; kill -9 ${i} >/dev/null 2>&1; fi | |
done | |
echo "done" | |
fi | |
} | |
do_status() { | |
if is_running; then | |
echo "${PROG_NICK} is running." | |
else | |
echo "${PROG_NICK} is stopped." | |
fi | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
restart) | |
do_stop | |
do_start | |
;; | |
status) | |
do_status | |
;; | |
*) | |
echo "Usage: ${0} {start|stop|restart|status}" | |
exit 3 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment