
a) 시스템을 종료하기 전에(재부팅 시 아님) 업데이트하고 plymouth에서 사용자에게 진행 상황을 표시하는 스크립트를 작성하려고 합니다.
지금까지는 종료 시 스크립트를 시작하도록 관리했지만(때때로?) 재부팅 시에도 시작됩니다(수정 예정).
[Unit]
Description=Update on Shutdown
Before=poweroff.target halt.target shutdown.target
After=network-online.target multi-user.target
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=true
ExecStop=/usr/share/services/shutdown_update
TimeoutSec=infinity
[Install]
WantedBy=poweroff.target halt.target shutdown.target
실제 스크립트는 다음과 같습니다.
#!/bin/sh
fun_update() {
plymouth display-message --text "Aktualisierungen werden installiert..."
plymouth change-mode --updates
pkcon update -p -y > /tmp/update_status.txt
update=0
plymouth change-mode --boot-up
plymouth display-message --text "Aufräumen..."
apt-get autoclean
apt-get autoremove
plymouth change-mode --shutdown
}
fun_plymouth() {
while [ "$update" = 1 ]
do
plymouth system-update --progress $(cat /tmp/update_status.txt | grep -oP "(?<=Percentage: ).*" | tail -1)
plymouth display-message --text "$(cat /tmp/update_status.txt | grep -oP "(?<=Percentage: ).*" | tail -1)%"
sleep 1
done
}
if echo systemctl list-jobs | egrep -q 'reboot.target.*start';
then
exit 0
fi
plymouth change-mode --boot-up
update=0
plymouth display-message --text 'Aktualisierung wird vorbereitet...'
plymouth display-message --text "Es wird nach Aktualisierungen gesucht..."
pkcon refresh
update_list=$(pkcon get-updates)
echo $update_list
if ! echo "$update_list" | grep -q "There are no updates available at this time."; then
update=1
fun_update & fun_plymouth & wait
else
plymouth display-message --text "Keine Aktualisierungen gefunden!"
sleep 3
fi
plymouth display-message --text ""
이러한 기능이 수행하는 작업(또는 수행하려는 작업)은 a) 사용자에게 시스템이 업데이트될 예정임을 알리고, b) pkcon을 사용하여 업데이트를 시작하고, c) plymouth 오프라인 업데이트 스플래시(스플래시)를 표시하는 것입니다. 오프라인 업데이트가 설치될 때 표시됨) pkcon의 진행 상황을 가져와 사용자에게 표시합니다(이것이 마지막 일치 항목만 가져오기 위해 grep 및 tail -1을 사용하는 이유입니다).
그러나 어떤 이유로 스크립트를 시작할 수 있지만 plymouth 메시지가 표시되지 않고 pkcon이 시작되지 않거나 시작하더라도 실패합니다. 이 스크립트에는 아마도 많은 문제가 있을 것입니다. plymouth와 systemd는 실제로 도움이 되지 않기 때문에 디버깅하지 못했습니다.
모든 조언을 환영합니다! 매우 감사합니다!
편집: 스크립트를 테스트하기 위해 plymouth-x11을 설치했습니다. 흥미롭게도 스크립트에서 보낸 명령은 실행 시(루트 셸에서도) 여기에서도 무시되지만 루트 셸에 수동으로 입력한 정확한 명령은 작동합니다. 또한 plymouth가 실행 중인지 확인하기 위해 다음 줄을 추가했습니다.
plymouth --ping && echo plymouth is running || echo plymouth NOT running
실행 중임을 반환합니다. 이건 말도 안 돼
EDIT2: plymouth-x11을 사용하여 update() 및 plymouth() 함수를 제거(줄 삭제)하면 plymouth가 메시지를 표시한다는 것을 알았습니다. 기능을 다시 추가하면 다시 중단됩니다. 또한 함수 선언 위에 plymouth 명령을 배치하면 다시 작동하게 됩니다.
EDIT3: 기능을 제거하고 코드를 추가 파일에 배치했습니다. 이제 예상대로 작동합니다(적어도 내 테스트 환경에서는). 그래서 질문은: 함수를 추가할 때 왜 스크립트가 중단됩니까?
편집 4: 호출하려는 명령처럼 함수 이름을 지정하지 마세요 -_-
EDIT5: 따라서 재부팅할 때 스크립트는 더 이상 아무 것도 없어야 하지만 여전히 plymouth는 메시지를 표시하지 않으며 종료 시 스크립트가 호출되지 않는 것 같습니다. 이것이 제가 지금 알고 있는 문제입니다. 호출되지 않은 스크립트를 테스트하는 것은 꽤 어렵습니다. plymouth-x11을 사용하여 수동으로 plymouthd를 시작하면 스크립트가 작동합니다.
우분투 21.04를 실행 중입니다.