问题描述
我制作了一个小的python3脚本来记录mpu9250的磁性数据。我可以通过
将其作为服务启动debian@beaglebone:~$ sudo systemctl start logdata.service
debian@beaglebone:~$ sudo systemctl status logdata.service
● logdata.service - Logging of 6D-Sensor to SD-card
Loaded: loaded (/lib/systemd/logdata.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-09-20 10:32:19 UTC; 16s ago
Main PID: 1622 (python3)
Tasks: 1 (limit: 1026)
Memory: 9.9M
CGroup: /system.slice/logdata.service
└─1622 python3 /var/lib/cloud9/oe8bck/imu.py
Sep 20 10:32:19 beaglebone systemd[1]: Started Logging of 6D-Sensor to SD-card.
但是在启动时启用它并不会启动:
debian@beaglebone:~$ sudo service logdata status
[sudo] password for debian:
● logdata.service - LSB: log sensor data to SD-card
Loaded: loaded (/etc/init.d/logdata; generated)
Active: active (exited) since Sun 2020-09-20 09:40:18 UTC; 1min 38s ago
Docs: man:systemd-sysv-generator(8)
Process: 550 ExecStart=/etc/init.d/logdata start (code=exited,status=0/SUCCESS)
Sep 20 09:40:36 beaglebone logdata[550]: /usr/local/lib/python3.7/dist-packages/rcpy-0.5.1-py3.7-linux-armv7l.egg/rcpy/__init__.py:127: UserWarni
Sep 20 09:40:36 beaglebone logdata[550]: warnings.warn('> Installing signal handlers')
Sep 20 09:40:36 beaglebone logdata[550]: Press Ctrl-C to exit
Sep 20 09:40:36 beaglebone logdata[550]: Bye BeagleBone!
Sep 20 09:40:36 beaglebone logdata[550]: Traceback (most recent call last):
Sep 20 09:40:36 beaglebone logdata[550]: File "/var/lib/cloud9/oe8bck/imu.py",line 59,in <module>
Sep 20 09:40:36 beaglebone logdata[550]: data=mpu9250.read()
Sep 20 09:40:36 beaglebone logdata[550]: mpu9250.error: Failed to read magnetometer data
Sep 20 09:40:36 beaglebone logdata[550]: Initiating cleanup...
Sep 20 09:40:36 beaglebone logdata[550]: Done with cleanup
在脚本中添加等待状态没有帮助,因此我认为守护程序是在正确初始化I2C总线之前启动的。哪个服务提供此服务?
非常感谢您的提示!
KR, 克里斯托夫
解决方法
sudo systemctl启用MyService.service
我找到了此信息。在这些地址上在线获取有关在Linux上设置服务文件的信息。
- https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
- https://www.freedesktop.org/software/systemd/man/systemd.service.html
因此,sudo systemctl start MyService.service
使.service文件在当前会话期间正常工作。
然后,sudo systemctl enable MyService.service
在重新引导或引导系统时使.service文件在引导期间工作。
如果您需要更多信息,请询问。
P.S。当我使用/ etc / systemd / system作为我的文件位置来启动/引导时,我还看到您正在使用/etc/init.d ...