On Arch Linux, I am trying to create a systemd service which runs this Bash script:
#!/bin/bash
/bin/xbindkeys &
/bin/setxkbmap -layout gb
With some online guidance I then made a file named myfirst.service
in /etc/systemd/system
to store my service. Here are the contents of the file:
[Unit]
Description=Command Service
[Service]
ExecStart=/etc/startupjobscript
User=user1
Type=oneshot
Restart=on-abort
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
The service is supposed to execute /etc/startupjobscript
, which is the Bash script. After this I enabled and started the service with:
systemctl enable myfirst
systemctl start myfirst
But for some reason it doesn't work and shows that it has failed to load and run at all.
EDIT: here is what sudo systemctl status myfirst give me:
Warning: The unit file, source configuration file or drop-ins of myfirst.service changed on disk. Run 'systemctl daemon-reload' to reload units.
● myfirst.service - Command Service
Loaded: loaded (/etc/systemd/system/myfirst.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2020-08-26 21:07:02 BST; 18min ago
Process: 332 ExecStart=/etc/startupjobscript (code=exited, status=255/EXCEPTION)
Main PID: 332 (code=exited, status=255/EXCEPTION)
Aug 26 21:07:01 archlinux systemd[1]: Starting Command Service...
Aug 26 21:07:02 archlinux startupjobscript[337]: Cannot open display "default display"
Aug 26 21:07:02 archlinux systemd[1]: myfirst.service: Main process exited, code=exited, status=255/EXCEPTION
Aug 26 21:07:02 archlinux systemd[1]: myfirst.service: Failed with result 'exit-code'.
Aug 26 21:07:02 archlinux systemd[1]: Failed to start Command Service.
systemctl daemon-reload
?/etc/
. Normally, things in/etc
are configuration files with permission 644. Check if your script has execute permissions (755) -- plus I recommend sticking it in/usr/local/bin
or/usr/local/sbin
. If it's not execute permissions, what is the output ofsystemctl status myfirst
?WantedBy=graphical.target
instead ofmulti-user.target
to ensure the X server is started before you try interfacing with it. I don't think this is the problem, butsystemctl status
output should tell us.DISPLAY
to act upon; it's a variable set in the environment of the user(s) who are running an X instance, it's not available to a system systemd unit. 2) X utilities will likely fail until the graphical environment is up and running for the user that runs them, which will most likely only happen at a later moment thanmulti-user.target
orgraphical.target
or the user'sdefault.target
. You may want to detail what you're trying to achieve, users here may suggest better approaches.