1 查看启用的units
systemctl list-unit-files | grep enabled
2 查看指定服务的日志 按服务单元过滤
journalctl -u j 查看j.service的日志 /输入shift+f 与tail -f等效 / 输入sfhit+g 到日志尾部
3 增加工作目录
#!/bin/sh - [Unit] Description=ATF Grafic Console [Service] WorkingDirectory=/home/pi ExecStart=/home/pi/launchscript.sh #ExecStart=-/RaspberryPi/ConsolaGrafica Restart=always #StandardOutput=syslogConsola # Output to syslog #StandardError=syslogConsola # Output to syslog [Install] WantedBy=multi-user.target
启动服务失败的原因
-
wrong path to script (e.g. /home/py/ReadPressure2AndPostToMqtt.py) 错误的路径
-
script not executable 脚本没有可执行权限
-
no shebang (first line) 脚本第一行没有shebang #!/bin/sh
-
wrong path in shebang (e.g. /bin/python3) shebang是错的
-
internal files in your script might be missing access permissions. 脚本内部访问的文件没有权限