在花了很多时间重新启动Raspberry并检查systemd [Unit]脚本是否工作后,我决定在这里提问。
我想在加载raspbian图形界面时启动脚本:
#!/bin/sh
# the & is for not needing the whole shell for one APP !
# this is just a test:
cd /home/pi/Desktop;
sudo touch test2.txt;
# opens sqlite browser for watching databank
sudo sqlitebrowser &
# opens the directory where all files are included:
cd /home/pi/Desktop
sudo nautilus test08-01 &
其他文件:
[Unit]
Description=Start Clock
[Service]
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/pi/.Xauthority
ExecStart=/usr/local/sbin/my-startup2.sh
Restart=always
RestartSec=100s
KillMode=process
TimeoutSec=0
[Install]
WantedBy=graphical.target
但是,这会打开sqlitebrowser太多次了。我希望我的脚本在图形界面加载后仅启动once。
要登录到桌面后启动sqlitebrowser,就这么简单:
# ~/.config/systemd/user/sqlitebrowser.service
[Service]
ExecStart=/usr/bin/sqlitebrowser
Environment=DISPLAY=:0
[Install]
WantedBy=graphical.target
如果要更改现有服务,请使用systemctl --user daemon-reload
。
您可以用systemctl --user start sqlitebrowser.service
进行测试。如果可行,那么您应该不错!
通过systemctl --user enable sqlitebrowser.service
启用。
注意:我在~/.config/...
中安装了* .service文件,此处使用--user
,因为我们通常不以root用户身份运行GUI应用程序。我怀疑您不打算以root用户身份运行它,而只是想使其正常运行。