2017-10-11 202 views
0

大家好,在sturtup上運行腳本還是在網絡上運行? Ubuntu17.04

這個問題可能是愚蠢的,我試圖谷歌,但沒有爲我工作。

所以我需要的是後接口ENO1在啓動時運行的腳本和eno2並得到了他們的IP地址:

#!/bin/sh 
ip rule add from 172.28.1.0/24 pref 200 lookup 201 
ip route add default via 172.28.1.1 dev eno1 table 201 
ip rule add from 172.28.2.0/24 pref 200 lookup 202 
ip route add default via 172.28.2.1 dev eno2 table 202 
ip route add default nexthop via 172.28.1.1 dev eno1 
ip route append default nexthop via 172.28.2.1 dev eno2 
ip route flush cache 
systemctl start apache2 

這是設置一些網絡參數。 所以,我想:

1.將命令添加到/etc/rc.local

不工作,因爲我沒有/etc/rc.local文件中

2.添加該腳本啓動應用程序

不工作假設需要一個sudo的權利(不知道如何使用sudo在啓動時運行腳本)

3.添加一個init腳本(過時)

不工作,我假設因爲sudo權利,因爲在以前的情況下。

評論:我這樣做是因爲系統啓動後systemctl啓動Apache2,Apache2的退出與一個錯誤:

no listening sockets available, shutting down 

編輯: 我創建了一個服務 - net_conf.service:

[Unit] 
After=network-online.target 

[Service] 
ExecStart=/network_configuration/conf.sh 

[Install] 
WantedBy=default.target 

我的腳本是conf.sh,你可以在下面看到。

它下一個(systemctl狀態net_conf.service)其結果是:

Oct 10 23:02:09 loraserver conf.sh[1848]: RTNETLINK answers: Network is unreachable 
Oct 10 23:02:09 loraserver conf.sh[1848]: RTNETLINK answers: File exists 
Oct 10 23:02:09 loraserver conf.sh[1848]: RTNETLINK answers: Network is unreachable 
Oct 10 23:02:09 loraserver conf.sh[1848]: RTNETLINK answers: Network is unreachable 
Oct 10 23:02:09 loraserver conf.sh[1848]: RTNETLINK answers: Network is unreachable 
Oct 10 23:02:09 loraserver conf.sh[1848]: Job for apache2.service failed because the control process exited with error code. 
Oct 10 23:02:09 loraserver conf.sh[1848]: See "systemctl status apache2.service" and "journalctl -xe" for details. 

EDIT2: 而且試圖添加-s -q --timeout = 30,並用120個參數的EXE啓動。不起作用。 有什麼建議嗎?

任何幫助表示讚賞,謝謝您提前。

最好的問候, 奧列格Somov

回答

0

隨着Linux新版本(包括Ubuntu 15.04以來的版本我認爲)systemd是啓動系統服務的系統。通常在systemd中創建一個服務文件,該文件將在操作系統啓動過程中的正確時間運行腳本。

你會發現這個文檔回答:

https://wiki.ubuntu.com/SystemdForUpstartUsers

它詳細介紹瞭如何創建一個新的服務,以及如何將其設置爲運行在啓動時(或在其他時間)。