0

I have a GUI program that I can run from a terminal with no issue using:

$ /home/user1/ibg/ibg username=*** password=***

With the above command, the program GUI is displayed, get automatically logged-into my online account, and I can communicate with their server through port 4002 using a python script and successfully request data. No issue.

I would like to create a service for the above command using systemd in ubuntu. The service file I wrote is as follows (placed in /etc/systemd/system):

[Unit]
Description=ibg service
After=network.target

[Service]
Type=simple
Environment=DISPLAY=:0
ExecStart=/home/user1/ibg/ibg username=**** password=****

[Install]
WantedBy=multi-user.target

However, the service cannot be run successfully.

user1@SFO:~$ sudo systemctl status ibg.service
● ibg.service - ibg service
   Loaded: loaded (/etc/systemd/system/ibg.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2020-08-18 22:13:07 PDT; 3s ago
  Process: 27951 ExecStart=/home/user1/ibg/ibg username=**** password=**** (code=exited, status=1/FAILURE)
 Main PID: 27951 (code=exited, status=1/FAILURE)

Aug 18 22:13:07 SFO ibg[27951]:         at java.security.AccessController.doPrivileged(Native Method)
Aug 18 22:13:07 SFO ibg[27951]:         at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
Aug 18 22:13:07 SFO ibg[27951]:         at java.awt.Toolkit.getEventQueue(Toolkit.java:1734)
Aug 18 22:13:07 SFO ibg[27951]:         at java.awt.EventQueue.invokeLater(EventQueue.java:1266)
Aug 18 22:13:07 SFO ibg[27951]:         at com.exe4j.runtime.LauncherEngine.handleFailure(LauncherEngine.java:140)
Aug 18 22:13:07 SFO ibg[27951]:         at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:94)
Aug 18 22:13:07 SFO ibg[27951]:         at com.install4j.runtime.launcher.UnixLauncher.start(UnixLauncher.java:66)
Aug 18 22:13:07 SFO ibg[27951]:         at install4j.ibg.GWClient.main(Unknown Source)
Aug 18 22:13:07 SFO systemd[1]: ibg.service: Main process exited, code=exited, status=1/FAILURE
Aug 18 22:13:07 SFO systemd[1]: ibg.service: Failed with result 'exit-code'.

Could someone help me how I can track down where the issue is? The status command does not provide why the service cannot be run. Is there any way to get more info on the failure? What could be the difference between running the command line version of the GUI with the service I created? I am using the exact same command to run it with ExecStart.

1
  • 2
    Try journalctl -u ibg.service to see the full log
    – Panki
    Commented Aug 19, 2020 at 7:30

1 Answer 1

2

Since it's a graphical application, I suspect this answer may help you:

Setting DISPLAY in systemd service file

You have a few problems with your service file as it's running a graphical application.

If you want to keep it as a system service:

  • It's WantedBy=multi-user.target. I recommend changing to WantedBy=graphical.target and After=graphical.target which should only happen after your display manager starts. However, it may still be a problem as it might try (and fail) to start the application before you log in.
  • It's running as root. You might want to set User= in the service section
  • Add Environment=DISPLAY=:0 and Environment=XAUTHORITY=/home/username/.Xauthority.

It might work better as a user service:

  • move *.service to ~/.config/systemd/user/
  • change WantedBy= to WantedBy=default.target

Once it is a user-service, enable it with systemctl --user enable ibg.service or start it with systemctl --user start ibg.service.

8
  • I modified my unit file based on your answer and did sudo systemctl daemon-reload, and started the service but I get the error Failed to start ibg.service: Unit ibg.service not found.. In addition to this, I also verified the service file and got sudo systemd-analyze verify ibg.service /etc/systemd/system/vncserver2.service:9: Unknown lvalue 'WorkinDirectory' in section 'Service' Attempted to remove disk file system, and we can't allow that. Commented Aug 20, 2020 at 3:22
  • 1
    When you put it in ~/.config/systemd/user/, you need to use systemctl --user to work with it. Editing the answer to be more clear.
    – Stewart
    Commented Aug 20, 2020 at 5:47
  • 1
    systemd doesn't do that natively, but you could always add an ExecStartPost= command to run a script to do it for you. See: stackoverflow.com/a/3800208/1723954
    – Stewart
    Commented Aug 20, 2020 at 6:59
  • 1
    When you use --user, you don't need to use sudo.
    – Stewart
    Commented Aug 21, 2020 at 5:44
  • 1
    Great! That fixed my issue. Thank you for that. It seems like I should use the following commands for user services: systemctl --user daemon-reload and systemctl --user start ibg.service Commented Aug 21, 2020 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .