我有這個 python 代碼,我需要運行systemd它并監(jiān)視它是否也被掛起。問題是,當我直接從 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條經(jīng)驗 獲得超5個贊
使用exec
, 用 python 進程替換 bash 進程:
exec /usr/bin/python ...
或設置NotifyAccess
為all
,以允許分叉子 python 進程發(fā)送 sd 消息,請參閱此線程。
添加回答
舉報
0/150
提交
取消