我对程序之间的差异感到好奇。通过systemctl启用时,以systemd开头,而不是/etc/rc.local通过CLI或通过CLI进行启动。
例如,我最近在树莓派上使用shairport-sync。最初,我通过启用sudo systemctl的shairport-sync将shairport-sync设置为启动。
后来,我使用其中的功能在shairport-sync脚本运行之前和发布到连接的设备。
令我惊讶的是,这些脚本在执行shairport-sync时没有kill arecord或aplay
但是,当我通过终端运行脚本时,脚本将执行并杀死arecord和aplay。
为了进一步迷惑自己,我shairport-sync通过终端杀死并启动了它,以查看正在发生的事情的输出。当我这样做时,脚本在设备连接并终止arecord并终止时按预期运行aplay。因此,作为一项修复,我禁用shairport-sync了sysmtectl它并将其设置/etc/rc.local为作为快速修复运行。之后,reboot它按我的预期运行。
这使我相信,单独运行systemd的程序与通过/etc/rc.local或CLI 启动时运行的程序之间存在一些差异。
为什么会这样?这是因为运行级别不同吗?一些黑魔法?
设备连接到时运行的脚本shairport-sync如下:shairportstart.sh
#!/bin/sh
/usr/bin/sudo /bin/pkill arecord
if [ $(date +%H) -ge "18" -o $(date +%H) -le "7" ]; then
/usr/bin/amixer set Speaker 40%
else
/usr/bin/amixer set Speaker 100%
fi
/home/pi/shScripts/shairportfade.sh&
exit 0
这是渐变脚本: shairportfade.sh
#!/bin/sh
/usr/bin/amixer set Speaker 30-
for (( i=0; i<30; i++))
do
/usr/bin/amixer set Speaker 1+
done
exit 0
设备断开连接时运行的脚本shairport-sync如下:shairportend.sh
#!/bin/sh
/usr/bin/amixer set Speaker 70%
/usr/bin/arecord -D plughw:1 -f dat | /usr/bin/aplay -D plughw:1 -f dat&
exit 0
我/var/log/syslog只有在最初以shairport-sync的身份运行时才发现以下错误systemd。当shairport-sync从CLI运行或/etc/rc.local没有错误存在。
Jan 24 00:38:45 raspberrypi shairport-sync[617]: sudo: no tty present and no askpass program specified
请注意,唯一的区别是shairport-sync设备连接或断开连接shairport-sync继续运行时的初始启动方式。
/home/pi/shScripts/shairportfade.sh吗?
rc.local
ps ... awk ... grep ...东西可能会被更简单的东西所取代pkill