2

I have a custom systemd service (created using this tutorial to modify my screen resolution to a custom value on startup.

I am having issues with the service failing to start (code=203/EXEC).

To start, I have tried all solutions to the following existing topics with no luck:

Fixing a systemd service 203/EXEC failure (no such file or directory)

Systemd service failing on startup

Unable to run Gunicorn as service in systemd 203/EXEC

My .service file is this:

[Unit]
Description=Set resolution to 1920x1080

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

[Install]
WantedBy=multi-user.target

My script is as follows:

#!/bin/bash
xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
xrandr --addmode Virtual1 "1920x1080_60.00"
xrandr --output Virtual1 --mode "1920x1080_60.00"

journalctl output states that the service "Failed at step EXEC spawning /usr/bin/fixres.sh: Permission denied". However, I have no issue running the script by myself with just bash /usr/bin/fixres.sh.

Other things of note: this is in CentOS7 running in VirtualBox

Can anyone find a mistake that I made, or possibly give me some more troubleshooting options?

Thanks in advance.

Edit:

I did the sensible thing and actually googled my error message from journalctl, yielding this link. After modifying the permissions of my script for execution, I get a new error in journalctl stating that the script can't open the display.

There is currently a comment on the question suggesting exactly this.

If I run xhost, I get the following output:

access control enabled, only authorized clients can connect
SI:localuser:root
SI:localuser:<username>

I'm unfamiliar with this aspect, but it seems like root has access to xhost.

The other option suggested was exporting the display. I am not sure what this would accomplish. I am not trying to access the display from a remote system. Or, is that how linux interprets this?

Update:

So, adding Environment=DISPLAY=:0 to the unit file allows me to start the service from the command line. However, it still fails on boot. I have a feeling that I need to wait for another service to start.

I have tried adding After=gdm.service, but this fails as well. Are there any other services I may need to wait for?

detroitwilly
  • 811
  • 3
  • 16
  • 30
  • `However, I have no issue running the script by myself` - but systemd has trouble running the script. Because it can't access desktop. You need to `export DISPLAY=....` and set `xhost +root` or similar on your xserver to allow access as root. Try running the script as root. – KamilCuk Jan 10 '19 at 00:37
  • Also inspect logs by using `systemctl status` and inspecting `journalctl`. You should find that `xrandr` could not ocnnect to display – KamilCuk Jan 10 '19 at 00:44
  • I've updated my question to include results from your suggestions, as well as an additional question. – detroitwilly Jan 10 '19 at 02:49
  • chmod a+x /usr/bin/fixres.sh https://unix.stackexchange.com/questions/203371/run-script-sh-vs-bash-script-sh-permission-denied – Zang MingJie Jan 10 '19 at 02:56
  • `it still fails on boot` - `After=gdm.service` will be ok, but probably initilialization race will be the issue. Well, I would just dirty add `ExecStartPre=/usr/bin/sleep 5`. Do you have a single user on your PC? The `systemctl --user` everything, should run after the user logs in into graphical interface, so the graphical interface is already existing. Actually the proper way of achieving what you want, would be to edit `~/.xinitrc` or /etc/X11/xinitrc or just add a script to autostart to gnome. Using systemd for running service to change desktop resolution - it's not the tool for that. – KamilCuk Jan 10 '19 at 06:23
  • Based on Kamil Cuk's and jww's comments, I will close this question here. Thanks to Kamil for clueing me in on the gnome autostart script method. This is what I'm using now ([for reference](https://stackoverflow.com/questions/8247706/start-script-when-gnome-starts-up)). I am still seeing some issues there, but I will ask the question over on Stack Exchange. – detroitwilly Jan 10 '19 at 18:35

0 Answers0