PlexRequests on Asustor

Share your awesome tips and tricks here.

Moderator: Lillian.W@AST

sanaritaamit
Posts: 2
youtube meble na wymiar Warszawa
Joined: Wed Dec 07, 2016 11:01 pm

Re: PlexRequests on Asustor

Post by sanaritaamit »

I kindly request anybody of the bests to:

1. Kindly show how can we run Meteor 1.4 and Mongo in asustor NAS. Step by step guide.
2. How can we access that localhost:3000 from the Network.

Regards
Amit.
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Re: PlexRequests on Asustor

Post by MikeG.6.5 »

I've already outlined doing the Meteor version in the first post of this thread. Keep in mind you NEED to have Father.Mande's HX-Desktop running in order to make that version work! You can find that in the 3rd party apps sub-forum.

To get PlexRequests.net working is so much easier!

1) Install Mono from App Central.
2) Make a directory to put the PlexRequests.net files into, one that can be seen by all of the users on the NAS. (I use /volume1/misc/PlexRequests.net)
3) Unzip the PlexRequests.net zip into this folder, moving the files to the top level of the folder. (When you unzip it, there is a sub folder made, and all files are moved to that by default. I just moved them up a level and deleted the unzipped destination.)
4) Test this by opening a PuTTY session and cd into the PlexRequests destination folder and run mono /volume1/Misc/plexrequests/PlexRequests.exe and then log into it from a computer's browser session to http://your.nas.ip.here:port. (Remember, PlexRequests by default, sets the port to 3579 by default, but you can change this once you get it to work and edit the settings.)
5) With WinSCP make a new file called ChkPlexRequests.sh in the /volume1/misc folder and put this into it:

Code: Select all

#!/bin/sh

curl -I -m 8 "localhost:port/userlogin";
if [ "$?" -ne "0" ]

then
/usr/sbin/syslog --log 0 --level 0 --user admin --event "PlexRequests isn't running: Starting it" 
exec nohup mono /volume1/misc/plexrequests/PlexRequests.exe &
fi

exit 0
8) Edit the script above to have your NAS's IP and the port you want to use, notice right now it says localhost:port
9) Edit the cron file found here: /var/spool/cron/crontabs/root to have this line in it:

Code: Select all

*/5 * * * * /volume1/misc/ChkPlexRequests.sh
10) Close the PuTTY session, and then open a new one and run this, then shut down PuTTY: exec nohup mono /volume1/misc/plexrequests/PlexRequests.exe &
11) Go back into your browser and refresh the page. You know everything is working right if you don't get a time out error.

And many thanks to @richardpoyner for help with the scripts and the executable line to make this run as a daemon.
MikeG.6.5
Posts: 917
Joined: Fri May 15, 2015 1:56 am

Re: PlexRequests on Asustor

Post by MikeG.6.5 »

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?
Post Reply

Return to “Tips & Tricks”