我想在启动时执行python3脚本-使用systemd可以正常工作。但是,我也想设置一个看门狗,以便万一失败,脚本将重新启动。
问题是:为此,我需要通知看门狗我的脚本仍在定期运行。我使用库string nameOrConnectionString = "YOUR_CONNECTION_STRING";
var dbcontext = new IdentityDbContext(nameOrConnectionString);
var userStore = new UserStore(dbcontext);
var roleStore = new RoleStore(dbcontext);
var UserManager = new UserManager(roleStore);
var RoleManager = new RoleManager(roleStore);
进行此操作。我可以实现它并运行脚本sdnotify
,而不会出现任何问题。一旦运行基本调用python3 notifyTest.py
的服务(sudo systemctl start notifyTest.service
),就会收到ImportError:
ImportError:没有名为“ sdnotify”的模块
因此,唯一的区别是我没有显式调用脚本,而是通过启动服务来调用它。 我不知道为什么我突然遇到这个错误。
我的文件是:(注意:notifyTest.py直到第一行(导入lib)才很有趣,但是为了提供一个完整的最小示例,我包括了实际上通知看门狗的部分)
python3 notifyTest.py
File: /lib/systemd/system/notifyTest.service
[Unit]
Description=Door Server Service. Should always run.
[Service]
ExecStart=/usr/bin/python3 /home/notifyTest.py
StandardOutput=syslog
WatchdogSec=20s
Restart=on-failure
NotifyAccess=all
[Install]
WantedBy=multi-user.target
Alias=doorman.service