How to open GUI from systemd service on startup?
5
votes
1
answer
7917
views
I'm trying to start a VMWare Workstation VM from the command line. I can do this under my user (not
root
) by running the following
/usr/bin/vmplayer /home/myUser/vmware/myVm.vmx
Now, I want to set this VM to start on boot, so I created a service /lib/systemd/system/myService.service
with the following:
[Unit]
Description=my vm service
[Service]
User=myUser
ExecStart=/usr/bin/vmplayer /home/myuser/vmware/myVm.vmx
Environment=DISPLAY=:0
[Install]
WantedBy=multi-user.target
If I run the service from the terminal (i.e. sudo systemctl restart myService
) I can see the VM window popping up and starting correctly. However, if I reboot the system the VM doesn't start and this is the status
I get
Jan 23 12:55:59 home systemd: Started myService service.
Jan 23 12:56:00 home truenas.sh: [AppLoader] Use shipped Linux kernel AIO access library.
Jan 23 12:56:00 home truenas.sh: An up-to-date "libaio" or "libaio1" package from your system is preferred.
Jan 23 12:56:00 home vmplayer: cannot open display: :0
Jan 23 12:56:00 home systemd: myService.service: Main process exited, code=exited, status=1/FAILURE
Jan 23 12:56:00 home systemd: myService.service: Failed with result 'exit-code'.
I thought DISPLAY=:0
on the environment would fix the issue but that's the error I got and I'm not able to fix it.
Asked by Victor
(163 rep)
Jan 23, 2023, 06:11 PM
Last activity: Jan 24, 2023, 03:32 AM
Last activity: Jan 24, 2023, 03:32 AM