Linux
systemctl 無法訪問服務文件,權限被拒絕
在 Fedora 35 上,我創建了自己的服務來安排備份。我在 /usr/local/bin/ 中有腳本,在 /lib/systemd/system/ 中有服務文件和計時器
ls -an /usr/local/bin/ 列印
-rwxr--r--. 1 0 0 3360 Dec 1 18:31 backup.sh
ls -an /lib/systemd/system/schedule-backup_root*
-rw-r--r--. 1 0 0 230 Dec 1 18:14 /lib/systemd/system/schedule-backup_root.service -rw-r--r--. 1 0 0 388 Dec 1 16:49 /lib/systemd/system/schedule-backup_root.timer
但是當我啟動服務 systemctl start schedule-backup_root.service
Dec 01 18:36:13 fallen-robot systemd[1]: Started Nightly snapshot backup job for ROOT volume. Dec 01 18:36:13 fallen-robot systemd[75159]: schedule-backup_root.service: Failed to locate executable /usr/local/bin/backup.sh: Permission denied Dec 01 18:36:13 fallen-robot systemd[75159]: schedule-backup_root.service: Failed at step EXEC spawning /usr/local/bin/backup.sh: Permission denied Dec 01 18:36:13 fallen-robot systemd[1]: schedule-backup_root.service: Main process exited, code=exited, status=203/EXEC Dec 01 18:36:13 fallen-robot systemd[1]: schedule-backup_root.service: Failed with result 'exit-code'.
我的服務文件如下所示:
[Unit] Description=Nightly snapshot backup job for ROOT volume [Service] Type=simple ExecStart=/usr/local/bin/backup.sh -s / -b /run/media/borko/BackupTest/ -t "Fallen Robot ROOT Backup Report" [Install] WantedBy=default.target
為什麼它無法訪問該文件?
禁用 SElinux 或將其設置為 permissive。
setenforce 0
這將暫時禁用它。禁用後再次測試,看看是否能解決問題。