<分区>
操作系统: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 测试成功然后完成。但这是最后的手段,我想按规定解决这个问题。