서비스가 있는데 다음과 같은 경우 서비스를 시작하고 중지하고 싶습니다.특정 네트워크 인터페이스위아래로 움직입니다 ( eth0
저의 경우). 문서와 게시물을 읽고 아래 장치에 접속했는데 불행히도 작동하지 않습니다.
명확히 하자면, 제가 원하는 것은 eth0
올라갈 때 my-service.service
시작 하고 eth0
내려갈 때 멈추는 것입니다 my-service.service
.
문제의 인터페이스는 관리 systemd-networkd
되며 고정 IP와 DHCP 서버가 있습니다.
systemd를 사용하여 이 작업을 수행할 수 있는 옵션이 있습니까? 아니면 유일한 옵션은 다음과 같은 다른 서비스입니다.networkd-dispatcher
?
시스템은 Yocto 프로젝트에서 만든 systemd
250.4 및 systemd-networkd
.
my-service.service
[Unit]
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device
BindsTo=nats.service
After=nats.service
BindsTo=postgresql.service
After=postgresql.service
[Service]
Type=simple
Restart=on-failure
EnvironmentFile=/opt/my/environment.txt
ExecStart=/opt/my/executable
[Install]
WantedBy=multi-user.target
systemctl list-units
흥미로운 내용이 표시되지 않습니다.
root@device:~# systemctl list-units | grep -i net
sys-devices-platform-bus\x405a000000-5a8e0000.can-net-can0.device loaded active plugged /sys/devices/platform/bus@5a000000/5a8e0000.can/net/can0
sys-devices-platform-bus\x405a000000-5a8f0000.can-net-can1.device loaded active plugged /sys/devices/platform/bus@5a000000/5a8f0000.can/net/can1
sys-devices-platform-bus\x405b000000-5b040000.ethernet-net-eth0.device loaded active plugged /sys/devices/platform/bus@5b000000/5b040000.ethernet/net/eth0
sys-devices-platform-bus\x405b000000-5b050000.ethernet-net-eth1.device loaded active plugged /sys/devices/platform/bus@5b000000/5b050000.ethernet/net/eth1
sys-subsystem-net-devices-can0.device loaded active plugged /sys/subsystem/net/devices/can0
sys-subsystem-net-devices-can1.device loaded active plugged /sys/subsystem/net/devices/can1
sys-subsystem-net-devices-eth0.device loaded active plugged /sys/subsystem/net/devices/eth0
sys-subsystem-net-devices-eth1.device loaded active plugged /sys/subsystem/net/devices/eth1
dhcpcd.service loaded active running A minimalistic network configuration daemon with DHCPv4, rdisc and DHCPv6 support
rdisc.service loaded active running Network Router Discovery Daemon
systemd-network-generator.service loaded active exited Generate network units from Kernel command line
systemd-networkd.service loaded active running Network Configuration
systemd-resolved.service loaded active running Network Name Resolution
systemd-timesyncd.service loaded active running Network Time Synchronization
xinetd.service loaded active running Xinetd A Powerful Replacement For Inetd
systemd-networkd.socket loaded active running Network Service Netlink Socket
network-pre.target loaded active active Preparation for Network
network.target loaded active active Network
nss-lookup.target loaded active active Host and Network Name Lookups
답변1
제가 올바르게 이해했다면 네트워크가 다운되었다는 맞춤 알림을 받고 싶으신가요?
my-service.service에 "ExecStopPost" 키를 추가하는 대신 서비스가 종료될 때 실행해야 하는 스크립트/응용 프로그램을 가리킵니다.
.service 파일에 대한 전체 설명을 보려면 여기를 읽어보세요. https://www.freedesktop.org/software/systemd/man/systemd.service.html