2017-10-11 197 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

它详细介绍了如何创建一个新的服务,以及如何将其设置为运行在启动时(或在其他时间)。

相关问题