From Fedora Project Wiki
(Add subpackage stuff) |
(Cut and past hack and slash. New section now should pass) |
||
Line 56: | Line 56: | ||
<pre> | <pre> | ||
% | %post | ||
/ | if [ $1 -eq 1 ] ; then | ||
# Initial installation | |||
# If a package is allowed to autostart: | |||
/bin/systemctl enable httpd.service >/dev/null 2>&1 || : | |||
# No autostart: | |||
# /bin/systemctl daemon-reload >/dev/null 2>&1 || : | |||
fi | |||
%preun | |||
if [ $1 -eq 0 ] ; then | |||
# Package removal, not upgrade | |||
/bin/systemctl --no-reload disable httpd.service > /dev/null 2>&1 || : | |||
/bin/systemctl stop httpd.service > /dev/null 2>&1 || : | |||
fi | |||
%postun | |||
/bin/systemctl daemon-reload >/dev/null 2>&1 || : | |||
if [ $1 -ge 1 ] ; then | |||
# Package upgrade, not uninstall | |||
/bin/systemctl try-restart httpd.service >/dev/null 2>&1 || : | |||
fi | |||
# Note: the NEVR in trigger scripts should all be the version in | |||
# which the package switched to systemd unit files and the comparision | |||
# should be less than. Using <= the last version with the sysV script won't | |||
# work for several reasons: | |||
# 1) disttag is different between Fedora releases | |||
# 2) An update in an old Fedora release may create a newer NEVR | |||
%triggerun -- httpd < 1.0-2 | |||
if chkconfig --level --no-redirect 1 foo ; then | if chkconfig --level --no-redirect 1 foo ; then | ||
ln -sf /lib/systemd/system/foo.service /etc/systemd/system/rescue.target.wants/ 2>&1 >/dev/null | ln -sf /lib/systemd/system/foo.service /etc/systemd/system/rescue.target.wants/ 2>&1 >/dev/null | ||
Line 81: | Line 110: | ||
fi | fi | ||
fi | fi | ||
# Run these because the SysV package being removed won't do it | |||
/bin/systemctl try-restart httpd.service >/dev/null 2>&1 || : | |||
# Run this because the chkconfig --del in the SysV providing package won't | |||
# fire unless the package is removed | |||
/sbin/chkconfig --del httpd >/dev/null 2>&1 || : | |||
/bin/systemctl daemon-reload >/dev/null 2>&1 || : | /bin/systemctl daemon-reload >/dev/null 2>&1 || : | ||
# If we're shipping sysvinit scripts | |||
%triggerpostun -n httpd-sysvinit -- httpd < 1.0-2 | |||
/sbin/chkconfig --add httpd >/dev/null 2>&1 || : | |||
</pre> | </pre> |
Revision as of 21:56, 8 March 2011
There are two options for scriptlets depending on whether we should care about user configuration of what services start in the past.
Start over fresh
%post if [ $1 -eq 1 ] ; then # Initial installation # If a package is allowed to autostart: /bin/systemctl enable httpd.service >/dev/null 2>&1 || : # No autostart: # /bin/systemctl daemon-reload >/dev/null 2>&1 || : fi %preun if [ $1 -eq 0 ] ; then # Package removal, not upgrade /bin/systemctl --no-reload disable httpd.service > /dev/null 2>&1 || : /bin/systemctl stop httpd.service > /dev/null 2>&1 || : fi %postun /bin/systemctl daemon-reload >/dev/null 2>&1 || : if [ $1 -ge 1 ] ; then # Package upgrade, not uninstall /bin/systemctl try-restart httpd.service >/dev/null 2>&1 || : fi # Note: the NEVR in trigger scripts should all be the version in # which the package switched to systemd unit files and the comparision # should be less than. Using <= the last version with the sysV script won't # work for several reasons: # 1) disttag is different between Fedora releases # 2) An update in an old Fedora release may create a newer NEVR %triggerun -- httpd < 1.0-2 # Run this because the chkconfig --del in the SysV providing package won't # fire unless the package is removed /sbin/chkconfig --del httpd >/dev/null 2>&1 || : # If the package is allowed to autostart: /bin/systemctl enable httpd.service >/dev/null 2>&1 # Run these because the SysV package being removed won't do it /bin/systemctl try-restart httpd.service >/dev/null 2>&1 || : /bin/systemctl daemon-reload >/dev/null 2>&1 || : # If we're shipping sysvinit scripts %triggerpostun -n httpd-sysvinit -- httpd < 1.0-2 /sbin/chkconfig --add httpd >/dev/null 2>&1 || :
Be sure to test that the try-restart in the trigger restarts the daemon if it was running in a former sysv package and also does not enable a daemon if it wasn't running.
Preserve user defaults
%post if [ $1 -eq 1 ] ; then # Initial installation # If a package is allowed to autostart: /bin/systemctl enable httpd.service >/dev/null 2>&1 || : # No autostart: # /bin/systemctl daemon-reload >/dev/null 2>&1 || : fi %preun if [ $1 -eq 0 ] ; then # Package removal, not upgrade /bin/systemctl --no-reload disable httpd.service > /dev/null 2>&1 || : /bin/systemctl stop httpd.service > /dev/null 2>&1 || : fi %postun /bin/systemctl daemon-reload >/dev/null 2>&1 || : if [ $1 -ge 1 ] ; then # Package upgrade, not uninstall /bin/systemctl try-restart httpd.service >/dev/null 2>&1 || : fi # Note: the NEVR in trigger scripts should all be the version in # which the package switched to systemd unit files and the comparision # should be less than. Using <= the last version with the sysV script won't # work for several reasons: # 1) disttag is different between Fedora releases # 2) An update in an old Fedora release may create a newer NEVR %triggerun -- httpd < 1.0-2 if chkconfig --level --no-redirect 1 foo ; then ln -sf /lib/systemd/system/foo.service /etc/systemd/system/rescue.target.wants/ 2>&1 >/dev/null multiuser=0 if chkconfig --level 3 foo; then ln -sf /lib/systemd/system/foo.service /etc/systemd/system/multi-user.target.wants/ 2>&1 >/dev/null multiuser=1 fi if chkconfig --level 5 foo; then # If it's already in multi-user, it will be inherited automatically if [ $multiuser -eq 0 ] ; then ln -sf /lib/systemd/system/foo.service /etc/systemd/system/graphical.target.wants/ 2>&1 >/dev/null fi else if [ $multiuser -eq 1 ] ; then # We have the option of disabling the service in graphical here to # match what the user explicitly customized their system to like # this: ln -sf /dev/null /etc/systemd/system/graphical.target.wants/foo.service # But we could also decide that this is not something that we're going # to migrate (as systemd itself sets graphical up as a strict # superset of multi-user). fi fi # Run these because the SysV package being removed won't do it /bin/systemctl try-restart httpd.service >/dev/null 2>&1 || : # Run this because the chkconfig --del in the SysV providing package won't # fire unless the package is removed /sbin/chkconfig --del httpd >/dev/null 2>&1 || : /bin/systemctl daemon-reload >/dev/null 2>&1 || : # If we're shipping sysvinit scripts %triggerpostun -n httpd-sysvinit -- httpd < 1.0-2 /sbin/chkconfig --add httpd >/dev/null 2>&1 || :