Orthanc as a service stops when a python script is provided

I’m trying to run the dummy python script reported here but the orthanc server doesn’t start correctly when executed as a service on windows and terminates unexpectedly (I get Event ID 7034 in the windows event viewer), while everything works well when launched manually from the command line. Here the logs file obtained when started as a service:

W1220 16:13:01.014953 main.cpp:1956] Orthanc version: 1.9.7
W1220 16:13:01.014953 OrthancConfiguration.cpp:117] Scanning folder “Configuration” for configuration files
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\dicomweb.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\indexer.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\mysql.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\odbc.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\orthanc.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\postgresql.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\serve-folders.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\stone-webviewer.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\tcia.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\transfers.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\webviewer.json”
W1220 16:13:01.014953 OrthancConfiguration.cpp:66] Reading the configuration from: “Configuration\worklists.json”
W1220 16:13:01.215225 main.cpp:878] Loading plugin(s) from: C:\Program Files\Orthanc Server\Plugins
W1220 16:13:01.215225 PluginsManager.cpp:269] Registering plugin ‘connectivity-checks’ (version 1.9.7)
W1220 16:13:01.215225 PluginsManager.cpp:269] Registering plugin ‘stone-webviewer’ (version 2.2)
W1220 16:13:01.215225 PluginsManager.cpp:269] Registering plugin ‘worklists’ (version 1.9.7)
W1220 16:13:01.215225 PluginsManager.cpp:168] Sample worklist plugin is initializing
W1220 16:13:01.215225 PluginsManager.cpp:168] Worklist server is disabled by the configuration file
W1220 16:13:01.215225 PluginsManager.cpp:269] Registering plugin ‘authorization’ (version 0.2.4)
W1220 16:13:01.215225 PluginsManager.cpp:168] Initializing the authorization plugin
W1220 16:13:01.215225 PluginsManager.cpp:168] No section “Authorization” in the configuration file, the authorization plugin is disabled
W1220 16:13:01.215225 PluginsManager.cpp:269] Registering plugin ‘dicom-web’ (version 1.7)
W1220 16:13:01.215225 PluginsManager.cpp:168] URI to the DICOMweb REST API: /dicom-web/
W1220 16:13:01.215225 PluginsManager.cpp:168] URI to the WADO-URI API: /wado
W1220 16:13:01.230850 PluginsManager.cpp:269] Registering plugin ‘gdcm’ (version 1.4)
W1220 16:13:01.230850 PluginsManager.cpp:168] Version of GDCM: 3.0.8
W1220 16:13:01.230850 PluginsManager.cpp:168] GDCM throttling is disabled
W1220 16:13:01.230850 PluginsManager.cpp:269] Registering plugin ‘indexer’ (version 1.0)
W1220 16:13:01.230850 PluginsManager.cpp:168] OrthancIndexer is disabled
W1220 16:13:01.230850 PluginsManager.cpp:269] Registering plugin ‘mysql-index’ (version 4.3)
W1220 16:13:01.230850 PluginsManager.cpp:168] The MySQL index is currently disabled, set “EnableIndex” to “true” in the “MySQL” section of the configuration file of Orthanc
W1220 16:13:01.230850 PluginsManager.cpp:269] Registering plugin ‘mysql-storage’ (version 4.3)
W1220 16:13:01.230850 PluginsManager.cpp:168] The MySQL storage area is currently disabled, set “EnableStorage” to “true” in the “MySQL” section of the configuration file of Orthanc
W1220 16:13:01.230850 PluginsManager.cpp:269] Registering plugin ‘odbc-index’ (version 1.0)
W1220 16:13:01.230850 PluginsManager.cpp:168] The ODBC index is currently disabled, set “EnableIndex” to “true” in the “Odbc” section of the configuration file of Orthanc
W1220 16:13:01.230850 PluginsManager.cpp:269] Registering plugin ‘odbc-storage’ (version 1.0)
W1220 16:13:01.230850 PluginsManager.cpp:168] The ODBC storage area is currently disabled, set “EnableStorage” to “true” in the “Odbc” section of the configuration file of Orthanc
W1220 16:13:01.246473 PluginsManager.cpp:269] Registering plugin ‘postgresql-index’ (version 4.0)
W1220 16:13:01.246473 PluginsManager.cpp:168] The PostgreSQL index is currently disabled, set “EnableIndex” to “true” in the “PostgreSQL” section of the configuration file of Orthanc
W1220 16:13:01.246473 PluginsManager.cpp:269] Registering plugin ‘postgresql-storage’ (version 4.0)
W1220 16:13:01.246473 PluginsManager.cpp:168] The PostgreSQL storage area is currently disabled, set “EnableStorage” to “true” in the “PostgreSQL” section of the configuration file of Orthanc
W1220 16:13:01.246473 PluginsManager.cpp:269] Registering plugin ‘python’ (version 3.4)
W1220 16:13:01.246473 PluginsManager.cpp:168] Python plugin is initializing
W1220 16:13:01.246473 PluginsManager.cpp:168] Using Python script “rest.py” from directory: C:\Program Files\Orthanc Server
W1220 16:13:01.246473 PluginsManager.cpp:168] Program name: C:\Program Files\Orthanc Server\Orthanc.exe

It seems like the service gets stuck after loading the script (I don’t know how to get a more verbose log when orthanc is launched as a service).

I want to specify that the service runs correctly also when no python script is provided in the PythonScripts option in the configuration file, so the python plugin is loaded correctly.

Thank you.

Hi Elia,

It’s likely at this time only that Orthanc tries to load the Python DLLs. I would double check your Environment Variables and make sure that Python has been added in the Path at System Level, not User Level.

When you start Orthanc manually, it uses Path from User Level while, when it starts as a service, it uses System Level env var. That would explain the difference.

HTH

Alain.

Hi Alain,

thank you very much for your reply. I already checked that, and the python path is correctly added in the Path of both the system and user environment variables. When the python path was not in the system path variable I get this error here, i.e. the python plugin is not even loaded, while in this case I can load the python plugin correctly and all runs well as a service if no python script is specified in the PythonScripts configuration variable, but when I specify a script (even very simple like a single print), the plugin is correctly loaded but all the service terminates unexpectedly when reading the script. I have python 3.8.10 and using the orthanc dll 3.4 of the corresponding python version. I hope I made the problem clearer.

Thank you,
Elia

Hi Elia,

I have basically the same setup as yours.

I would recommend you to use Process Monitor: https://docs.microsoft.com/en-us/sysinternals/downloads/procmon, add a filter for Orthanc.exe:
image.png

Then, restart your service, check the time of failure in the logs and check the Process Monitor logs around the same timestamp. Hopefully, you should get useful info from there.

HTH,

Alain.

Thank you again for your reply. I checked the process through Process Monitor and I found these differences between the system started as a service when a python script is specified, and the same process started via cli. I outlined in red the parts where the two processes start to be different, until this point it seems that they make the same calls. I don’t know what is going wrong here, if you (or someone else) have some spare time to help, I leave in the attachments the full log file of Process Monitor for both the call via cli and via service.

cli.PNG

Figure 1: Process monitor of Orthanc started via cli (working correctly).

service.PNG

Figure 2: Process monitor of Orthanc started as a service (not working).

Thank you,
Elia

Logfile-cli-ok.PML
Logfile-service-notworking.PML

image.png

From this point, there is a difference. At this time, Python is looking for its libraries/modules at the wrong place when it is running as a service.

I see that python is installed in your user folder. I would highly recommend reinstalling python for “all users”

image.png

HTH,

Alain

image.png

service.PNG

cli.PNG

Thank you very very much for your kind support, the problem was exactly that!

Have a nice day,
Elia