如何将 upstart 作业转换为 systemd 服务?

如何将 upstart 作业转换为 systemd 服务?

我有以下新贵工作:

# 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还。

相关内容