mirror of
https://gitlab.com/LazyLibrarian/LazyLibrarian.git
synced 2026-02-06 10:47:15 +00:00
Init.d script contained a space after the `--daemon` flag, which would ultimately become a double space when paired with any of the following flags. The double space would cause the `pgrep` in the `is_running()` function to not find any results, since the double space would be parsed out by the kernel but still exist in the `$DAEMON_OPTS` variable that is being used to grep. When `is_running()` fails the application cannot be stopped, since it doesn't believe it's running. Additionally, on certain versions of Debian there is an issue when running `start-stop-daemon` with a `--pidfile` that is not owned by root. This causes the stop command to fail and an error to be displayed. Include the `--user $RUN_AS` flag as a workaround.
151 lines
4.0 KiB
Bash
Executable File
151 lines
4.0 KiB
Bash
Executable File
#! /bin/sh
|
|
|
|
# Copyright (C) 2011- by Mar2zz <LaSi.Mar2zz@gmail.com>
|
|
# released under GPL, version 2 or later
|
|
|
|
|
|
################################################
|
|
# #
|
|
# TO CONFIGURE EDIT /etc/default/lazylibrarian
|
|
# #
|
|
################################################
|
|
|
|
### BEGIN INIT INFO
|
|
# Provides: LazyLibrarian
|
|
# Required-Start: $all
|
|
# Required-Stop: $all
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# Short-Description: starts instance of LazyLibrarian
|
|
# Description: starts instance of LazyLibrarian using start-stop-daemon
|
|
### END INIT INFO
|
|
|
|
|
|
# main variables
|
|
DAEMON=/usr/bin/python3
|
|
SETTINGS=/etc/default/lazylibrarian
|
|
|
|
SETTINGS_LOADED=FALSE
|
|
|
|
DESC=LazyLibrarian
|
|
|
|
# only accept values from /etc/default/lazylibrarian
|
|
unset RUN_AS CONFIG DATADIR PID_FILE
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
[ -x $DAEMON ] || {
|
|
log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON";
|
|
return 1; }
|
|
|
|
[ -r $SETTINGS ] || {
|
|
log_warning_msg "$DESC: Can't read settings, aborting. See $SETTINGS";
|
|
return 1; }
|
|
|
|
check_retval() {
|
|
if [ $? -eq 0 ]; then
|
|
log_end_msg 0
|
|
return 0
|
|
else
|
|
log_end_msg 1
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
load_settings() {
|
|
if [ $SETTINGS_LOADED != "TRUE" ]; then
|
|
. $SETTINGS
|
|
|
|
[ -n "$APP_PATH" ] || {
|
|
log_warning_msg "$DESC: path to $DESC not set, aborting. See $SETTINGS";
|
|
return 1; }
|
|
|
|
[ $ENABLE_DAEMON != 1 ] && {
|
|
log_warning_msg "$DESC: daemon not enabled, aborting. See $SETTINGS";
|
|
return 1; }
|
|
|
|
[ -z "$RUN_AS" ] && {
|
|
log_warning_msg "$DESC: daemon username not set, aborting. See $SETTINGS";
|
|
return 1; }
|
|
[ -z "${RUN_AS%:*}" ] && exit 1
|
|
|
|
DAEMON_OPTS="LazyLibrarian.py --nolaunch --daemon"
|
|
[ -n "$CONFIG" ] && DAEMON_OPTS="$DAEMON_OPTS --config=$CONFIG"
|
|
[ -z "$CONFIG" ] && DAEMON_OPTS="$DAEMON_OPTS --config=/home/$RUN_AS/.lazylibrarian/config.ini"
|
|
[ -n "$DATADIR" ] && DAEMON_OPTS="$DAEMON_OPTS --datadir=$DATADIR"
|
|
[ -z "$DATADIR" ] && DAEMON_OPTS="$DAEMON_OPTS --datadir=/home/$RUN_AS/.lazylibrarian"
|
|
[ -n "$PORT" ] && DAEMON_OPTS="$DAEMON_OPTS --port=$PORT"
|
|
if ! [ -n "$PID_FILE" ]; then
|
|
PID_FILE=/var/run/lazylibrarian/lazylibrarian.pid
|
|
fi
|
|
DAEMON_OPTS="$DAEMON_OPTS --pidfile=$PID_FILE"
|
|
SETTINGS_LOADED=TRUE
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
load_settings || exit 0
|
|
|
|
is_running () {
|
|
# returns 1 when running, else 0.
|
|
PID=$(pgrep -f "$DAEMON_OPTS")
|
|
RET=$?
|
|
[ $RET -gt 1 ] && exit 1 || return $RET
|
|
}
|
|
|
|
handle_pid () {
|
|
PID_PATH=`dirname $PID_FILE`
|
|
[ -d $PID_PATH ] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || {
|
|
log_warning_msg "$DESC: Could not create $PID_FILE, aborting.";
|
|
return 1;}
|
|
}
|
|
|
|
enable_updates () {
|
|
chown -R $RUN_AS $APP_PATH > /dev/null || {
|
|
log_warning_msg "$DESC: $APP_PATH not writable for web-updates, See $SETTINGS";
|
|
return 0; }
|
|
}
|
|
|
|
start_lazylibrarian () {
|
|
if ! is_running; then
|
|
log_daemon_msg "Starting $DESC"
|
|
[ "$WEB_UPDATE" = 1 ] && enable_updates
|
|
handle_pid
|
|
start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS
|
|
check_retval
|
|
else
|
|
log_success_msg "$DESC: already running (pid $PID)"
|
|
fi
|
|
}
|
|
|
|
stop_lazylibrarian () {
|
|
if is_running; then
|
|
log_daemon_msg "Stopping $DESC"
|
|
start-stop-daemon -o --stop --user $RUN_AS --pidfile $PID_FILE --retry 15
|
|
check_retval
|
|
else
|
|
log_success_msg "$DESC: not running"
|
|
fi
|
|
}
|
|
|
|
|
|
case "$1" in
|
|
start)
|
|
start_lazylibrarian
|
|
;;
|
|
stop)
|
|
stop_lazylibrarian
|
|
;;
|
|
restart|force-reload)
|
|
stop_lazylibrarian
|
|
start_lazylibrarian
|
|
;;
|
|
*)
|
|
N=/etc/init.d/$NAME
|
|
echo "Usage: $N {start|stop|restart|force-reload}" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|