过程:
写了一个自定义systemctl的service,很简单,就是执行一个脚本去配置IP。
/etc/systemd/system/configip.service
1 2 3 4 5 6 7 8 9 10 11 12
| [Unit] Description=configip service
[Service] ExecStart=/home/root/configip.sh ExecReload=/home/root/configip.sh ExecStop=
StandardOutput=tty [Install] WantedBy=multi-user.target
|
/home/root/configip.sh
1 2
| ifconfig eth0 192.168.2.10 echo "ifconfig eth0 192.168.2.10"
|
可是执行的时候不起作用,使用status查看
1
| systemctl status configip
|
发现报错,错误码203:
1 2 3 4 5 6
| configip.service - configip service Loaded: loaded (/etc/systemd/system/configip.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2018-01-01 00:02:50 HKT; 6s ago Process: 649 ExecStart=/home/root/configip.sh (code=exited, status=203/EXEC) Main PID: 649 (code=exited, status=203/EXEC)
|
原因:
systemctl执行脚本时需要知道脚本的解释器
解决方法:
在/home/root/configip.sh脚本的开头加上#!/bin/sh
1 2 3
| #!/bin/sh ifconfig eth0 192.168.2.10 echo "ifconfig eth0 192.168.2.10"
|
问题解决!