Systemd 203 / EXEC error correction (no such file or directory)

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

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

 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 am lost since files and directories exist. The script is executable and, just for verification, I even set permissions for 777.

Some background:

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

backup.timer loaded and active and is 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 finally, this is the paraphrase of backup.sh :

 #!/usr/env/bin bash rsync -a --delete --quiet /home/user/directory/ /mnt/drive/directory-backup/ 

The script works fine if I executed it myself.

Not sure if that matters, but I'm using fish as my shell (launched from .bashrc).

I am happy to publish the full script if this is helpful.

+34
source share
6 answers

I think I found the answer:

In the .service file .service I need to add /bin/bash to the script path.

For example, for backup.service:

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

Unlike:

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

I'm not sure why. Perhaps fish . On the other hand, I have another script for my email, and the service file works fine without /bin/bash . However, it uses default.target instead of multi-user.target .

In most tutorials that I came across, don't add /bin/bash , but then I saw this SO answer that had this and thought 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.

+76
source

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

+6
source

To simplify, be sure to add a hash hit at the top of your ExecStart script, i.e.

 #!/bin/bash python -u alwayson.py 
+2
source

If this is a copy / paste from your script, you rearranged this line:

 #!/usr/env/bin bash 

There is no #!/usr/env/bin , you mean #!/usr/bin/env .

+2
source

I actually used the answer. How to run node.js application as background service? combined with what dwrz said above. In my case, I created the Discord bot, which should have worked when I was not around.

With this service in place, I initially got the same error as the original poster that brought me here. I lost #!/usr/bin/env node at the top of my node.js. executable script

Since then, no problems, although I intend to see what else can be expanded for the service itself.

+1
source

I also came across Main process exited, code=exited, status=203/EXEC today, and my mistake was that I forgot to add the executable bit to the file.

0
source

Source: https://habr.com/ru/post/1271017/


All Articles