Can't run wine using crontab?

Questions about Wine on Linux
Locked
htorbov
Level 2
Level 2
Posts: 21
Joined: Wed Feb 01, 2012 11:33 am

Can't run wine using crontab?

Post by htorbov »

My crontab:

Code: Select all

* * * * * ~/d2gs.sh
My application:

Code: Select all

#!/bin/sh

#
# D2GS
#

# Go to the directory
cd ~

# Run the applications
if ! ps aux | pgrep "D2GS"; then
    wine "C:/D2GS/D2GS.exe" > /dev/null 2>&1 &
fi
The problem:
The crontab is not starting the process. Which is weird, since I can start it with ~/d2gs.sh manually - successfully.
jkfloris
Level 12
Level 12
Posts: 3141
Joined: Thu Aug 14, 2014 10:10 am

Re: Can't run wine using crontab?

Post by jkfloris »

Probably the ~ isn't recognized.
Try to use the full path

Code: Select all

cd /home/user/.wine/drive_c/D2GS
wine D2GS.exe
htorbov
Level 2
Level 2
Posts: 21
Joined: Wed Feb 01, 2012 11:33 am

Re: Can't run wine using crontab?

Post by htorbov »

With the full path or not, it still doesn't start. I've saw somewhere, that I need to specify `export DISPLAY=:0`, but I don't have X-server on my server.
User avatar
Bob Wya
Level 12
Level 12
Posts: 3068
Joined: Sat Oct 16, 2010 7:40 pm

Re: Can't run wine using crontab?

Post by Bob Wya »

Code: Select all

if ! ps aux | pgrep "D2GS"; then
This is completely wrong ... But haven't we already had this discussion? :roll:

As has been stated previously - if you want a persistent Wine service (without X) - you are much better off using a systemd User service unit.
Or the equivalent for other init systems.

Cron is for running jobs at specified times and that's it folks... So it's not very efficient as a keep alive job scheduler...

Bob
torbov
Newbie
Newbie
Posts: 1
Joined: Sun Dec 03, 2017 9:58 am

Re: Can't run wine using crontab?

Post by torbov »

Thanks for the reply. Well, I install the .exe as a service - it works fine. But when I restart the server, it doesn't start again :-( I've looked the `systemd` documentation, but I couldn't do it to auto-start the process...
User avatar
Bob Wya
Level 12
Level 12
Posts: 3068
Joined: Sat Oct 16, 2010 7:40 pm

Re: Can't run wine using crontab?

Post by Bob Wya »

torbov wrote:Thanks for the reply. Well, I install the .exe as a service - it works fine. But when I restart the server, it doesn't start again :-( I've looked the `systemd` documentation, but I couldn't do it to auto-start the process...
Oh but it can... :lol: 8)

I would seriously suggest to sit down and get familiar with systemd... systemd units are very powerful.
I've been using systemd on Gentoo well before it was even "officially" supported...

I've got NFS systemd network automount/mount units for my NAS server that get torn down when the network connects and reconnects them when it is back up (e.g. suspend-resume cycle). Same with my SSHFS network mount. This connects over Internet back to my NAS at home. If my DynDNS resolution fails - then a fallback systemd mount unit is run to connect to my NAS over my LAN (by hostname).

Similarly I've a systemd autossh service unit that creates a set of SSH tunnels to my NAS - so I can access various web frontends for servers remotely. These are torn down and recreated each time the network is stopped / restarted.

I know a lot of people that hate on systemd - but personally I find it pretty useful.

I did some tests on my Gentoo system... Note: systemd unit paths vary between Linux distributions...

ROOT USER

Anyway for your particular case... You'd want to create a systemd user unit similar to:

Code: Select all

/etc/systemd/user/d2gs.service

Code: Select all

[Unit]
Description=Persisent Diablo II Game Server
BindsTo=network.target
After=network.target

[Service]
# Set your WINEPREFIX here...
Environment="WINEPREFIX= ... "
# Set the full Windows path to your D2GS.EXE executable here...
Environment="D2GS_EXECUTABLE=C:\\d2gs.exe"
ExecStart=/usr/bin/wine ${D2GS_EXECUTABLE}
Restart=always
RestartSec=2s

[Install]
WantedBy=default.target
To stop systemd complaining it can't find the network.target - which is not accessible by default to systemd user units:

Code: Select all

ln -s /lib/systemd/system/network.target /etc/systemd/user/

LINUX (WINE) USER

Code: Select all

# Reload all systemd unit files
systemctl --user daemon-reload

# Start d2gs.service to test
systemctl start --user d2gs.service

# Enable d2gs.service to start at every boot
systemctl enable --user d2gs.service

# Follow d2gs.service unit status in real time
journalctl --user --unit d2gs.service --follow
Took a bit of fiddling to get the service unit to run here. Check it runs OK with your full Diablo 2 Game Server setup - I didn't test this.
The RestartSec=2s is necessary as systemd has a throttle for service unit restarts (≤5 burst / 10 seconds is the default here).

Post your journalctl log if you hit some issues...

Bob
Locked