How to best run wine program as systemd service? Type=forking? PID of start.exe or wineserver?
How to best run wine program as systemd service? Type=forking? PID of start.exe or wineserver?
I have a piece of text mode Windows program that listens on TCP port 25. In Windows the program would normally run as a Windows Service without console output.
My Arch Linux kernel 6.2.9 with wine-8.5 has no X installed, it's text mode.
The program is tested to run from a user login. Now the program should run automatically, as the same user, without user login. My idea is to run the program on Linux as daemon via a systemd service. So service management can be done from the Linux command prompt, like other running daemons.
Running as a specific user is possible with systemd: [Service] section must in include a "User=" line, or use systemd --user session.
Systemd service type
Choosing a systemd service type is more challenging. I think service type should be Type=forking. Though that requires a PID file to be generated. A 2001 wineserver pid file patch didn't make it into wine. No PID file is generated when running wine or wineconsole.
Type=forking PIDFile=?
The lack of PID file generation might be worked around with a pidof command.
Is it then better to use the PID of start.exe or the PID of /usr/bin/wineserver?
PS Tips and tricks how to run a Windows executable as Linux daemon are welcome.
My Arch Linux kernel 6.2.9 with wine-8.5 has no X installed, it's text mode.
The program is tested to run from a user login. Now the program should run automatically, as the same user, without user login. My idea is to run the program on Linux as daemon via a systemd service. So service management can be done from the Linux command prompt, like other running daemons.
Running as a specific user is possible with systemd: [Service] section must in include a "User=" line, or use systemd --user session.
Systemd service type
Choosing a systemd service type is more challenging. I think service type should be Type=forking. Though that requires a PID file to be generated. A 2001 wineserver pid file patch didn't make it into wine. No PID file is generated when running wine or wineconsole.
Type=forking PIDFile=?
The lack of PID file generation might be worked around with a pidof command.
Is it then better to use the PID of start.exe or the PID of /usr/bin/wineserver?
PS Tips and tricks how to run a Windows executable as Linux daemon are welcome.
Re: How to best run wine program as systemd service? Type=forking? PID of start.exe or wineserver?
An example for the Diablo Game Server can be found here:PS Tips and tricks how to run a Windows executable as Linux daemon are welcome.
viewtopic.php?p=113281#p113281
This example is much simpler, but does have a handy ExecStop in it:
https://github.com/Fuseteam/systemd-ser ... al.service
Re: How to best run wine program as systemd service? Type=forking? PID of start.exe or wineserver?
Another complex Wine systemd service file example is at https://github.com/7thCore/isrsrv-scrip ... 40.service
Most complex up till now is how to get the WINEDLLOVERRIDES Environment var set correctly in the systemd .service unit file.
No good is:
Also tried without improvement:
Most complex up till now is how to get the WINEDLLOVERRIDES Environment var set correctly in the systemd .service unit file.
No good is:
Code: Select all
[Service]
Environment="WINEDLLOVERRIDES=explorer.exe,services.exe=d"
ExecStart=/usr/sbin/wineconsole "/home/wineuser/mbserver.exe"
Code: Select all
[Service]
ExecStart=/usr/bin/bash -c 'env WINEDLLOVERRIDES="explorer.exe,services.exe=d" /usr/sbin/wineconsole "/home/wineuser/mbserver.exe"'
Last edited by cj000 on Fri Apr 14, 2023 11:22 am, edited 2 times in total.
-
- Level 5
- Posts: 368
- Joined: Tue Dec 24, 2019 3:23 pm
Re: How to best run wine program as systemd service? Type=forking? PID of start.exe or wineserver?
Thanks invisible_kid.
It's all my bad (manually comparing systemctl status output with the wrong output lines), actually my first try:
runs ok, and outputs this as status:
It's all my bad (manually comparing systemctl status output with the wrong output lines), actually my first try:
Code: Select all
[Service]
Environment="WINEDLLOVERRIDES=explorer.exe,services.exe=d"
ExecStart=/usr/sbin/wineconsole "/home/wineuser/mbserver.exe"
Code: Select all
systemd[1]: Started Xwall spam filter.
wineconsole[822]: 002c:err:wineboot:start_services_process Couldn't start services.exe: error 126
wineconsole[824]: 0034:err:win:get_desktop_window failed to start explorer c0000135
wineconsole[834]: 0034:err:win:get_desktop_window failed to start explorer c0000135
wineconsole[834]: 005c:err:winediag:nodrv_CreateWindow Application tried to create a window, but no driver could be loaded.
wineconsole[834]: 005c:err:winediag:nodrv_CreateWindow L"The explorer process failed to start."
Re: How to best run wine program as systemd service? Type=forking? PID of start.exe or wineserver?
Instead of using WINEDLLOVERRIDES, you can disable the programs in the registry.
Code: Select all
wine reg add "HKCU\Software\Wine\DllOverrides" /v explorer.exe
Re: How to best run wine program as systemd service? Type=forking? PID of start.exe or wineserver?
For now I will switch from "wineconsole" to "wine" to start mbserver.exe. The results in more output at systemctl status output:
And I will not use ExecStop=wineserver -k.
Without the ExecStop and having Killmode=control-group (=default value), systemctl status output is without errors after a systemctl stop xwall.service:
Instead of:
Code: Select all
wine[1106]: XWall v3.59 (Win10x64 WINE)
wine[1106]: (c) copyright DataEnter GmbH 1991-2023
Without the ExecStop and having Killmode=control-group (=default value), systemctl status output is without errors after a systemctl stop xwall.service:
Code: Select all
Active: inactive (dead) since Fri 2023-04-14 20:35:30 CEST; 3s ago
Duration: 34.514s
Process: 1094 ExecStart=/usr/sbin/wine /home/user/mbserver.exe (code=killed, signal=TERM)
Main PID: 1094 (code=killed, signal=TERM)
CPU: 16.444s
Code: Select all
Active: failed (Result: exit-code) since Fri 2023-04-14 20:33:33 CEST; 3s ago
Duration: 55.865s
Process: 1046 ExecStart=/usr/sbin/wine /home/user/mbserver.exe (code=exited, status=1/FAILURE)
Process: 1071 ExecStop=/usr/sbin/wineserver -k (code=exited, status=0/SUCCESS)
Main PID: 1046 (code=exited, status=1/FAILURE)
CPU: 16.824s
Apr 14 20:32:38 host.domain.tld wine[1052]: 0034:err:win:get_desktop_window failed to start explorer c0000135
Apr 14 20:32:39 host.domain.tld wine[1058]:
Apr 14 20:32:39 host.domain.tld wine[1058]: XWall v3.59 (Win10x64 WINE)
Apr 14 20:32:39 host.domain.tld wine[1058]: (c) copyright DataEnter GmbH 1991-2023
Apr 14 20:32:39 host.domain.tld wine[1058]:
Apr 14 20:33:33 host.domain.tld systemd[1]: Stopping Xwall spam filter...
Apr 14 20:33:33 host.domain.tld systemd[1]: xwall.service: Main process exited, code=exited, status=1/FAILURE
Apr 14 20:33:33 host.domain.tld systemd[1]: xwall.service: Failed with result 'exit-code'.