There's a script which has to be run by a systemd service's ExecStartPre. What would be the proper path to put this script into and how to specify it in the unit? Currently using paths such as these fail (the service won't start due to bad unit file):

  • script.sh
  • ./script.sh
  • /etc/systemd/system/script.sh
  • /usr/local/sbin/script.sh

Here's the error I get in the status:

Process: 8679 ExecStartPre=/usr/local/sbin/script.sh (code=exited, status=203/EXEC)

And here's the script:

if [ ! -e /var/log/myservice ];
                echo "myservice's log directory doesn't exist. creating it."
                mkdir /var/log/myservice
  • ExecStartPost or ExecStartPre? Where is the script actually located?
    – muru
    Commented Sep 8, 2020 at 8:12
  • Fixed it now, I'd tested many times so the log was slightly different. The script is in /usr/local/sbin/
    – aderchox
    Commented Sep 8, 2020 at 8:13
  • Is the script actually executable?
    – muru
    Commented Sep 8, 2020 at 8:14
  • Ah silly me thank you muru. Yes chmod +x fixed it.
    – aderchox
    Commented Sep 8, 2020 at 8:16

1 Answer 1


Since you don’t need to change your script, the advice in this answer applies: the script should go in /usr/local/sbin. It also needs to be executable. Your ExecStartPre would be


However you don’t need a script at all to create a directory:

ExecStartPre=mkdir -p /var/log/myservice

Better yet, use LogsDirectory=, which will create the directory if necessary and ensure it’s available inside the sandbox if the service is sandboxed:

  • I thought p was for creating the parents, but I didn't know about -p, --parents no error if existing.... Great! Thanks.
    – aderchox
    Commented Sep 8, 2020 at 8:18
  • The keen eyed can spot the systemd way of doing this at unix.stackexchange.com/q/567317/5132 . (-:
    – JdeBP
    Commented Sep 8, 2020 at 8:45
  • Ah yes, thanks @JdeBP, I thought there was something like that but couldn’t find it. Commented Sep 8, 2020 at 8:56

You must log in to answer this question.

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