大网数据广告活动
服务器运维问答

systemd: myservice.service vs myservice.target

· 52CE 我爱测

In a systemd service definition file, what is the difference between [Unit] Description=My service... After=zookeeper.service and [Unit] Description=My service... After=zookeeper.target zookeeper is another service defined in ano…

问题原文

原帖链接 · clay · CC BY-SA 3.0

In a systemd service definition file, what is the difference between

[Unit]
Description=My service...
After=zookeeper.service

and

[Unit]
Description=My service...
After=zookeeper.target

zookeeper is another service defined in another service file, but what is the significance of the extension .service vs .target. Is there a difference?

社区高分解答

原帖链接 · fbicknel · CC BY-SA 4.0

A service:

A unit configuration file whose name ends in .service encodes information about a process controlled and supervised by systemd.

A target:

A unit configuration file whose name ends in ".target" encodes information about a target unit of systemd, which is used for grouping units and as well-known synchronization points during start-up.

These both refer to unit configuration files, which are:

A unit configuration file encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a watched file system path, a timer controlled and supervised by systemd(1), a resource management slice or a group of externally created processes.

Reference: man pages for systemd.service, systemd.target, and systemd.unit, respectively.

Also, with respect to the configuration files themselves; services need:

Service files must include a "[Service]" section, which carries information about the service and the process it supervises.

No such requirement exists for target configuration files. In fact, targets have no options specific to targets; items are configured in generic [Unit] and [Install] sections.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。