我希望在Debian 9系统启动时运行一个脚本。我的脚本在单独运行时有效,但在systemd下失败。
我的脚本只是将备份文件从远程服务器复制到本地机器:
我的脚本只是将备份文件从远程服务器复制到本地机器:
#!/bin/sh
set -e
/usr/bin/sshpass -p "PASSWORD" /usr/bin/scp -p USER@10.0.0.2:ORIGINPATH/backupserver.zip DESTINATIONPATH/backupserver/
为保护隐私,上面的密码、用户名和路径已被替换。
我编写了以下systemd服务单元:
[Unit]
Description=backup script
[Service]
Type=oneshot
ExecStart=PATH/backup.sh
[Install]
WantedBy=default.target
然后我为脚本设置权限:
chmod 744 PATH/backup.sh
同时安装该服务:
chmod 664 /etc/systemd/system/backup.service
systemctl daemon-reload
systemctl enable backup.service
当我重启脚本时,它会失败:
● backup.service - backup script
Loaded: loaded (/etc/systemd/system/backup.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2017-05-13 13:39:54 -03; 47min ago
Main PID: 591 (code=exited, status=1/FAILURE)
journalctl -xe的结果如下:
mai 16 23:34:27 rodrigo-acer systemd[1]: backup.service: Main process exited, code=exited, status=6/NOTCONFIGURED
mai 16 23:34:27 rodrigo-acer systemd[1]: Failed to start backup script.
mai 16 23:34:27 rodrigo-acer systemd[1]: backup.service: Unit entered failed state.
mai 16 23:34:27 rodrigo-acer systemd[1]: backup.service: Failed with result 'exit-code'.
可能出了什么问题?
systemctl start backup
使其正常工作。 - Zan Lynx