我有这个 python 代码,我需要运行systemd它并监视它是否也被挂起。问题是,当我直接从 systemd 运行 python 脚本时,它工作正常。但是,当 python 脚本从另一个从我的 systemd 服务运行的 shell 脚本运行时,它说sdping_py.service: Got notification message from PID 6828, but reception only permitted for main PID 6768问题似乎是作为 shell 脚本和 systemd 服务的子进程运行的 python 脚本期望来自 shell 脚本的通知,这是服务的主要进程。我怎样才能解决这个问题?我的应用程序严格需要从 shell 脚本运行。这是我试过的python代码,import sdnotify, timen = sdnotify.SystemdNotifier()print("Gonna start")time.sleep(2)print("Started!")n.notify("READY=1")i=0while True: print(i) time.sleep(1) n.notify("WATCHDOG=1") i+=1这是我的服务文件[Unit]Description=Test watchdog Demo processDefaultDependencies=falseRequires=basic.target[Service]Type=notifyWatchdogSec=2ExecStart=/home/teshanl/sdping/scripts/sdping_py.sh#ExecStart=/usr/bin/python /home/teshanl/sdping/src/sdping_pub.pyStartLimitInterval=5minStartLimitBurst=5#StartLimitAction=rebootRestart=always这是shell文件#!/bin/bash/usr/bin/python /home/teshanl/sdping/src/sdping_pub.py
1 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
使用exec
, 用 python 进程替换 bash 进程:
exec /usr/bin/python ...
或设置NotifyAccess
为all
,以允许分叉子 python 进程发送 sd 消息,请参阅此线程。
添加回答
举报
0/150
提交
取消