/usr/lib/systemd/*/*.service 和 /lib/systemd/*/*.service 之间的区别

/usr/lib/systemd/*/*.service 和 /lib/systemd/*/*.service 之间的区别

在 Debian 上,一些 systemd 服务安装到/usr/lib/systemd/*/*.service,例如:

/usr/lib/systemd/user/org.gnome.Evince.service
/usr/lib/systemd/user/pulseaudio.service
/usr/lib/systemd/user/gpg-agent.service

其他服务(实际上更多)都在/lib/systemd/*/*.service

/lib/systemd/system/networking.service
/lib/systemd/system/sddm.service
/lib/systemd/system/apache2.service
/lib/systemd/system/dm-event.service
/lib/systemd/system/ModemManager.service

有文件夹/lib/systemd

/lib/systemd/network/
/lib/systemd/system/
/lib/systemd/system-generators/
/lib/systemd/system-preset/
/lib/systemd/system-shutdown/
/lib/systemd/system-sleep/

/usr/lib/systemd

/usr/lib/systemd/boot/
/usr/lib/systemd/catalog/
/usr/lib/systemd/scripts/
/usr/lib/systemd/system/
/usr/lib/systemd/user/
/usr/lib/systemd/user-environment-generators/
/usr/lib/systemd/user-generators/
/usr/lib/systemd/user-preset/

那么,这两个目录有什么区别呢?系统文档/lib/systemd根本没有提到。

是发行版还是上游软件选择的地方?例如对于阿帕奇德班使用/lib/systemd/system/apache2.service,但是buildroot /usr/lib/systemd/system/apache.service(看起来 buildroot 也使用了/lib/systemd)。

它是否受到某种影响/usr合并

大家只关心/usr/lib/systemd/system 和 /etc/systemd/system 之间的区别触及主题显示 的路径Units of installed packages是发行版特定的 – Centos 7 使用/usr/lib/systemd/system, Debian /lib/systemd/system,但 Debian 使用这两个路径)。

答案1

消息人士回答了这个问题,它确实受到了影响/usr合并, 看LOOKUP_PATHS_SPLIT_USR

src/portable/portable.c:we force looking inside of /lib/systemd/system/ for units too, as we might be compiled for a split-usr system but the image might be a legacy-usr one

/* Then, send unit file data to the parent (or/and add it to the hashmap).
 * For that we use our usual unit discovery logic. Note that we force looking 
 * inside of /lib/systemd/system/ for units too, as we might be
 * compiled for a split-usr system but the image might be a legacy-usr one. */
r = lookup_paths_init(&paths, UNIT_FILE_SYSTEM, LOOKUP_PATHS_SPLIT_USR, where);

(评论重新格式化以提高可读性)

src/共享/路径查找.c: 添加"/lib/systemd/system"if 标志LOOKUP_PATHS_SPLIT_USR

case UNIT_FILE_SYSTEM:
   add = strv_new(
      /* If you modify this you also want to modify
       * systemdsystemunitpath= in systemd.pc.in! */
      ...
      "/usr/local/lib/systemd/system",
      SYSTEM_DATA_UNIT_PATH,
      "/usr/lib/systemd/system",
      STRV_IFNOTNULL(flags & LOOKUP_PATHS_SPLIT_USR ? "/lib/systemd/system" : NULL),
            ...

src/core/systemd.pc.in/usr/lib/systemd/system/lib/systemd/system

systemdsystemunitpath=${systemdsystemconfdir}:/etc/systemd/system:\
/run/systemd/system\:/usr/local/lib/systemd/system:${systemdsystemunitdir}\:
/usr/lib/systemd/system:/lib/systemd/system

(重新格式化以获得更好的可读性)

提交消息来自799b210267(“路径查找:添加标志以选择性地强制检查 split-usr 单元目录”)

When we look into a portable service image it might contain the unit
files in split-usr directories rather than merged-usr directories as on
the host. Hence, let#s add a flag that checking all dirs can be forced.

相关内容