【问题标题】:Enable a systemd service at rpm installation在 rpm 安装时启用 systemd 服务
【发布时间】:2018-11-22 17:25:07
【问题描述】:

我正在尝试构建一个能够以正确方式启用 systemd 服务的 rpm 包。

在我的 rpm 规范文件中,我添加了:

%{?systemd_requires}
BuildRequires: systemd

...

%postun
%systemd_postun yeah.service

我的 rpm 副本在 /usr/lib/systemd/system/ 中的yeah.service 文件。

但是在安装包之后,服务仍然被禁用:

root@ansible-1:1:~# systemctl status yeah
Unit yeah.service could not be found.
root@ansible-1:1:~# rpm -Uvh /home/intersec/delivery/yeah.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:yeah################################# [100%]
root@ansible-1:1:~# systemctl status yeah
● yeah.service - Yeah
   Loaded: loaded (/usr/lib/systemd/system/yeah.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

怎么了?

拉乌尔

【问题讨论】:

    标签: centos7 systemd rpm-spec


    【解决方案1】:

    %postun 脚本在卸载后运行。我认为你也应该添加

    %post
    %systemd_post yeah.service
    

    【讨论】:

      【解决方案2】:

      您需要创建一个预设文件并将其安装到正确的预设目录中。那并使用systemd_*-macros 将启用您的服务(但不启动)。

      这需要添加到规范文件的%install-section。

      %{__install} -Dm644 %{name}.preset %{buildroot}%{_presetdir}/50-%{name}.preset
      

      这是一个预设文件的例子:

      enable <your-service-name>.service
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-25
        • 2020-01-20
        • 1970-01-01
        • 1970-01-01
        • 2017-02-28
        • 2016-11-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多