过程:

写了一个自定义systemctl的service,很简单,就是执行一个脚本去配置IP。

/etc/systemd/system/configip.service

[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

ifconfig eth0 192.168.2.10
echo "ifconfig eth0 192.168.2.10"

可是执行的时候不起作用,使用status查看

systemctl status configip

发现报错,错误码203:

 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

#!/bin/sh
ifconfig eth0 192.168.2.10
echo "ifconfig eth0 192.168.2.10"

问题解决!

systemctl自定义service执行shell脚本时报错code exited status 203 EXEC
Tagged on:     

发表评论

邮箱地址不会被公开。 必填项已用*标注