Great NEWS all!
I know have a functional way to get PlexRequests.net working with start, stop, restart and status command from a terminal widow. I also have a functioning script to test it on a cron job and to restart it if it's not up. All without the needs of using the HX-Engine or relying on something that can't be stoped. (Which the previously written scripts had issues with. SO disregard any of the previous scripts for this, posted in this thread and use these instead!
The first one is the biggy. This gives start, stop, restart and status from the command line. I called it
PlexRequests2.sh, but you can name it what makes sense to you:
Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides: PlexRequests.net
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: PlexRequests.net
# Description: PlexRequests.net
### END INIT INFO
# Documentation available at
# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
# Debian provides some extra functions though
. /lib/lsb/init-functions
USER=admin
GROUP=administrators
DAEMON_NAME="PlexRequests"
DAEMON_USER="${USER}:${GROUP}"
DAEMON_PATH="/usr/local/bin/mono"
DAEMON_PACK_PATH="/volume1/misc/PlexRequests"
DAEMON_OPTS=${DAEMON_PACK_PATH}/PlexRequests.exe
DAEMON_PWD="/volume1/misc/PlexRequests/"
DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description")
DAEMON_PID=${DAEMON_PACK_PATH}/PlexRequests.pid
DAEMON_NICE=0
DAEMON_LOG='/volume1/misc/PlexRequests/PlexRequests.log'
[ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}"
do_start() {
local result
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
if [ $? -eq 0 ]; then
log_warning_msg "${DAEMON_NAME} is already started"
result=0
else
log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
touch "${DAEMON_LOG}"
chown $DAEMON_USER "${DAEMON_LOG}"
chmod u+rw "${DAEMON_LOG}"
if [ -z "${DAEMON_USER}" ]; then
start-stop-daemon -S --background --quiet --chuid "${DAEMON_USER}" --user "${USER}" --pidfile "${DAEMON_PID}" --make-pidfile --exec "$DAEMON_PATH" -- "$DAEMON_OPTS"
result=$?
else
start-stop-daemon -S --background --quiet --chuid "${DAEMON_USER}" --user "${USER}" --pidfile "${DAEMON_PID}" --make-pidfile --exec "$DAEMON_PATH" -- "$DAEMON_OPTS"
result=$?
fi
log_end_msg $result
fi
return $result
}
do_stop() {
local result
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
if [ $? -ne 0 ]; then
log_warning_msg "${DAEMON_NAME} is not started"
result=0
else
log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
result=$?
log_end_msg $result
rm "${DAEMON_PID}"
fi
return $result
}
do_restart() {
local result
do_stop
result=$?
if [ $result = 0 ]; then
do_start
result=$?
fi
return $result
}
do_status() {
local result
status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
result=$?
return $result
}
do_usage() {
echo $"Usage: $0 {start | stop | restart | status}"
exit 1
}
case "$1" in
start) do_start; exit $? ;;
stop) do_stop; exit $? ;;
restart) do_restart; exit $? ;;
status) do_status; exit $? ;;
*) do_usage; exit 1 ;;
esac
This was a lot of trouble shooting, testing and editing to make work, using the scripts found here as a base:
http://www.htpcguides.com/install-plex- ... untu-14-x/. I also had to go into the Sonarr scripts for starting and stopping and do some edits based on those, to make all of this work right. Test in PuTTY first, and kick off your browser to the NAS IP and port. You can configure the port in the settings for the app, if you don't want to use the defaults. I put this into my usual place
/volume1/misc If you make changes to this path, make sure you touch the following script as well to reflect that change.
Now we need to check to see if it's running, so that's another script. This one is a lot like many of the other scripts you've seen of mine, which uses curl to test for a web output on the port. I called this (in keeping with previous scripts)
ChkPlexRequests.sh and it's also located in the same directory I put all of the other scripts:
/volume1/misc If there is a valid output on that page this script exits. If not, then call the first script I put on this page with a restart command to get PlexRequests running:
Code: Select all
#!/bin/sh
#######################################################################################
# This script tests to make sure the PlexRequests.net application is running on your #
# Asustor NAS. If it is the script exits and does nothing. If not it will restart #
# PlexRequests as a daemon so the app is always running. This app is usefull #
# because you can set it to monitor your HDD space, and view recently added shows #
# and movies within Plex. #
# --------------------------------------------------------------------------------- #
# You can change this to test for remote access by changing the localhost to the #
# DNS name of your NAS. Ex: If you use Asustor's DDNS service it would be something #
# like http://yourddnsname.myasustor.com: If you are using PlexRequests.net on #
# another port than 3579 you will need to edit the script below to reflect the port #
# number. #
# --------------------------------------------------------------------------------- #
# This can be used to test operation of any app that has a web page for accessing #
# the app itself. If the app is a stand alone app and doesn't use a web page #
# this check will not work. There are other ways to check their operations. #
# --------------------------------------------------------------------------------- #
# Visit http://forum.asustor.com/index.php and ask MikeG.6.5 for any support issues #
#######################################################################################
curl -I -m 8 "localhost:3579/userlogin";
if [ "$?" -ne "0" ]
then
/usr/sbin/syslog --log 0 --level 0 --user admin --event "PlexRequests isn't running: Starting it"
/volume1/misc/PlexRequests2.sh restart
fi
exit 0
REMEMBER if you change the port to something other than the defaults of 3579 in the app, it will ALWAYS restart PlexRequests.net. You need to change the line that reads
curl -I -m 8 "localhost:3579/userlogin"; to read the port you are using rather than the 3579 it's set to now! You been warned (at least 3 times now!)
Next, to test this every 15 minutes, you need to edit the cron file found here:
/var/spool/cron/crontabs/root Put this line into it:
Code: Select all
*/15 * * * * /volume1/misc/ChkPlexRequests.sh
This executes the second script on this page every 15 minutes on the hour. (on the hour, 1/4 after, 1/2 past, 3/4 hour, etc.) This will put a line into your Asustor log files, and if you have Pushbullet configured, you can get a text message automatically, every time PlexRequests needs to be restarted.
Once you have PlexRequests and the scripts all configured you can shut down the PuTTY session that you had PlexRequests running on and it should kick off a new daemon on the next quarter hour if everything is done right. (Correct paths, ports, etc.)
A lot of efforts went into this, and I'm not a wizard at scripting. Let me know if you have issues, or what you think about it.
EDIT!!! This is buggier than a roach convention in Florida. Go back to using the other method, for now. If someone wants to try troubleshooting this, go for it. Post the replacement scripts and let us know in this thread, please?