Systemd Spec 宏

spec文件中这几个宏是systemd提供的一些方便使用的宏: 

%post
%systemd_post xxxxxxxx.service       //安装后触发


%preun
%systemd_preun xxxxxxxx.service      //卸载前触发


%postun
%systemd_postun_with_restart xxxxxxxx.service      //如果升级需要重启
%systemd_postun    xxxxxxxx.service      //如果升级不需要重启

宏具体细节:

#按照预设文件(*.preset)的指示,重置指定单元的启用(enable)/停用(disable)状态。

%systemd_post() \

if [ $1 -eq 1 ] ; then \

        # Initial installation \

        systemctl preset %{?*} >/dev/null 2>&1 || : \  #其效果等价于按照预设规则,对列出的单元依次使用 disable 或 enable 命令                               

fi \

%{nil}
-------------------------------------------
%systemd_preun() \

if [ $1 -eq 0 ] ; then \

        # Package removal, not upgrade \

        systemctl --no-reload disable %{?*} > /dev/null 2>&1 || : \  #执行disable即不开机自启动,并且不自动加载配置(.service文件),也就是不自动执行daemon-load命令。
  
        systemctl stop %{?*} > /dev/null 2>&1 || : \                  

fi \

%{nil}
------------------------------------------
#重新加载 systemd 守护进程的配置。
%systemd_postun() \

systemctl daemon-reload >/dev/null 2>&1 || : \   #重新加载所有单元文件,即.service文件             

%{nil}
------------------------------------------
#重新启动(先停止再启动)指定的已启动单元。 

%systemd_postun_with_restart() \

systemctl daemon-reload >/dev/null 2>&1 || : \ 

if [ $1 -ge 1 ] ; then \

        # Package upgrade, not uninstall \

        systemctl try-restart %{?*} >/dev/null 2>&1 || : \   #注意,若指定的单元尚未启动,则不做任何操作。             

fi \

%{nil}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值