修复systemd服务203/EXEC故障(无此类文件或目录) [英] Fixing a systemd service 203/EXEC failure (no such file or directory)

查看:2623
本文介绍了修复systemd服务203/EXEC故障(无此类文件或目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个简单的systemd计时器来每天午夜运行bash脚本.

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

systemctl --user status backup.service失败并记录以下内容:

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'.

我迷路了,因为文件和目录存在.该脚本是可执行的,为了进行检查,我什至将权限设置为777.

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

一些背景:

backup.timerbackup.service单位文件位于/home/user/.config/systemd/user中.

backup.timer已加载并处于活动状态,当前正在等待午夜.

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

这是它的样子:

[Unit]
Description=Runs backup at 0000

[Timer]
OnCalendar=daily
Unit=backup.service

[Install]
WantedBy=multi-user.target

这里是backup.service:

[Unit]
Description=backup

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

[Install]
WantedBy=multi-user.target

最后,这是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.

不确定是否重要,但是我使用fish作为外壳程序(从.bashrc开始).

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.

推荐答案

我想我找到了答案:

.service文件中,我需要在脚本路径之前添加/bin/bash.

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

例如,对于backup.service:

For example, for backup.service:

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

相对于:

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

我不确定为什么.也许fish.另一方面,我为电子邮件运行了另一个脚本,并且在没有/bin/bash的情况下,服务文件似乎运行良好.不过,它确实使用了default.target而不是multi-user.target.

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.

我遇到的大多数教程都不以/bin/bash开头,但是随后我看到了

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.

服务文件执行脚本,并且计时器在systemctl --user list-timers中列出,因此希望可以使用.

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.

这篇关于修复systemd服务203/EXEC故障(无此类文件或目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆