Skip to content

Run as a Windows Service with NSSM

Beangate edited this page Feb 28, 2025 · 1 revision

These are user-provided instructions, and I have not validated them. In theory you can just do this as a normal Windows Service, but I know that dealing with Windows Services is not Trivial.

Run as a service NSSM (Windows)

Download NSSM from the official website. NSSM is used to create a windows service to run the script.

Once downloaded, copy nssm.exe to the same directory the script is located in.

Next, open cmd in that directory with administrator privileges.

In cmd, enter the following command:

nssm install AniSync

You can replace AniSync with a name of your choice but remember to replace any instances of AniSync in the following commands with your choice.

Next, enter the following command:

nssm edit AniSync

This will open up a GUI interface. Enter the details as follows:

  • Path: path\to\your\python.exe
  • Startup Directory: path\to\your\EmbyAniSync\directory
  • Arguments: "path\to\EmbyAniSync.py"

Screenshot 2024-08-10 123852

Note:

  • Path to your Startup Directory is the same directory where EmbyAniSync.py is located.
  • Arguments should include the quotation marks ("").

Next click on the details tab and make sure Startup type is set to Automatic.

Screenshot 2024-08-10 132317

Next, click on Edit Service.

Finally, enter the following command in cmd:

nssm restart AniSync

Optional - Create logs

You can create logs for the service. This can be helpful to debug any issues.

First create a directory to save your log files. Ideally you can create this directory in the same directory as your script.

.
└── EmbyAniSync/
    ├── embypython/
    ├── logs/
    ├── EmbyAniSync.py
    └── nssm.exe

Next, open up cmd as administrator in the same directory that EmbyAniSync.py is located.

Enter the following command:

nssm edit AniSync

Now, in the NSSM GUI, click on the I/O tab. You may need to click on the arrow buttons to navigate to it.

  • In Output (stdout) enter the following:

    path\to\the\log\directory\service.log

  • In Error (stderr) enter the following:

    path\to\the\log\directory\service-debug.log

Screenshot 2024-08-10 125554

Next, click on Edit Service.

Finally, enter the following command in cmd:

nssm restart AniSync

Clone this wiki locally