gpt4 book ai didi

linux - 系统脚本失败

转载 作者:太空宇宙 更新时间:2023-11-04 10:20:55 25 4
gpt4 key购买 nike

我想在 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'.

有什么问题吗?

最佳答案

解决了伙计们。有两个问题:

1 - 我必须更改服务单元文件以使服务仅在网络启动后运行。单元部分更改为:

 [Unit]
Description = World server backup
Wants = network-online.target
After = network.target network-online.target

2 - root 用户没有将远程主机添加到已知主机列表中,这与我用来测试脚本的普通用户不同。

关于linux - 系统脚本失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43956077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com