Make PlexConnect start with the OS:
- Okay. I am not a linux Guru and I am writing this as I go along so bear with me.
- Furthermore, I assume you used this guide to install plexconnect and that you have installed all the required packages.
- Basically as I understand it (correct me if I am talking crap), if you want something to start at boot time you need to add a script to /etc/rc.d folder,
- Since each jail runs its "own" little os within the jail you want the startup script to start when the vm is booted.
- Also I assume that you are running all the scripts from the root directory. if you use CD to change directory change the commands accordingly.
What you need:
- Putty (or something similar)
- A bit of patience. This is not difficult but you have to do a few things to get it working.
Initial Setup:
Putty
Connect to your Freenas using putty. Then similar to the guide above run the following command:
jls
then run
jexec csh
where jailnumber is the correct jail as returned by jls, if you installed plexconnect on the same jail as plexmediaserver.
Time to get messy:
While inside the jail run the following command to create the service script in rc.d:
nano /etc/rc.d/plexconnect
copy and paste the following code and then save and close the file.
#!/bin/sh
#
#PROVIDE: PlexConnect
#REQUIRE: DAEMON
#KEYWORD: shutdown
. /etc/rc.subr
name=plexconnect
rcvar=plexconnect_enable
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
extra_commands=“status”
plexconnect_start()
{
/usr/local/bin/bash /PlexConnect/PlexConnect_daemon.bash start
}
plexconnect_stop()
{
/usr/local/bin/bash /PlexConnect/PlexConnect_daemon.bash stop
}
plexconnect_status()
{
/usr/local/bin/bash /PlexConnect/PlexConnect_daemon.bash status
}
load_rc_config $name
run_rc_command “$1”
NOTE: if you installed PlexConnect in a different directory change the directory to the bash script.
Next make sure the permissions are the same as the other scripts, run the following script:
chmod 0555 /etc/rc.d/plexconnect
Register the script (we will need this later):
Run the following command to open the rc.conf file:
nano /etc/rc.conf
and add the following line:
plexconnect_enable="Yes"
It should look like this:
portmap_enable="NO"
sshd_enable="NO"
sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
devfs_enable="YES"
devfs_system_ruleset="devfsrules_common"
plexconnect_enable="Yes"
plexmediaserver_enable="YES"
save and close the file.
Check that the script works:
so when you are in the root dir and you call:
/etc/rc.d/plexconnect start
and then calling:
/etc/rc.d/plexconnect status
and it returns:
PlexConnect is running
so great the script works.
Now just run:
/etc/rc.d/plexconnect stop
So we make sure plex is not running before we try to start it as a service.
Setup the plexconnect service:
Now call same command from the service handler:
service plexconnect status
and you will get this if you use /usr/local/bin/bash:
/PlexConnect/PlexConnect_daemon.bash: line 29: python: command not found
No problem. We must edit the PlexConnect_daemon.bash so that it explicitly references the python instance. Run the following to open the .bash script:
nano /PlexConnect/PlexConnect_daemon.bash
You should the the following:
#!/bin/bash
Linux PlexConnect start stop script
Package
DNAME=“PlexConnect”
PNAME=“PlexConnect_daemon”
Others
SOURCE="${BASH_SOURCE[0]}"
while [ -h “$SOURCE” ]; do
DIR="$( cd -P “$( dirname “$SOURCE” )” && pwd )"
SOURCE="$(readlink “$SOURCE”)"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
INSTALL_DIR="$( cd -P “$( dirname “$SOURCE” )” && pwd )"
PYTHON=“python”
PROGRAM="${INSTALL_DIR}/${PNAME}.py"
PID_FILE="/var/${PNAME}.pid"
Edit the PYTHON line as follows (so that it references the python instance explicitly):
PYTHON="/usr/local/bin/python"
Save the file.
FINALLY:
run the following command:
service plexconnect status
and it should return:
PlexConnect is not running
Okay great the service is now working. Thank god. Now just startup plexconnect:
service plexconnect start
So plexconnect is now running and it is a valid service. Yay.
You can then test if it is working by either rebooting your NAS or toggling the plugins on off switch.
FINAL NOTE: When you update plexconnect. Make sure that you remember to re-edit the PlexConnect_daemon.bash file as that will be replaced when updating.
--++00DONE00++--
Edit 1: Changed bash command in script to /usr/local/bin/bash (now the services compiler can find the bash command)
Edit 2: Changed PlexConnect_daemon.bash to point to python to /user/local/bin/python
Edit 3: Added startup to rc.conf
Edit 4: Moved the rc.conf step earlier.
Edit 5: Updated the guide to use only putty.