デバイスを有効にできませんでした:file log.service:そのファイルまたはディレクトリはありません。

デバイスを有効にできませんでした:file log.service:そのファイルまたはディレクトリはありません。

電源が切れたり停電する前に録音したいです。

uname -a
Linux xxx 4.9.0-4-amd64 #1 SMP Debian 4.9.51-1 (2017-09-28) x86_64 GNU/Linux

systemctl get-default
graphical.target
runlevel
N 5

私のスクリプトを編集してください。

sudo vim   /etc/systemd/system/graphical.target.wants/log.service
[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/log.sh

有効にしてください。

sudo systemctl  enable  log.service
Failed to enable unit: File log.service: No such file or directory

どうすれば修正できますか?以下の設定に問題があるのでしょうか?

sudo cat   /etc/systemd/system/log.service
[Unit]
Description=Run command at shutdown
After=shutdown.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStop=/bin/bash /home/log.sh


[Install]
WantedBy=graphical.target

有効化にsudo systemctl enable log.service問題はありません。
なぜログ情報がなく、/home/log.sh 実行できないのですか?

ベストアンサー1

このディレクトリにユニットを作成しないでくださいgraphical.target.wants。これはシンボリックリンクに使用されます。代わりにディレクトリに直接作成してください/etc/systemd/system

[Install]また、このコマンドを使用するときにインストールする場所を説明するセクションも必要です。systemctl enable(あなたの場合はを使うことができますgraphical.targetmulti-user.targetもっと一般的なオプションであり、依存関係なので、graphical.target起動時に取得します。)

そのため、以下で作成してください/etc/systemd/system/log.service

[Unit]
Description=...

[Service]
...
ExecStop=/bin/bash /home/log.sh

[Install]
WantedBy=multi-user.target

次に、次を使用して有効にします。

$ sudo systemctl enable log.service

これでこれが機能します。

依存関係が正しくない可能性があります。持っているが実行する必要があるサービスの依存関係をBefore=shutdown.target reboot.target使用する可能性が高いです。After=今後彼らはブロックされました。依存関係は終了時に逆の順序で機能するため、このセクションに依存する項目をリストします(例えば、、local-fs.target)。 log.shを実行するにはファイルシステムをインストールする必要があるため、この手順は興味深いかもしれません。network.targetAfter=RequiresMountsFor=

おすすめ記事