
システムを起動するたびに、次のように入力します。
# su
Password:
# hciattach -s 152000 /dev/ttyS1 billionton
これは私のBTマウスを初期化するために必要なものです。一時停止から再開したら、次のように入力する必要があります。
# su
Password:
hciattach PIDを見つけて終了します。
# pkill hciattach
# hciattach -s 152000 /dev/ttyS1 billionton
これで2つのスクリプトを作成しました。
# cat bt-mouse-suspend.service
[Unit]
Description=BT Mouse suspend helper
Before=sleep.target
[Service]
Type=simple
ExecStart=-/usr/bin/pkill hciattach
[Install]
WantedBy=sleep.target
# cat bt-mouse-resume.service
[Unit]
Description=BT Mouse resume helper
After=suspend.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/hciattach -s 152000 /dev/ttyS1 billionton
[Install]
WantedBy=suspend.target
# systemctl status bt-mouse-resume
● bt-mouse-resume.service - BT Mouse resume helper
Loaded: loaded (/etc/systemd/system/bt-mouse-resume.service; enabled; vendor preset: disabled)
Active: active (exited) since Mon 2017-04-03 22:09:50 EEST; 12min ago
Main PID: 6386 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/bt-mouse-resume.service
apr 03 22:09:50 Twinh systemd[1]: Started BT Mouse resume helper.
apr 03 22:09:51 Twinh hciattach[6386]: Device setup complete
# pgrep hciattach
#
ストップスクリプトは正常に動作し、予想される内容を終了します。しかし、履歴書hciattachは一度実行すると消えます。
答え1
After
あなたが話す内容が混乱して、After
サービスが開始される前に他のデバイスを待つことになります。あなたWanted-By=suspend.target
とAfter=suspend.target
あなたは互いに矛盾します。
Wanted-By
これを宣言するのはbt-mouse-resume.service
プロセスの一部ですが、suspend.target
宣言After
が完了するbt-mouse-resume.service
まで待つ必要がありますsuspend.target
。サービスはターゲットの一部ではありません。開始する前にそのターゲットを待つ必要があります。これはsuspend.target
、シャットダウンではなく起動時にサービスを実行するように構成することを意味します。
あなたが本当に探しているのは、停止している間に何かを実行する方法なので、suspend.target
次の中で非常に重要な部分をお知らせしますsystemd
。
順次依存関係を持つ2つのデバイスがシャットダウンすると、開始順序は逆になります。
だからあなたはあなたのものがうまくbt-mouse-suspend.service
いくと言います。Wanted-By=sleep.target
これはsleep.target
サービスの開始時に実行されます。逆にsleep.target
止まるとbt-mouse-suspend.service
止まります。このサービスにはフィールドは必要ありませんBefore
。サービスをその宛先に対する操作にしました。
したがって、/usr/bin/hciattach -s 152000 /dev/ttyS1 billionton
休暇をしたい場合。sleep.target
ExecStop
bt-mouse-suspend.service
また、これがどのように機能するかをよく読むことをお勧めしますsystemd
。つまり、次を見てください。
https://www.freedesktop.org/software/systemd/man/systemd.service.html#
https://www.freedesktop.org/software/systemd/man/systemd.unit.html#
https://www.freedesktop.org/software/systemd/man/systemd.target.html#
また、2つのサービス目標suspend.target
はとですsleep.target
。明らかに、実際に興味のあるものは何でも使うべきですが、ただsuspend.target
。