Install as a daemon

jj-uk edited this page Dec 22, 2017 · 33 revisions

These steps are presented as guidelines. Your results may vary, depending on operating system, installation path and other settings.

Windows

Interactive

This will start PlexPy in the background when you login to Windows without the command prompt.

  • Make sure PlexPy is shutdown. PlexPy > Settings > Shutdown
  • Create a new shortcut (screenshot) in your startup folder with
    • Target: C:\Python27\pythonw.exe C:\PlexPy\PlexPy.py
    • Start in: C:\Python27
  • Start PlexPy with the shortcut

Non Interactive

This will start PlexPy in the background when your computer starts, regardless of whether you are logged in.

  • Make sure PlexPy is shutdown. PlexPy > Settings > Shutdown
  • Create a new text file and enter the following line: Start C:\Python27\pythonw.exe C:\PlexPy\PlexPy.py
  • Save the file in your PlexPy folder as PlexPy.cmd (e.g. C:\PlexPy\PlexPy.cmd)
  • Open the "Run" dialog window (Win+R) and run %windir%\system32\taskschd.msc to open your Windows Task Scheduler.
  • Create a new task with the following settings:
    • General:
      • Name: PlexPy
      • (•) Run whether user is logged on or not
      • Configure for: Windows 10 (select your own Windows version)
    • Triggers:
      • Add a new trigger:
        • Begin the task: At startup
        • [✓] Delay task for: 30 seconds (to allow your server to start up, adjust as necessary)
        • Click OK
    • Actions:
      • Add a new action:
        • Action: Start a program
        • Program/script: C:\PlexPy\PlexPy.cmd
        • Click OK
    • Settings:
      • [✓] Allow task to be run on demand
      • [✓] Run task as soon as possible after a scheduled start is missed
      • [✓] If the task fails, restart every: 1 minute
      • Attempt to restart up to: 3 times
      • [✓] If the running task does not end when requested, force it to stop
      • If the task is already running, then the following rule applies: Do not start a new instance
    • Click OK
  • PlexPy should show up in the list of Active Tasks.
  • Double click on the task, then click "Run" on the right hand side. The status will change the "Running".
  • Once PlexPy has started, the status should change back to "Ready" and the last run result should say "The operation completed successfully (0x0)".
  • In your Windows Task Manager, there should be a "pythonw.exe" background process running.

Linux (systemd)

Use the following service script for CentOS, Fedora, openSUSE, Ubuntu, etc. that uses systemd. The instructions are in the script file.

Ubuntu (<15.10)

This installation assumes PlexPy is installed to /opt/plexpy. Make sure all paths are correct and accessible. A common mistake is that a daemon user has no read and/or write permissions.

For other versions of Ubuntu:

  • Make sure PlexPy is shutdown. PlexPy > Settings > Shutdown
  • cd /opt/plexpy
  • sudo touch /etc/default/plexpy
  • Optional:
    • sudo adduser --system --no-create-home plexpy
    • sudo chown plexpy:nogroup -R /opt/plexpy
  • Adjust settings in /etc/default/plexpy. See the comments in /opt/plexpy/init-scripts/init.ubuntu for the list of parameters.
  • sudo chmod +x /opt/plexpy/init-scripts/init.ubuntu
  • sudo ln -s /opt/plexpy/init-scripts/init.ubuntu /etc/init.d/plexpy
  • sudo update-rc.d plexpy defaults
  • sudo service plexpy [start | stop | reload | restart]

Mac OS X

Tested on Mac OS X 10.11.3. Assumes PlexPy is installed to /Applications/PlexPy/

If you need to specify a version of Python, edit com.JonnyWong16.plexpy.plist

  • Make sure PlexPy is shutdown. PlexPy > Settings > Shutdown
  • cp /Applications/PlexPy/init-scripts/init.osx ~/Library/LaunchAgents/com.JonnyWong16.plexpy.plist
  • To start PlexPy run launchctl load ~/Library/LaunchAgents/com.JonnyWong16.plexpy.plist
  • To stop PlexPy run launchctl unload ~/Library/LaunchAgents/com.JonnyWong16.plexpy.plist

FreeBSD

This assumes PlexPy is installed to /usr/local/share/ as per installation instructions, and user is _sabnzbd. You can make your own user too: sudo adduser

  • Make sure PlexPy is shutdown. PlexPy > Settings > Shutdown
  • Ensure user permissions are correct: sudo chown -R _sabnzbd:_sabnzbd /usr/local/share/plexpy
  • Copy init script: sudo cp /usr/local/share/plexpy/init-scripts/init.freebsd /usr/local/etc/rc.d/plexpy
  • Enable at boot: sudo sysrc plexpy_enable="YES"
  • To start sudo service plexpy start

Optional:

  • If you need to change user: sudo sysrc plexpy_user="USERNAME"
  • Run from another directory: sudo sysrc plexpy_dir="DIRECTORY"

FreeNAS (FreshPorts pkg install)

  • pkg install plexpy
  • pkg update && pkg upgrade
  • pkg install -y plexpy

Auto-start when the jail starts:

  • sysrc plexpy_enable="YES"

Set the user for which plexpy will run as:

  • sysrc plexpy_user="root"

If you're using FreeNAS 11.1, and you're installing into a 'warden' jail (e.g. created with the 'old' FreeNAS GUI), you'll need to install older versions of sqlite3 and py-sqlite3:

  • portsnap fetch

  • portsnap extract

  • cd /usr/ports/databases/sqlite3

  • make deinstall

  • make install clean ALLOW_UNSUPPORTED_SYSTEM=true

  • cd /usr/ports/databases/py-sqlite3

  • make deinstall

  • make install clean ALLOW_UNSUPPORTED_SYSTEM=true

Finally, either restart the jail via the FreeNAS GUI, or start the service manually:

  • service plexpy start

Plexpy is available at:

  • http:// jail ip : 8181

FreeNAS (git clone)

Instructions by Supa on the FreeNAS forums.

This assumes PlexPy is installed to /usr/local/share/ as per installation instructions, and user is root.

To automate the PlexPy script just do this in the jail shell (in root directory):

  • Make sure PlexPy is shutdown. PlexPy > Settings > Shutdown
  • Ensure user permissions are correct: chown -R root:wheel /usr/local/share/plexpy
  • Copy init script: cp /usr/local/share/plexpy/init-scripts/init.freenas /etc/rc.d/plexpy
  • Enable at boot: sysrc plexpy_enable="YES"
  • Set user to run: sysrc plexpy_user="root"
  • To start service plexpy start
    • You can use service plexpy [start | stop | restart | status] to start/stop/restart or check the status of the PlexPy service

Optional:

  • If you need to change user: sysrc plexpy_user="USERNAME"
    • Set user permissions for the plexpy directory: chown -R USERNAME:GROUPNAME /usr/local/share/plexpy
  • Run from another directory: sysrc plexpy_dir="DIRECTORY"