How To Keep Plex Server Always Running Windows As Service

9 min read Oct 04, 2024
How To Keep Plex Server Always Running Windows As Service

How to Keep Your Plex Server Running 24/7 on Windows: The Service Route

You've built your dream media library with Plex, but the constant worry of it shutting down when your computer sleeps keeps you from fully enjoying your setup. You long for a solution to ensure your Plex server runs seamlessly, even when you're away or your computer is idle. The answer lies in turning your Plex server into a Windows service, ensuring it operates in the background, unfazed by your PC's status. Let's explore how to achieve this.

Why Should You Turn Plex into a Windows Service?

Turning your Plex server into a Windows service offers several compelling advantages:

  • Uninterrupted Streaming: No more interruptions in your movie night or music playlist due to your computer going to sleep or restarting. Your Plex server will run tirelessly, providing continuous access to your media library.
  • Automatic Startup: When your computer boots up, your Plex server will automatically fire up, eliminating the need for manual intervention. This simplifies your life and ensures your server is ready for action.
  • Background Operation: The service runs discreetly in the background, minimizing system impact and allowing you to use your computer for other tasks without interference.

Setting Up Plex as a Windows Service: A Step-by-Step Guide

Here's a detailed breakdown of the process to transform your Plex server into a reliable Windows service:

1. Download the Necessary Tools:

  • Plex Media Server: Ensure you have the latest version of Plex Media Server installed on your Windows computer.
  • NSIS: This powerful installer tool enables us to create a Windows service for Plex. Download the latest version of NSIS from the official website.

2. Create a Batch File:

  • Create a new text file and save it as plex.bat in your Plex Media Server installation directory.
  • Paste the following code into the file:
"%PROGRAMFILES%\Plex\Plex Media Server\Plex Media Server.exe" --no-ui --log-level debug
  • Explanation:
    • "%PROGRAMFILES%\Plex\Plex Media Server\Plex Media Server.exe": This line specifies the path to the Plex Media Server executable.
    • --no-ui: This parameter hides the Plex Media Server interface from your screen.
    • --log-level debug: This parameter ensures that Plex generates detailed log files for troubleshooting purposes.

3. Install NSIS:

  • Run the NSIS installer. Follow the prompts to complete the installation process.

4. Create a Service Configuration File:

  • Create a new text file and save it as plex.nsi in your Plex Media Server installation directory.
  • Add the following code to the file:
!define PRODUCT_NAME "Plex Media Server"
!define PRODUCT_VERSION "1.0.0"
!define PRODUCT_DESCRIPTION "A service for running Plex Media Server"
!define PRODUCT_DIR "$PROGRAMFILES$\Plex\Plex Media Server"
!define PRODUCT_EXE "Plex Media Server.exe"

; Include the NSIS core libraries.
!include "MUI2.nsh"
!include "x64.nsh"

; Define the sections that will be used in the installer.
Section "Install"
    SetOutPath $PRODUCT_DIR
    File "${PRODUCT_DIR}\${PRODUCT_EXE}"
    ; Copy the batch file to the same directory.
    File "${PRODUCT_DIR}\plex.bat"
    ; Install the service.
    WriteUninstaller "uninst.exe"
    ; Create a service entry.
    CreateService "${PRODUCT_NAME}" "" "$PRODUCT_DIR\plex.bat" "" "" "" "NT AUTHORITY\SYSTEM" "" "service"
SectionEnd

; Define the uninstall section.
Section "Uninstall"
    Delete "$PRODUCT_DIR\${PRODUCT_EXE}"
    Delete "$PRODUCT_DIR\plex.bat"
    ; Remove the service.
    DeleteService "${PRODUCT_NAME}"
SectionEnd

; Define the installer UI.
!define MUI_PAGE_WELCOME
!define MUI_PAGE_LICENSE
!define MUI_PAGE_COMPONENTS
!define MUI_PAGE_DIRECTORY
!define MUI_PAGE_INSTFILES
!define MUI_PAGE_FINISH

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
  • Explanation:
    • !define PRODUCT_NAME, !define PRODUCT_VERSION, !define PRODUCT_DESCRIPTION: These lines define basic information about your Plex service.
    • !define PRODUCT_DIR: This line specifies the installation directory for Plex.
    • !define PRODUCT_EXE: This line defines the name of the Plex executable file.
    • SetOutPath $PRODUCT_DIR: This line specifies the output directory for the files to be installed.
    • File "${PRODUCT_DIR}\${PRODUCT_EXE}": This line copies the Plex Media Server executable to the specified directory.
    • File "${PRODUCT_DIR}\plex.bat": This line copies the batch file to the same directory.
    • CreateService "${PRODUCT_NAME}" "" "$PRODUCT_DIR\plex.bat" "" "" "" "NT AUTHORITY\SYSTEM" "" "service": This line creates a new Windows service with the specified name, using the batch file as its executable.

5. Build the Installer:

  • Open the command prompt or PowerShell.
  • Navigate to the directory containing your plex.nsi file using the cd command.
  • Run the following command:
makensis plex.nsi
  • This command will create a new installer file (usually named plex.exe).

6. Install the Plex Service:

  • Run the newly created plex.exe installer.
  • Follow the prompts to install the Plex service.

7. Start the Plex Service:

  • After installation, open the Windows "Services" application (search for "Services" in the Start menu).
  • Locate the "Plex Media Server" service and double-click it.
  • In the service properties window, click "Start" to start the service.

8. Verify Service Status:

  • Ensure the service status is set to "Running."
  • You should now be able to access your Plex server through your web browser or Plex app.

9. Troubleshooting:

  • Firewall Issues: If the service doesn't start, ensure that your firewall rules allow the Plex Media Server executable to access the network.
  • User Permissions: The service may require specific user permissions. In the service properties, check the "Log On" tab and ensure the correct user account and permissions are set.
  • Log Files: Consult the Plex Media Server log files for detailed error messages. They are usually located in the Plex Media Server directory.

Conclusion

By following these steps, you've successfully transformed your Plex server into a reliable Windows service, ensuring uninterrupted streaming and simplifying your server management. Enjoy your media library without the worry of interruptions, knowing your Plex server is always running, ready to deliver your favorite movies, shows, and music whenever you need them.

Featured Posts