起動操作をシステムサービスに変換するには?

起動操作をシステムサービスに変換するには?

私は次のスタートアップを運営しています。

# hwclock - adjust system clock and timezone
#
# The hwclock task adjusts the system clock when the hardware clock is
# set to localtime (e.g. when dual-booting with Windows), and also
# ensures that the system timezone is set so that timestamps are written
# to FAT devices.

description     "adjust system clock and timezone"

start on starting mountall

task

script
    exec hwclock --systz --utc --noadjfile
end script

systemdサービスに切り替えたいです。

systemdではどのように実装する必要がありますかstart on starting mountall

以下のようにsystemdサービスを作成しましたが、どうすればよいかわかりませんstart on starting mountall

[Unit]
Description=hwclock
After=
Before=

[Service]
ExecStart=/sbin/hwclock --systz --utc --noadjfile

ベストアンサー1

次の行が必要です。

Requires=
After=

ここで指定されているように:

Requires=: このディレクティブは、このデバイスが本質的に依存するすべてのデバイスをリストします。現在のデバイスがすでに有効になっている場合は、ここに記載されているデバイスも正常に有効にする必要があります。それ以外の場合、デバイスは失敗します。デフォルトでは、これらのデバイスは現在のデバイスと並列に起動されます。

After=: このディレクティブにリストされているデバイスは、現在のデバイスが起動する前に起動されます。これは、必要に応じて上記のディレクティブを介して設定する必要がある依存関係を意味しません。

構造は次のようになります。

[Unit]
Description=hwclock
Requires= # mountall most happen
After= # mountall should have started before hwclock run

[Service]
Type=oneshort
ExecStart=/sbin/hwclock --systz --utc --noadjfile

~からここ:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Upstart stanza | systemd unit file directive | systemd unit file section
               |                             |
-------------------------------------------------------------------------
start on       |    Wants, Requires, Before, |
               |    After                    |  Unit 
--------------------------------------------------------------------------

注:これはUbuntuシステム用ですが、類似している必要があります。望むより:https://www.freedesktop.org/software/systemd/man/systemd.unit.html返品。

おすすめ記事