From Fedora Project Wiki
No edit summary
(Rewrite for new guidelines)
Line 1: Line 1:
There are two options for scriptlets depending on whether we should care about user configuration of what services start in the past.
When updating from a systemV to a systemd package, we "start-over fresh" with default start and stop policy from the package, not what the user had previously configured.  systemd provides a tool, <code>systemd-sysv-convert --apply</code>, to help do this conversion if the user wants after the package is updated.
 
Scriptlets:


== Start over fresh ==
== Start over fresh ==
<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
# This is actually needed for the %triggerun script but Requires(triggerun)
if [ $1 -eq 0 ] ; then
# is not valid.  We can use %post because this particular %triggerun script
    # Package removal, not upgrade
# should fire just after this package is installed.
    /bin/systemctl --no-reload disable httpd.service > /dev/null 2>&1 || :
Requires(post): systemd-sysv
    /bin/systemctl stop httpd.service > /dev/null 2>&1 || :
fi


%postun
### A sysv => systemd migration contains all of the same scriptlets as a
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
### systemd package. These are additional scriptlets
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
# Note: the NEVR in trigger scripts should all be the version in
Line 39: Line 27:
%triggerun -- httpd < 1.0-2
%triggerun -- httpd < 1.0-2
# Save the current service runlevel info
# Save the current service runlevel info
# User must manually run sysv2systemd --restore httpd to migrate them to systemd targets
# User must manually run systemd-sysv-convert --apply httpd
/bin/sysv2systemd --save httpd
# to migrate them to systemd targets
/usr/bin/systemd-sysv-convert --save httpd


# If the package is allowed to autostart:
# If the package is allowed to autostart:
/bin/systemctl enable httpd.service >/dev/null 2>&1
/bin/systemctl enable apache-httpd.service >/dev/null 2>&1


# Run these because the SysV package being removed won't do them
# Run these because the SysV package being removed won't do them
/sbin/chkconfig --del httpd >/dev/null 2>&1 || :
/sbin/chkconfig --del httpd >/dev/null 2>&1 || :
/bin/systemctl try-restart httpd.service >/dev/null 2>&1 || :
/bin/systemctl try-restart apache-httpd.service >/dev/null 2>&1 || :
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
/bin/systemctl daemon-reload >/dev/null 2>&1 || :


Line 54: Line 43:
%triggerpostun -n httpd-sysvinit -- httpd < 1.0-2
%triggerpostun -n httpd-sysvinit -- httpd < 1.0-2
/sbin/chkconfig --add httpd >/dev/null 2>&1 || :
/sbin/chkconfig --add httpd >/dev/null 2>&1 || :
</pre>
{{admon/question|sysv2systemd|Someone needs to write this tool.  We think that Lennart might be willing but we'll need to verify}}
== Preserve user defaults ==
<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
    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
      # Note: we don't have to do this; it says that if the user ran something in 3 but
      # disabled it in 5 then we don't want it to run in graphical.target.  It's a
      # literal translation
      ln -sf /dev/null /etc/systemd/system/graphical.target.wants/foo.service
    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 || :
</pre>
</pre>


{{admon/question||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.  For other test cases, see my notes on the many variants that we have to test here: https://fedoraproject.org/wiki/User:Toshio/Testing_systemd}}
{{admon/question||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.  For other test cases, see my notes on the many variants that we have to test here: https://fedoraproject.org/wiki/User:Toshio/Testing_systemd}}

Revision as of 17:20, 6 April 2011

When updating from a systemV to a systemd package, we "start-over fresh" with default start and stop policy from the package, not what the user had previously configured. systemd provides a tool, systemd-sysv-convert --apply, to help do this conversion if the user wants after the package is updated.

Scriptlets:

Start over fresh


# This is actually needed for the %triggerun script but Requires(triggerun)
# is not valid.  We can use %post because this particular %triggerun script
# should fire just after this package is installed.
Requires(post): systemd-sysv

### A sysv => systemd migration contains all of the same scriptlets as a
### systemd package.  These are additional scriptlets

# 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
#    Note that this means an update in an older Fedora release must be NEVR
#    lower than this.  Freezing the version and release of the old package and
#    using a number after the disttag is one way to do this.  Example:
#        httpd-1.0-1%{?dist} => httpd-1.0-1%{?dist}.1

%triggerun -- httpd < 1.0-2
# Save the current service runlevel info
# User must manually run systemd-sysv-convert --apply httpd
# to migrate them to systemd targets
/usr/bin/systemd-sysv-convert --save httpd

# If the package is allowed to autostart:
/bin/systemctl enable apache-httpd.service >/dev/null 2>&1

# Run these because the SysV package being removed won't do them
/sbin/chkconfig --del httpd >/dev/null 2>&1 || :
/bin/systemctl try-restart apache-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 || :
Questionmark.png
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. For other test cases, see my notes on the many variants that we have to test here: https://fedoraproject.org/wiki/User:Toshio/Testing_systemd