我已经使用systemd创建了自己的服务。它应该在启动时运行一次python脚本。它发送带有IP地址和Teamviewer ID的电子邮件,这就是为什么我在其中有一个延迟,否则我会收到一个错误,指出无法解析邮件服务器的域。由于延迟30秒,该脚本应在后台运行。 该脚本位于/usr/bin/glatv.py中,并且可以执行,该脚本运行没有问题。该结构在Raspian Buster 2020-02-13的Raspberry Pi4上运行
该服务位于/ etc / systemd / system /中,可以执行并启用:
[Unit]
Description=My Own Service
[Service]
Type=oneshot
ExecStart=/usr/bin/glatv.py &
[Install]
WantedBy=reboot.target
但是
systemctl start myservice
正在正常工作
● glatvd.service - My Own Service
Loaded: loaded (/etc/systemd/system/glatvd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Apr 02 12:52:31 raspberrypi systemd[1]: Starting My Own Service...
Apr 02 12:53:02 raspberrypi systemd[1]: glatvd.service: Succeeded.
Apr 02 12:53:02 raspberrypi systemd[1]: Started My Own service.
重启后没有通话或登录
答案 0 :(得分:0)
您应该尝试运行此命令以使您的服务在重新启动后能够运行
systemctl enable myservice
对于日志,我相信您必须将此参数放入服务的配置文件中
StandardOutput=/path/to/info/log/info_log.log
StandardError=/path/to/error/log/error_log.log
我得到的任何参考:How to redirect output of systemd service to a file
答案 1 :(得分:0)
将延迟添加到您的服务文件中,而不是延迟30秒:
After=network-online.target
Wants=network-online.target