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

前端 未结 6 2043
时光取名叫无心
时光取名叫无心 2020-12-07 21:46

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 follo

相关标签:
6条回答
  • 2020-12-07 22:21

    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.

    0 讨论(0)
  • 2020-12-07 22:24

    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.

    0 讨论(0)
  • 2020-12-07 22:25

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

    #!/bin/bash
    
    python -u alwayson.py    
    
    0 讨论(0)
  • 2020-12-07 22:29

    If that is a copy/paste from your script, you've permuted this line:

    #!/usr/env/bin bash
    

    There's no #!/usr/env/bin, you meant #!/usr/bin/env.

    0 讨论(0)
  • 2020-12-07 22:38

    I ran across a Main process exited, code=exited, status=203/EXEC today as well and my bug was that I forgot to add the executable bit to the file.

    0 讨论(0)
  • 2020-12-07 22:41

    I actually used the answer from How do I run a node.js app as a background service? combined with what dwrz said above. In my case, I was creating a Discord bot that needed to be able to run when I was not around.

    With this service in place, I initially got the same error that the initial poster did, which brought me here. I was missing the #!/usr/bin/env node at the top of my executed node.js script.

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

    0 讨论(0)
提交回复
热议问题