我正在尝试创建一个 systemctl 单元,只有当另一个单元处于活动状态时,该单元才会启动。据我所知,可以通过指定一个Requisite
字段来完成。因此,我已按如下方式配置我的单元:
[Unit]
Description=Force clients with mismatching IPs to reconnect
[email protected]
[Service]
Type=oneshot
ExecStart=/etc/openvpn/kicker/kicker.py
TimeoutSec=15
但是,当我使用systemctl stop openvpn@server
和时systemctl start my-unit
,我收到以下日志:
Starting openvpn-kicker.service - Force clients with mismatching IPs to reconnect...
Dependency failed for openvpn-kicker.service - Force clients with mismatching IPs to reconnect.
openvpn-kicker.service: Job openvpn-kicker.service/start failed with result 'dependency'.
kicker.py[1026]: Traceback (most recent call last):
kicker.py[1026]: File "/etc/openvpn/kicker/kicker.py", line 16, in <module>
kicker.py[1026]: manage.connect(Manage_Path)
kicker.py[1026]: FileNotFoundError: [Errno 2] No such file or directory
Main process exited, code=exited, status=1/FAILURE
openvpn-kicker.service: Failed with result 'exit-code'.
因此,基本上,单元在需求检查时失败,但无论如何都会在“ExecStart”中执行脚本 - 因此出现 python 错误。它是否打算以这种方式工作,而我弄错了什么,或者这是一个错误?如果相关,操作系统是 Ubuntu 22.04