2

Could anyone figure out why this systemd unit fails to start?

I have placed the service in /etc/systemd/system/startup_actions.service

[Unit]  
Description=Startup actions

[Service]
Type=oneshot 
ExecStart=/usr/local/bin/disable_pgupdw.sh

[Install]
WantedBy=multi-user.target

To run it I do

sudo systemctl start startup_actions.service 

The unit symply disables the pgup and down keys with xmodmap, and works on its own:

#!/bin/bash
xmodmap -e 'keycode 112 = NoSymbol'
xmodmap -e 'keycode 117 = NoSymbol'

The script is placed in

/usr/local/bin

This is the output of systemctl status startup_actions

startup_actions.service - Startup actions
Loaded: loaded (/etc/systemd/system/startup_actions.service; enabled; vendor preset: enable
Active: failed (Result: exit-code) since Sat 2017-11-04 14:15:18 GMT; 1h 21min ago
Process: 2360 ExecStart=/usr/local/bin/disable_pgupdw.sh (code=exited, status=1/FAILURE)
Main PID: 2360 (code=exited, status=1/FAILURE)

When I try to start it it says:

Job for startup_actions.service failed because the control process exited with error code.
See "systemctl  status startup_actions.service" and "journalctl  -xe" for details.
1
  • Have you done 'systemctl daemon-reload' ? What does it say when you try to start it? What's output of the 'systemctl status startup_actions? Commented Nov 4, 2017 at 15:34

2 Answers 2

1

The following unit works, even though it is not the optimal solution

[Unit]  
Description=Startup actions

[Service]
Type=simple
User=USERNAME
Environment=DISPLAY=:0 
ExecStart=/usr/local/bin/disable_pgupdw.sh

[Install]
WantedBy=multi-user.target

One in fact needs to add a sleep 10 at the beginning of the script, which is not very nice

#!/bin/bash
sleep 10
xmodmap -e 'keycode 112 = NoSymbol'
xmodmap -e 'keycode 117 = NoSymbol'

As pointed out by Ignacio, xmodmap requires access to the X server. The combination

Type=simple
User=USERNAME
Environment=DISPLAY=:0

and

sleep 10

in the script seems to achieve the requirement.

0

The same unit work for me when I put it in ~user/.config/systemd/user/ ( then systemctl --user daemon-reload ) and starting it using systemctl --user start startup_actions.service.
This ways environment variables are properly sets.

You must log in to answer this question.

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