我已经创建了一个 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
最佳答案
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
也是一样的。
关于linux - RPM SPEC Systemd 启用并启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55378760/