These instructions cover how you can set up a Python script - such as a ModelHost script - so that it runs as a service.
On Windows, you can use a tool called the Non-Sucking Service Manager or NSSM to create a Windows service that runs a specified application.
This can be found in the drivers\nssm\win64 folder.
To register a script at C:\Scripts\model.py to run as a service, you'd go through the following steps…
1) Open an Administrative command-prompt, 2) Type c:\ardi\drivers\win64\nssm install “Service Name” 3) Under Path, choose C:\Python314\python.exe 4) Under 'Startup Directory', choose the folder where your script is stored, 5) Under Arguments, enter the path to your Python file (remember to add double-quotes if there are spaces in your file name), followed by any optional arguments. 6) Set an appropriate user account to run as, 7) Under I/O, add a file-name for the Output and Error logs (these can point to the same file).
Then click 'Install Service'. You should then be able to see and start the service from the normal Windows 'Services' app.
On Linux servers, you will usually need to create a service file. On Ubuntu and most systems, this will be in the /etc/systemd/system folder.
The file should be named <service-name>.service (for example, a model might be 'datamodel.service'.
It should contain the following, replacing 'service-name' with your service name…
[Unit] Description=Service Description After=multi-user.target [Service] ExecStart=python3 [SCRIPT LOCATION] [ARGUMENTS] StandardOutput=file:/var/log/service-name.log StandardError=file:/var/log/service-name.log Environment=PYTHONUNBUFFERED=1 [Install] WantedBy=multi-user.target
Once you've created your service file, you'll need the following two commands run as root/sudo…
sudo systemctl daemon-reload sudo systemctl enable <service-name>
Your service should now be running. You can check its status using…
sudo service <service-name> status