RPM SPEC Systemd启用和启动

问题描述 投票:0回答:1

我创建了一个RPM SPEC文件,但我正在努力使用Systemd启用和启动。通过yum更新程序包会禁用并停止服务。分布是Centos 7.x.

我在/ etc / systemd / system下安装了该服务。这是我试过的,但它不起作用。

我还没有找到任何有关如何做到这一点的好工作示例。

我用这个页面作为参考。 https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax

    #Pre installation/upgrade of RPM section
    %pre      
      #Upgrading
      if [ $1 -eq 2 ]; then
        /usr/bin/systemctl stop %{pkgname}.service >/dev/null 2>&1 ||:
      fi

    %post
    %systemd_post %{pkgname}.service

      if [ $1 -eq 1 ]; then        
        /usr/bin/systemctl daemon-reload
        /usr/bin/systemctl start %{pkgname}.service
      fi
      if [ $1 -eq 2 ]; then
        /usr/bin/systemctl daemon-reload
        /usr/bin/systemctl start %{pkgname}.service    
      fi

   %preun
   %systemd_preun %{pkgname}.service
    #old package
    #uninstall
    if [ $1 -eq 0 ]; then
      /usr/bin/systemctl --no-reload disable %{pkgname}.service
      /usr/bin/systemctl stop %{pkgname}.service >/dev/null 2>&1 ||:
      /usr/bin/systemctl disable %{pkgname}.service

    fi
    if [ $1 -eq 1 ]; then
      /usr/bin/systemctl --no-reload disable %{pkgname}.service
      /usr/bin/systemctl stop %{pkgname}.service
    fi
linux centos7 rpm
1个回答
2
投票

1)%{pkgname}.service应该放在%{_unitdir},扩展到/usr/lib/systemd/system/

2)当你使用%systemd_post %{pkgname}.service宏时,没有必要在那里:

  if [ $1 -eq 1 ]; then        
    /usr/bin/systemctl daemon-reload
    /usr/bin/systemctl start %{pkgname}.service
  fi
  if [ $1 -eq 2 ]; then
    /usr/bin/systemctl daemon-reload
    /usr/bin/systemctl start %{pkgname}.service    
  fi

%pre%preun也是如此。

© www.soinside.com 2019 - 2024. All rights reserved.