【发布时间】:2015-09-30 18:51:27
【问题描述】:
操作系统:Debian Jessie
我想在每次系统启动时更新用户文件夹中的 git 存储库。
我用 cron @reboot 条目试过这个。 Cron 启动得太早,结果给我发了邮件“SSH:无法解析主机名...”
然后我尝试了 SysV 初始化脚本。效果 - 一样。
目前我正在尝试具有相同错误报告的 systemd 服务。
/usr/bin/git_repo
#! /bin/sh
# Description: Updates local git repository with latest content
#cd /home/tanglor/repo
su -c'cd repo;git pull' - tanglor
/etc/systemd/system/repo.service
[Unit]
Description = Updates local git repository with latest content
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/repo
[Install]
WantedBy=multi-user.target
还是没有结果。我的意思是在系统日志中我发现:
Sep 30 19:41:59 Khlavan repo[422]: ssh: Could not resolve hostname bitbucket.org: Name or service not known
Sep 30 19:41:59 Khlavan repo[422]: fatal: Could not read from remote repository.
Sep 30 19:41:59 Khlavan repo[422]: Please make sure you have the correct access rights
Sep 30 19:41:59 Khlavan repo[422]: and the repository exists.
Sep 30 19:41:59 Khlavan systemd[1]: repo.service: main process exited, code=exited, status=1/FAILURE
Sep 30 19:41:59 Khlavan systemd[1]: Failed to start Updates local git repository with latest content.
Sep 30 19:41:59 Khlavan systemd[1]: Unit repo.service entered failed state.
如何实现每次系统启动时的仓库更新?
一种解决方案是使用带有 sleep 命令的脚本,它会等到一些 ssh 测试成功然后完成。但这是不得已而为之,我想按部就班地解决这个问题。
【问题讨论】:
-
这太疯狂了。如果您不经常重启怎么办?
-
One solution is to use script with sleep command which will wait till some ssh test will succeed and then complete.这是迄今为止我找到的唯一可靠的解决方案。 Systemd 很奇怪。