quatmo
Well-Known Member
Học từ bài của anh @tml3nr , thanks anh!
SMPD 0.96 Update #3
Các bác đam mê cải tiến SMPD có thể theo cách sau để tối ưu hệ thống tắt các service khi đang play TC.
Lệnh kiểm tra TC
Khi TC đang idle, kết quả là số 14Mã:pgrep -wc tidal_connect
Khi TC có phone kết nối, kết quả là số 16
Khi TC đang play, kết quả là số 17
Nhờ vào điều trên mình làm 2 việc:
1. Mod lại file /home/pi/misc/ympd_event.sh
Những phần mod:
#START ADDON
#STOP ADDON
#CHECK PLAY (2 vị trí)
---------
Mã:#!/bin/bash urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } parse() { echo `cat "$1" | sed -n "s/^[ \t]*$2[ \t]*[=]*[ \t]*//p" | head -n1 | sed -e "s/\"//g"` } case "$1" in r) # read conf (plain text) parse $2 $3 ;; w) # write conf tmp=$(urldecode "$3") if [[ $tmp == *=* ]];then key=`echo $tmp | cut -f1 -d'='` val=`echo $tmp | cut -f2 -d'='` else key=$tmp val="" fi if [ "$key" = "" ];then echo error elif [ "$val" = "" ];then # read parse $2 $key else # write line=`grep -nE "^\s*$key(\s|=)+" "$2" | head -n1 |sed -e 's/:.*//g'` echo $2 $key $val $line sed -i -e "$line s|\(^\s*$key\s*[\s|=|\"]\{1\}\s*\)[^\"]*\(\"*\)|\1$val\2|" "$2" sync fi ;; p) # list plugins (json) TARGET=.$2 cd /home/pi/plugins CMD="" i=0 for dir in `ls -d $TARGET/*` do CMD=$CMD'.['$i'].path="'$dir'"|' let ++i done CMD=$CMD. cat $TARGET/*/app.json|jq -s -c '.'| jq $CMD ;; isolate) systemd-run --nice=19 systemctl stop spotifyd systemd-run --nice=19 systemctl stop shairport-sync systemd-run --nice=19 systemctl stop tidal systemd-run --nice=19 systemctl stop aprenderer systemd-run --nice=19 systemctl stop minidlna #systemd-run --nice=19 systemctl stop upmpdcli sleep 0.4 ;; #STOP ADDON addon-stop) systemd-run --nice=19 systemctl stop shairport-sync systemd-run --nice=19 systemctl stop aprenderer systemd-run --nice=19 systemctl stop minidlna #systemd-run --nice=19 systemctl stop upmpdcli sleep 1 systemctl start soundcheck.service sleep 1 systemctl stop ympd systemctl stop ympd.socket systemctl stop mpd umount /var/lib/mpd/music/NAS/* sync sleep 0.4 exit ;; ###### END STOP ADDON ###### #START ADDON addon-start) sleep 2 if [ "`pgrep -wc tidal_connect`" = "16" ];then #echo "It's start addon" systemctl start ympd.socket mount -a systemctl start mpd systemctl start shairport-sync systemctl start aprenderer systemctl start minidlna fi sync sleep 0.4 exit ;; ###### END START ADDON ###### stop-avahi) #systemd-run --nice=19 systemctl stop avahi-daemon #systemd-run --nice=19 systemctl stop avahi-daemon.socket sleep 0.4 ;; pause) #CHECK PLAY if [ "`pgrep -wc tidal_connect`" = "17" ];then echo "It's play" systemd-run /home/pi/misc/ympd_event.sh addon-stop fi ###### END CHECK PLAY ###### if [ "`pidof spotifyd`" = "" ];then if [ `journalctl -u spotifyd|grep "Authenticated as" | wc -l` -gt 0 ];then systemd-run /home/pi/misc/ympd_event.sh spotifyd-start fi fi ;; spotifyd-start) sleep 2 systemctl start spotifyd ;; stop) if [ $(mpc|grep "\[playing\]"|wc -l) = 1 -o $(mpc|grep "\[paused\]"|wc -l) = 1 ];then exit fi #CHECK PLAY if [ "`pgrep -wc tidal_connect`" = "17" ];then echo "It's play" systemd-run /home/pi/misc/ympd_event.sh addon-stop fi ###### END CHECK PLAY ###### if [ "`pidof spotifyd`" = "" ];then if [ `journalctl -u spotifyd|grep "Authenticated as" | wc -l` -gt 0 ];then systemd-run /home/pi/misc/ympd_event.sh spotifyd-start fi fi ;; browse) ls /var/lib/mpd/music/RAM/* >/dev/null 2>&1 if [ $? -eq 0 ]; then mpc update RAM fi ;; dashboard) /home/pi/util-plot.sh /home/pi/util-dashboard.sh ;; esac exit
2. Tạo thêm file soundcheck (Không enable service)
Mã:sudo nano /lib/systemd/system/soundcheck.service
Mã:[Unit] Description=Sound check for Addon After=sound.target [Service] Type=simple ExecStart=/home/pi/misc/ympd_event.sh addon-start Restart=always StartLimitInterval=5 User=root Group=root [Install] WantedBy=multi-user.target
Kết quả việc này là khi bấm play TC, giao diện YMPD, MPD, AP, DLNA... sẽ tắt đi.
Khi stop TC thì những cái trên tự động bật trở lại.
Các bác test thử nhé! Hy vọng con đường này sáng sủa.
--------
Nếu không muốn chỉnh code, các bác download mấy file này, dùng WinSCP copy vào thư mục /tmp/ rồi chạy từng dòng sau:
Mã:sudo tar -xf /tmp/ympd.tgz --overwrite -C /home/pi/misc/ sudo tar -xf /tmp/configs.tgz --overwrite -C /home/pi/configs/ sudo tar -xf /tmp/soundcheck.tgz --overwrite -C /lib/systemd/system/ sudo tar -xf /tmp/service.tgz --overwrite -C /etc/systemd/system/
https://drive.google.com/drive/folders/1KSxHF75me0sdcqSSQmx32bDSpt25h4Zo?usp=sharing
Cách STOP/START này có thể áp dụng cho OS khác OK.
MoodeAudio
File soundcheck.sh (mới update chút nhìn cho mạch lạc)
Mã:
sudo nano /home/pi/soundcheck.sh
Mã:
#!/bin/sh
if [ "`pgrep -wc tidal_connect`" = "16" ];then
echo "16"
sudo systemctl start upmpdcli.service
# MOODE WEB UI
sudo systemctl restart php7.3-fpm.service
sudo systemctl restart nginx
#exit
elif [ "`pgrep -wc tidal_connect`" = "17" ];then
echo "17"
sudo systemctl stop upmpdcli.service
# MOODE WEB UI
sudo systemctl stop php7.3-fpm.service
sudo systemctl stop nginx
#exit
else
echo "14"
exit
fi
Mã:
sudo chmod -R 777 /home/pi/soundcheck.sh
File soundcheck.service
Mã:
sudo nano /etc/systemd/system/soundcheck.service
Mã:
[Unit]
Description=Sound check for Addon
Requires=tidal.service
After=tidal.servict
[Service]
Type=simple
ExecStart=/bin/sh /home/pi/soundcheck.sh
Restart=always
RestartSec=2
User=root
Group=root
[Install]
WantedBy=multi-user.target
Mã:
sudo chmod -R 777 /etc/systemd/system/soundcheck.service
sudo systemctl enable soundcheck.service
sudo reboot
Khi stop TC, chừng 20s sau Web Moode mới hiện trở lại.
Check htop để biết Task: thr giảm xuống bao nhiêu.
Moode mình start AP, Asset luôn cả upmpdcli, Task: thr = 50.
Khi chạy TC thì tắt hết giảm xuống thr = 32.
--------------------
ROPI
soundcheck.sh
Mã:
#!/bin/sh
if [ "`pgrep -wc tidal_connect`" = "16" ];then
echo "16"
systemctl start upmpdcli
systemctl start ropieee-web
systemctl start mpd
systemctl start librespot
#exit
elif [ "`pgrep -wc tidal_connect`" = "17" ];then
echo "17"
systemctl stop upmpdcli
systemctl stop ropieee-web
systemctl stop mpd
systemctl stop librespot
#exit
else
echo "14"
exit
fi
Chỉnh sửa lần cuối: