我创建了一个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
也是如此。