Linux/Ubuntu: Run window program with wine headless on server


Mon Aug 29 2022 16:38:46 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero #bash


#--- xvfb
sudo apt install -y xvfb

#-- add this into /etc/rc.local:

    #!/bin/sh -e
    Xvfb -ac :99 -screen 0 1024x768x16 &
    exit 0

#-- save & first run:
Xvfb -ac :99 -screen 0 1024x768x16 &

#--- wine
sudo dpkg --add-architecture i386

wget -O- -q | sudo apt-key add -
echo "deb ./" | sudo tee /etc/apt/sources.list.d/wine-obs.list

sudo apt update
sudo apt install --install-recommends winehq-stable winetricks

wine --version
wine --help

wineboot -u

winetricks allfonts

#-- install my app at /opt
sudo mkdir -p /opt/report/cache
sudo chmod -R 777 /opt/report
cp ReportService5.exe /opt/report
cd /opt/report

#-- and test it:
DISPLAY=:99 wine ReportService5.exe </dev/null &>/dev/null &

#-- create systemd service:

sudo nano /lib/systemd/system/report-service.service

Description=Reporting service

ExecStart=/usr/bin/wine "/opt/report/ReportService5.exe" </dev/null &>/dev/null &


#-- save.

#-- create

nano /opt/report/

kill $(pgrep ReportService5.exe)
kill -9 $(pgrep winedevice.exe)

#-- save.

sudo chmod +x /opt/report/

#-- start service:
sudo systemctl enable report-service
sudo systemctl start report-service

DISPLAY=:99 import -window root -quality 90 /tmp/screenshot.jpg


I have a windows program (.exe) that serves http api. I needed it to be running on my server (Ubuntu), but I didn't want to install virtualbox, VMWare or any other virtualization engine in my server. So I thought on wine and I got very good result.