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?