Debian 9またはRaspbian 8で終了時にスクリプトを実行する方法(Jessie)

Debian 9またはRaspbian 8で終了時にスクリプトを実行する方法(Jessie)

再起動と終了時に次のシェルスクリプトを実行したいと思います。

#!/bin/sh
touch /test

権限は次のとおりです。

-rwxr-xr-x 1 root root 22 Feb 24 09:34 /etc/init.d/te1

このリンクがあります。

/etc/rc0.d/K01te1 -> ../init.d/te1
/etc/rc6.d/K01te1 -> ../init.d/te1

このリンクがあると、起動時に機能します。

/etc/rc5.d/S01te1 -> ../init.d/te1

ただし、終了時に実行する必要があります。

Debian 8と9のテストでこれをどのように実行しますか?

これ提案 touch /var/lock/subsys/te1役に立たない。

ベストアンサー1

私の考えでは、他の人もこのプログラムを実行するのに問題があるようです。 systemdはDebian 8.0(Jessie)以降、System V initとの互換性が損なわれているようです。

だからここsystemd サービスを作成することをお勧めします。解決策はここで使用してください次のようになります。

[Unit]
Description=The te1 script

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/usr/local/bin/te1

[Install]
WantedBy=multi-user.target

systemdサービス/lib/systemd/system/te1.servicesudo systemctl enable te1

おすすめ記事