编辑:
我编写了一个 Python 脚本,用于在启用 TLS 选项的情况下启动 mosquitto 客户端。当我从命令行(不使用 sudo)运行它时,一切运行正常。现在,在重新安装一些软件包后,它就坏了。
但是,我需要脚本在系统启动时启动,因此我创建了一个 SYSTEMD 服务作为守护进程运行。根据服务状态报告,我推断cert
或key
文件不可用,因此守护进程存在错误。这些文件与 .py 脚本位于同一目录中。有什么想法可能是什么问题吗?
pi@raspberrypi:~/FONA_PROJECT $ sudo systemctl status fonagps.service
● fonagps.service - Vechicle Tracking System
Loaded: loaded (/lib/systemd/system/fonagps.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2018-03-19 22:17:59 UTC; 3s ago
Process: 1526 ExecStart=/usr/bin/python /home/pi/FONA_PROJECT/iot_sub.py (code=exited, status=1/FAILURE)
Main PID: 1526 (code=exited, status=1/FAILURE)
Mar 19 22:17:59 raspberrypi systemd[1]: Started Vechicle Tracking System.
Mar 19 22:17:59 raspberrypi python[1526]: Traceback (most recent call last):
Mar 19 22:17:59 raspberrypi python[1526]: File "/home/pi/FONA_PROJECT/iot_sub.py", line 129, in <module>
Mar 19 22:17:59 raspberrypi python[1526]: client.tls_set(ca_certs=ca_certs, certfile=certfile, keyfile=keyfile, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
Mar 19 22:17:59 raspberrypi python[1526]: File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 694, in tls_set
Mar 19 22:17:59 raspberrypi python[1526]: context.load_cert_chain(certfile, keyfile)
Mar 19 22:17:59 raspberrypi python[1526]: IOError: [Errno 2] No such file or directory
Mar 19 22:17:59 raspberrypi systemd[1]: fonagps.service: Main process exited, code=exited, status=1/FAILURE
Mar 19 22:17:59 raspberrypi systemd[1]: fonagps.service: Unit entered failed state.
Mar 19 22:17:59 raspberrypi systemd[1]: fonagps.service: Failed with result 'exit-code'.