【发布时间】:2022-01-06 01:23:02
【问题描述】:
我需要 bash 和 systemctl 服务方面的帮助...
我的问题是我的公司要求我自动启动在我们的 KVM 服务器 (CentOS) 上运行的所有虚拟机,我们总共有 5 台物理主机;但是,我在其中一个上遇到了一个问题,我最近更新了我的 VM 版本,我的服务
file: vmx.service
[Unit]
Description=Juniper vMX Router
Wants=network-online.target
After=network-online.target
After=libvirtd.service
[Service]
WorkingDirectory=/home/vMX-21.1R1/
Environment="PATH=/opt/rh/python27/root/usr/bin:/usr/lib64/qt3.3/bin:/usr/local/sbin:/usr/local/bin:/$
Type=oneshot
User=root
Group=root
RemainAfterExit=true
## Commands used to stop/start/restart the vMX
ExecStart=/bin/bash -c './path-python.sh'
ExecStart=/bin/bash -c './vmx.sh -lv --start --cfg config/pod8/vmx1.conf' <<<<<<<<<<<<<<<<<<<<<<<
ExecStart=/bin/bash -c './vmx.sh -lv --start --cfg config/pod8/vmx2.conf'
ExecStart=/bin/bash -c './vmx.sh -lv --start --cfg config/pod8/vr-device.conf'
[Install]
WantedBy=multi-user.target
这是我的服务状态:
Loaded: loaded (/etc/systemd/system/vmx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2021-11-29 14:04:37 AEST; 2h 4min ago
Process: 2324 ExecStart=/bin/bash -c ./vmx.sh -lv --start --cfg config/pod8/vmx1.conf (code=exited, status=2)
Process: 1877 ExecStart=/bin/bash -c ./path-python.sh (code=exited, status=0/SUCCESS)
Main PID: 2324 (code=exited, status=2)
Nov 29 14:04:37 Juniper-KVM3 bash[2324]: import netifaces as ni
Nov 29 14:04:37 Juniper-KVM3 bash[2324]: ImportError: No module named netifaces
Nov 29 14:04:37 Juniper-KVM3 bash[2324]: Log file........................................../home....log
Nov 29 14:04:37 Juniper-KVM3 bash[2324]: ==================================================
Nov 29 14:04:37 Juniper-KVM3 bash[2324]: Aborted!. 1 error(s) and 0 warning(s)
Nov 29 14:04:37 Juniper-KVM3 bash[2324]: ==================================================
Nov 29 14:04:37 Juniper-KVM3 systemd[1]: vmx.service: main process exited, code=exited, status=2...MENT
Nov 29 14:04:37 Juniper-KVM3 systemd[1]: Failed to start Juniper vMX Router.
Nov 29 14:04:37 Juniper-KVM3 systemd[1]: Unit vmx.service entered failed state.
Nov 29 14:04:37 Juniper-KVM3 systemd[1]: vmx.service failed.
我认为错误:ImportError: No module named netifaces 将通过运行来修复
pip uninstall netifaces && pip install netifaces 读入this article。
但是,它也不起作用,无论如何,最奇怪的是,当我在终端中运行相同的脚本时,它起作用了:
[root@system]# ./vmx.sh -lv --stop --cfg config/pod8/vmx1.conf
[...]
==================================================
VMX Status Verification Completed.
==================================================
Log file........................................../home/vMX-21.1R1/build/8m1/logs/vmx_1638166233.log
==================================================
Thank you for using VMX
==================================================
我确保 SElinux 被禁用:
SELinux status: disabled
值得注意的是./path-python.sh脚本运行没有问题,这个脚本可以让我改变我的python27路径,否则我的VM安装会失败,但我可以肯定地说这个问题与 python 本身无关,因为该脚本仅在我在终端中运行时才有效。 (我的其他服务器使用相同的脚本和 bash 按预期工作,我不知道出了什么问题)。
【问题讨论】:
-
我怀疑你的脚本在网络服务之前启动,所以它没有找到任何 netifaces。但是当计算机启动时,网络正在运行,并且您手动运行脚本时,netifaces 就在那里。