首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将新建作业转换为systemd服务?

如何将新建作业转换为systemd服务?
EN

Unix & Linux用户
提问于 2018-01-22 05:09:10
回答 1查看 1K关注 0票数 1

我有以下的新贵工作:

代码语言:javascript
复制
# 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

代码语言:javascript
复制
[Unit]
Description=hwclock
After=
Before=

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

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-01-22 06:31:17

您将需要以下几行:

代码语言:javascript
复制
Requires=
After=

如下文所述:

Requires=:此指令列出了该单元本质上依赖的任何单元。如果当前单元被激活,这里列出的单元也必须成功激活,否则此单元将失败。默认情况下,这些单元与当前单元并行启动。After=:本指令中列出的单元将在启动当前单元之前启动。这并不意味着依赖关系,如果需要,必须通过上述指令建立依赖关系。

其结构应是:

代码语言:javascript
复制
[Unit]
Description=hwclock
Requires= # mountall most happen
After= # mountall should have started before hwclock run

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

来自这里

代码语言:javascript
复制
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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

票数 1
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/418749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档