diff options
Diffstat (limited to 'run.sh')
-rw-r--r-- | run.sh | 44 |
1 files changed, 17 insertions, 27 deletions
@@ -5,7 +5,7 @@ _USER="freenet" WRAPPER_CMD="/usr/bin/java-service-wrapper" WRAPPER_CONF="/opt/freenet/wrapper.config" PIDFILE="/run/freenet/freenet.pid" -TIMEOUT=60 +TIMEOUT=120 #----------------------------------------------------------------------------- fail() { @@ -15,21 +15,19 @@ fail() { check_user() { if [[ "$(id -un)" != "$_USER" ]]; then - SCRIPT_PATH="$(cd $(dirname $0) && pwd)/$(basename $0)" + SCRIPT_PATH="$(cd "$(dirname $0)" && pwd)/$(basename $0)" su - "$_USER" -c "${SCRIPT_PATH} $@" exit $? fi } init_vars() { + [[ "$EUID" -eq 0 ]] && + fail "Attempting to start as root! You should never see this message, please report it" [[ ! -r "$WRAPPER_CONF" ]] && fail "Unable to read \$WRAPPER_CONF: ${WRAPPER_CONF}" [[ ! -x "$WRAPPER_CMD" ]] && fail "Unable to find or execute \$WRAPPER_CMD: ${WRAPPER_CMD}" - [[ ! $(grep -E ^_USER $0) && "$EUID" = "0" ]] && - fail "Attempting to start as root! Please edit $(basename $0) and set the variable \$_USER" - [[ "$(id -un "$_USER")" != "$_USER" ]] && - fail "\$_USER does not exist: $_USER" COMMAND_LINE="\"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"freenet\" wrapper.name=\"freenet\" TZ=UTC" } @@ -52,7 +50,7 @@ check_if_running() { rm -f "$PIDFILE" fi else - [[ "$pid" != "$(get_pid)" ]] && + [[ "$pid" -ne "$(get_pid)" ]] && fail "\$PIDFILE $PIDFILE differs from what is actually running!" fi else @@ -64,8 +62,7 @@ check_if_running() { _console() { if [[ ! "$pid" ]]; then trap '' INT QUIT - eval $COMMAND_LINE - [[ $? != 0 ]] && fail "Failed to launch the wrapper!" + eval "$COMMAND_LINE" || fail "Failed to launch the wrapper!" else echo "Freenet is already running! (pid: $pid)" fi @@ -75,10 +72,9 @@ _start() { if [[ ! "$pid" ]]; then echo -n "Starting Freenet" COMMAND_LINE+=" wrapper.daemonize=TRUE" - eval $COMMAND_LINE - [[ $? != 0 ]] && fail "Failed to launch the wrapper!" + eval "$COMMAND_LINE" || fail "Failed to launch the wrapper!" i=0 - while [[ ! "$pid" || $i < $TIMEOUT ]]; do + while [[ ! "$pid" || $i -lt $TIMEOUT ]]; do echo -n "." sleep 1 check_if_running @@ -93,25 +89,22 @@ _start() { _restart() { [[ "$pid" ]] && - kill -USR1 $(get_wrapper_pid) || echo "Freenet is not running" + kill -USR1 "$(get_wrapper_pid)" || echo "Freenet is not running" } _stop() { if [[ "$pid" ]]; then echo "Stopping Freenet, this will take a few minutes" - kill -TERM $(get_wrapper_pid) - [[ $? != 0 ]] && fail "Unable to stop Freenet: kill -TERM $pid" + kill -TERM "$(get_wrapper_pid)" || fail "Unable to stop Freenet: kill -TERM $pid" i=0 - while [[ "$pid" || $i > $TIMEOUT ]]; do + while [[ "$pid" || $i -gt $TIMEOUT ]]; do echo -n "." sleep 1 [[ ! $(get_pid) ]] && unset pid ((i++)) done - if [[ "$pid" ]]; then - fail "timeout: Failed to stop wrapper!" - fi - echo " done" + [[ "$pid" ]] && + fail "timeout: Failed to stop wrapper! (pid: $pid)" || echo " done" else echo "Freenet is not running." fi @@ -119,10 +112,8 @@ _stop() { _dump() { if [[ "$pid" ]]; then - echo "Dumping threads..." - kill -QUIT $pid - [[ $? != 0 ]] && - fail "Failed to dump Freenet Service" || echo "Dumped Freenet Service." + kill -QUIT "$pid" || fail "Failed to dump Freenet Service" + echo "Thread Dump is available in wrapper.log" else echo "Freenet is not running." fi @@ -130,14 +121,13 @@ _dump() { #----------------------------------------------------------------------------- [[ "$1" != @(console|start|stop|restart|dump) ]] && { - echo "Usage: $(basename $0) [command]" - echo + echo "Usage: $(basename $0) <command>" echo "Commands:" echo " console Launch in the current console" echo " start Start in the background as a daemon process" echo " stop Stop if running as a daemon or in another console" echo " restart Restart the JVM" - echo " dump Request a Java thread dump if running" + echo " dump Request a Java thread dump" exit } |