服务未在boot debian中启动

问题描述 投票:0回答:1

我有一个启动脚本,但是出现退出状态2错误。但是,一旦系统启动,我就运行脚本,并且运行正常,没有任何问题。会是什么?

noname@debian:~$ cat /etc/systemd/system/arp_estatica.service 
[Unit]
Description=Script service
After=network.target network-online.target
Wants=network-online.target

[Service]
ExecStart=/etc/init.d/arp_estatica

[Install]
WantedBy=multi-user.target


noname@debian:~$ sudo systemctl status arp_estatica 
● arp_estatica.service - Script service
   Loaded: loaded (/etc/systemd/system/arp_estatica.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-12-31 03:48:25 CET; 8min ago
 Main PID: 710 (code=exited, status=2)

dic 31 03:48:25 debian systemd[1]: Started Script service.
dic 31 03:48:25 debian systemd[1]: arp_estatica.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
dic 31 03:48:25 debian systemd[1]: arp_estatica.service: Failed with result 'exit-code'.


noname@debian:~$ cat /etc/init.d/arp_estatica 
#!/bin/bash

### BEGIN INIT INFO
# Provides:          arp_estatica
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Entrada estatica para evitar mitm
### END INIT INFO

arp -s $(route -n | grep -e '^0.0.0.0' | awk '{print $2}' | sed -n '1p') $(arp -n | grep `route -n | grep -e '^0.0.0.0' | awk '{print $2}' | sed -n '1p'` | awk '{print $3}')
exit 0
linux service
1个回答
0
投票

似乎在执行命令时/ net / proc / arp为空。因此,我一开始已对此进行了修复。

#!/bin/bash

### BEGIN INIT INFO
# Provides:          arp_estatica
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: Entrada estatica para evitar mitm
### END INIT INFO

cmd=$(cat /proc/net/arp | wc -l | awk '{print $1}')
while [ $cmd -eq 1 ]
do
        sleep(1)
        cmd=$(cat /proc/net/arp | wc -l | awk '{print $1}')
done
arp -s $(route -n | grep -e '^0.0.0.0' | awk '{print $2}' | sed -n '1p') $(arp -n | grep `route -n | grep -e '^0.0.0.0' | awk '{print $2}' | sed -n '1p'` | awk '{print $3}')
exit 0
© www.soinside.com 2019 - 2024. All rights reserved.