title: systemd service failing (203/EXEC)
body: <p>I have a custom systemd service (created using <a href="https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd">this tutorial</a> to modify my screen resolution to a custom value on startup.</p>
  
  <p>I am having issues with the service failing to start (code=203/EXEC).</p>
  
  <p>To start, I have tried all solutions to the following existing topics with no luck:</p>
  
  <p><a href="https://stackoverflow.com/questions/45776003/fixing-a-systemd-service-203-exec-failure-no-such-file-or-directory">Fixing a systemd service 203/EXEC failure (no such file or directory)</a></p>
  
  <p><a href="https://stackoverflow.com/questions/38256227/systemd-service-failing-on-startup">Systemd service failing on startup</a></p>
  
  <p><a href="https://stackoverflow.com/questions/51117100/unable-to-run-gunicorn-as-service-in-systemd-203-exec">Unable to run Gunicorn as service in systemd 203/EXEC</a></p>
  
  <p>My .service file is this:</p>
  
  <pre><code>[Unit]
  Description=Set resolution to 1920x1080
  
  [Service]
  Type=oneshot
  ExecStart=/usr/bin/fixres.sh
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>My script is as follows:</p>
  
  <pre><code>#!/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"
  </code></pre>
  
  <p>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 <code>bash /usr/bin/fixres.sh</code>.</p>
  
  <p>Other things of note: this is in CentOS7 running in VirtualBox</p>
  
  <p>Can anyone find a mistake that I made, or possibly give me some more troubleshooting options?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit:</p>
  
  <p>I did the sensible thing and actually googled my error message from journalctl, yielding <a href="https://unix.stackexchange.com/questions/209097/systemd-failed-at-step-exec-spawning-script-permission-denied">this link</a>.  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.</p>
  
  <p>There is currently a comment on the question suggesting exactly this.</p>
  
  <p>If I run <code>xhost</code>, I get the following output:</p>
  
  <pre><code>access control enabled, only authorized clients can connect
  SI:localuser:root
  SI:localuser:&lt;username&gt;
  </code></pre>
  
  <p>I'm unfamiliar with this aspect, but it seems like root has access to xhost.</p>
  
  <p>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?</p>
  
  <p>Update:</p>
  
  <p>So, adding <code>Environment=DISPLAY=:0</code> 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.</p>
  
  <p>I have tried adding <code>After=gdm.service</code>, but this fails as well.  Are there any other services I may need to wait for?</p>