
私は、シャットダウンする前に(再起動時ではなく)システムを更新し、その進行状況を 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
そして実行中であると返されます。これは意味がありません
編集2: plymouth-x11 では、update() 関数と plymouth() 関数を削除 (行を削除) すると、plymouth にメッセージが表示されることがわかりました。関数を再度追加すると、再びエラーが発生します。また、関数宣言の上に plymouth コマンドを配置すると、再び機能するようになります。
編集3: 関数を削除し、コードを追加のファイルに配置しました。これで期待どおりに動作します (少なくとも私のテスト環境では)。それでは質問です: 関数を追加するとスクリプトが壊れるのはなぜでしょうか?
編集4: 呼び出したいコマンドのような関数名を付けないでください -_-
編集5: 再起動するとスクリプトは何も表示されなくなるはずですが、それでも、plymouth はメッセージを表示せず、シャットダウン時にスクリプトは呼び出されないようです。これらは私が現在知っている問題であり、呼び出されないスクリプトをテストするのはかなり困難です。plymouth-x11 を使用して plymouthd を手動で起動すると、スクリプトは機能します。
私はUbuntu 21.04を使用しています