slackbuilds_ponce/multimedia/sickchill/rc.sickchill
Jeremy Hansen c511d2dc98 multimedia/sickchill: Added (Video Library Manager).
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
2023-07-15 17:24:53 +07:00

118 lines
3.1 KiB
Bash

#!/bin/bash
# Start/stop/restart sickchill.
# rc.sickrage created by Jeremy Hansen for Slackware in 2016
# rc.sickchill was updated by Jeremy Hansen for Slackware in 2023
# Set program name in case you want to run sick{beard|rage|gear|etc}
PROG=${PROG:-sickchill}
# Source SickRage configuration
if [ -f /etc/"$PROG".conf ]; then
. /etc/"$PROG".conf
fi
# Ensure all required variables are set in conf file
# Edit conf file in /etc/sickchill.conf for any changes
for var in USERNAME HOMEDIR DATADIR PIDFILE PORT; do
if [ -z "${!var}" ]; then
echo "/etc/$PROG.conf is missing some or all required variables ($var)."
echo "Please check the file and try again."
exit 1
fi
done
# Check if the program is running and pid file exists
check() {
if pgrep "$PROG" > /dev/null; then
if [ -e "$PIDFILE" ] && ! pgrep -F "$PIDFILE" > /dev/null; then
STATUS=broken
echo "WARNING: $PROG is running, but its PID does not match the one in $PIDFILE."
elif [ ! -e "$PIDFILE" ]; then
STATUS=broken
echo "WARNING: $PROG is running, but $PIDFILE does not exist."
echo "Maybe you ran $PROG from the commandline rather than rc.sickchill?"
else
STATUS=running
fi
else
if [ -e "$PIDFILE" ]; then
STATUS=broken
echo "WARNING: $PROG is not running but $PIDFILE exists."
else
STATUS=stopped
fi
fi
}
status() {
if [ $STATUS == "running" ]; then
echo "$PROG currently running."
elif [ $STATUS == "stopped" ]; then
echo "$PROG not running."
elif [ $STATUS == "broken" ]; then
echo "Please fix the issue before attempting to run $(basename "$0") again."
else
echo "Status unknown."
fi
}
start() {
if [ $STATUS == "running" ]; then
echo "$PROG already running or not shut down properly."
else
echo -n "Starting $PROG: "
if su "$USERNAME" -s /bin/sh -c "/usr/bin/sickchill --daemon --pidfile=${PIDFILE} --datadir=${DATADIR} --port=${PORT} &> /dev/null"; then
echo "Startup Successful"
else
echo "Startup Failed. Please try running the following to see the errors."
echo "su $USERNAME -s /bin/sh -c \"/usr/bin/sickchill --daemon --pidfile=${PIDFILE} --datadir=${DATADIR} --port=${PORT}\""
fi
fi
}
stop() {
if [ $STATUS == "stopped" ]; then
echo "$PROG doesn't seem to be running. Please try running"
echo "$0 start"
elif [ $STATUS == "broken" ]; then
echo "Cannot stop. Please correct issue and try again."
else
if [ "$EUID" -ne 0 ];then
echo "Please run as root"
exit 1
fi
PID=$(cat "$PIDFILE")
echo -n $"Shutting down $PROG: "
if ! curl -s http://localhost:"$PORT"/home/shutdown/?pid="$PID" | grep -q "shutting down"; then
echo "Normal Shutdown Failed - Attempting to kill the process."
sleep 7
kill -9 "$PID"
else
echo "Shutdown Successful"
fi
fi
}
case "$1" in
start)
check
start
;;
stop)
check
stop
;;
restart)
check
stop
start
;;
status)
check
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac