How can I turn PlexConnect into a service that can be started, stopped, restarted etc?
Sent from my iPhone using Tapatalk
On Linux use the following:
sudo ./PlexConnect_daemon.bash start
sudo ./PlexConnect_daemon.bash status
sudo ./PlexConnect_daemon.bash stop
OK, so this is a bit of a hijack, but if you changed the INSTALL_DIR part of PlexConnect_daemon.bash to the following, you would be able to run the script from anywhere, including from symlinks in directories dedicated to running scripts at startup time.
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 )"
(With this, all other directory changes can be removed as well.)
EDIT: and restart can be added with
restart)
# Restart the daemon.
$0 stop && sleep 2 && $0 start && sleep 2 && $0 status
;;
Hm. Do you need that "while" - I guess to follow symlinks?
In /support/OSX we have a similar "program directory find" in install.bash. If I remember correctly it is more or less just your last line and - honestly - I haven't tested it with nested, linked directories.
Hm. Do you need that "while" - I guess to follow symlinks?
The while unravels symlinks one at a time, using readlink.
On Ubuntu, you would symlink PlexConnect_daemon.bash from /etc/init.d/plexconnect and that symlink would then be symlinked from the various /etc/rcN.d dir, with a priority prefix:
> find /etc -name *plexconnect* /etc/rc2.d/S20plexconnect /etc/rc3.d/S20plexconnect /etc/rc1.d/K20plexconnect /etc/rc0.d/K20plexconnect /etc/rc4.d/S20plexconnect /etc/rc6.d/K20plexconnect /etc/init.d/plexconnect /etc/rc5.d/S20plexconnect
->http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
Highest rated answer has your proposed code as well.
Thinking of moving the *_daemon stuff into /support/Linux... I guess we can implement those changes on the way. :-)