2015-09-30 57 views
2

操作系統:Debian JessieDebian systemd服務在網絡準備就緒之前啓動

我想在每次系統啓動時更新用戶文件夾中的git存儲庫。

我試着用cron @reboot入口。克朗開始過早,並在結果郵寄給我「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. 

如何在每個系統啓動時實現存儲庫更新?

一個解決方案是使用帶有睡眠命令的腳本,它將等待一些ssh測試成功並完成。但這是最後的手段,我想通過這本書解決。

+0

這太瘋狂了。如果你不經常重新啓動會怎樣? – tripleee

+0

'一個解決方案是使用帶有sleep命令的腳本,它將等待一些ssh測試成功並完成。 「這是迄今爲止我發現的唯一可靠解決方案。 Systemd很奇怪。 – Mahn

回答

4

您應該查看最適合您的解決方案的systemd文檔,但這裏有幾條鏈接可能對您有所幫助。

許多網絡管理解決方案提供了一種在network-online.target無條件地拉,從而提升network.target到效果的影響network-online.target。

如果您使用NetworkManager可以通過啓用NetworkManager的-等待online.service做到這一點:

systemctl enable NetworkManager-wait-online.service

如果使用systemd-networkd你可以做到這一點通過啓用systemd-networkd-等待online.service

systemctl enable systemd-networkd-wait-online.service

這將確保所有的C已啓動的網絡設備已啓動並且具有在引導繼續之前分配的IP地址。此服務將在90年代後超時。即使未達到超時,啓用此服務也可能會延遲啓動。這兩項服務默認都是禁用的。

或者,你可以改變你的服務需要網絡可達,包括後= network-online.target想要= network-online.target(freedesktop。組織,2015年)

檢查的=前,在手冊頁後=選擇選項。這些選項可以改變systemd啓動單位的順序,然後選擇你必須啓動的單位。


希望這會幫助你,如果不是解決你的問題,而是找到解決問題的方法。

+0

非常感謝。啓用NetworkManager-wait-online.service解決了此問題。其他方法 - 比如向network.target和network-online.target添加依賴關係是不夠的。 – T4ng10r

+0

我有與OP相同的問題與lighttpd,綁定和後綴(所有綁定到特定的IP)。 'network-online.target'似乎不工作.. – TCB13

相關問題