[Fedora-packaging] Systemd scriptlet comments

Ville Skyttä ville.skytta at iki.fi
Tue Jul 19 22:24:14 UTC 2011


On 06/22/2011 07:24 PM, Toshio Kuratomi wrote:

> We discussed this when we came up with the guidelines.  IIRC, we finally
> decided this wasn't workable because we don't prevent people from packaging
> systemVinit scripts (either in subpackages or in a wholly separate package.
> 
> I agree with your points about fragility, though.  If you can think of a way
> that handles both I'd be happy to hear it.

Regarding the above, I don't think trying to chase "someone might do
something" at the expense of making regular package maintenance harder
or knowingly break at least to some extent is a good approach.

Anyway, here's a couple of new thoughts:

First, daemons are usually restarted on upgrade after the old package
has been removed, so if this is desirable and the trigger approach is
used, the try-restart should be done in %triggerpostun instead of
%triggerun, no?

Second, one way to ensure that the EVR of the package in the distro
version that had the sysv scripts stays older than the one in which
systemd migration happens even if the old distro version gets version
updates is to bump Epoch when doing the migration, and take advantage of
that in the versioned trigger.

Third, for my test case where the old package does its try-restart with
"service" instead of invoking the init script directly, this appears to
work fine:

    %pre
    if [ $1 -gt 1 ] && [ ! -e %{_unitdir}/FOO.service ] && \
       [ -e %{_initddir}/FOO ] ; then
        systemd-sysv-convert --save FOO &>/dev/null
        chkconfig --del FOO &>/dev/null || :
    fi

    %post
    systemctl daemon-reload &>/dev/null || :

    %preun
    if [ $1 -eq 0 ] ; then
        systemctl --no-reload disable FOO.service &>/dev/null
        systemctl stop FOO.service &>/dev/null || :
    fi

    %postun
    systemctl daemon-reload &>/dev/null
    [ $1 -gt 0 ] && systemctl try-restart FOO.service &>/dev/null || :

I believe the conditions in %pre should prevent it from doing bad things
(only when upgrading the package, and only if the sysv script is around
but the unit file isn't yet).  Note that daemon-reload is done in %post
also for upgrades so that the "service FOO try-restart" in the old
package's %postun will do the right thing.  Note also no need for
triggers in this scenario.

If the old package's %postun invokes the sysv init script directly,
getting the daemon restarted gets uglier but using a temp file (for
example
%{_var}/run/%{name}-%{version}-%{release}-%{arch}.systemd-migration,
referred to as %{migrfile} below), something like this works in my tests:

    %pre
    rm -f %{migrfile} &>/dev/null
    if [ $1 -gt 1 ] && [ ! -e %{_unitdir}/FOO.service ] && \
       [ -e %{_initddir}/FOO ] ; then
        systemd-sysv-convert --save FOO &>/dev/null
        chkconfig --del FOO &>/dev/null
        touch %{migrfile} &>/dev/null
    fi
    exit 0

    %post
    [ $1 -eq 1 ] && systemctl daemon-reload &>/dev/null || :

    %preun
    if [ $1 -eq 0 ] ; then
        systemctl --no-reload disable FOO.service &>/dev/null
        systemctl stop FOO.service &>/dev/null || :
    fi

    %postun
    systemctl daemon-reload &>/dev/null
    [ $1 -gt 0 ] && systemctl try-restart FOO.service &>/dev/null || :

    %triggerpostun -- %{name}
    if [ $1 -gt 0 ] && [ -e %{migrfile} ] ; then
        systemctl daemon-reload &>/dev/null
        systemctl try-restart FOO.service &>/dev/null
    fi
    rm -f %{migrfile} &>/dev/null || :


More information about the packaging mailing list