【发布时间】:2019-03-27 13:45:42
【问题描述】:
我已经创建了一个 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
【问题讨论】: