Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

systemd

I'm trying to set up a simple systemd timer to run a bash script every day at midnight.

systemctl --user status backup.service fails and logs the following:

backup.service: Failed at step EXEC spawning /home/user/.scripts/backup.sh: No such file or directory.

backup.service: Main process exited, code=exited, status=203/EXEC
Failed to start backup.
backup.service: Unit entered failed state.
backup.service: Failed with result 'exit-code'.

I'm lost, since the files and directories exist. The script is executable and, just to check, I've even set permissions to 777.

Some background:

The backup.timer and backup.service unit files are located in /home/user/.config/systemd/user.

backup.timer is loaded and active, and currently waiting for midnight.

Here's what it looks like:

[Unit]
Description=Runs backup at 0000

[Timer]
OnCalendar=daily
Unit=backup.service

[Install]
WantedBy=multi-user.target

Here's backup.service:

[Unit]
Description=backup

[Service]
Type=oneshot
ExecStart=/home/user/.scripts/backup.sh

[Install]
WantedBy=multi-user.target

And lastly, this is a paraphrase of backup.sh:

#!/usr/env/bin bash

rsync -a --delete --quiet /home/user/directory/ /mnt/drive/directory-backup/

The script runs fine if I execute it myself.

Not sure if it matters, but I use fish as my shell (started from .bashrc).

I'm happy to post the full script if that's helpful.

like image 991
dwrz Avatar asked Aug 19 '17 20:08

dwrz


People also ask

What is exited status 203 exec?

Code 203 from systemd simply means "unable to start the process". Maybe it doesn't exist at the path you gave, or maybe permissions are set wrongly.

What is ExecStart in Linux?

ExecStart. The commands and arguments executed when the service starts. ExecStartPre, ExecStartPost. Additional commands that are executed before or after the command in ExecStart . ExecReload.


3 Answers

I think I found the answer:

In the .service file, I needed to add /bin/bash before the path to the script.

For example, for backup.service:

ExecStart=/bin/bash /home/user/.scripts/backup.sh

As opposed to:

ExecStart=/home/user/.scripts/backup.sh

I'm not sure why. Perhaps fish. On the other hand, I have another script running for my email, and the service file seems to run fine without /bin/bash. It does use default.target instead multi-user.target, though.

Most of the tutorials I came across don't prepend /bin/bash, but I then saw this SO answer which had it, and figured it was worth a try.

The service file executes the script, and the timer is listed in systemctl --user list-timers, so hopefully this will work.

Update: I can confirm that everything is working now.

like image 61
dwrz Avatar answered Oct 09 '22 22:10

dwrz


To simplify, make sure to add a hash bang to the top of your ExecStart script, i.e.

#!/bin/bash

python -u alwayson.py    
like image 16
crizCraig Avatar answered Oct 09 '22 23:10

crizCraig


When this happened to me it was because my script had DOS line endings, which always messes up the shebang line at the top of the script. I changed it to Unix line endings and it worked.

like image 10
ke4ukz Avatar answered Oct 09 '22 23:10

ke4ukz