systemd vs. SysV init script in .spec files for new packages

Nico Kadel-Garcia nkadel at gmail.com
Sat Feb 23 13:13:31 UTC 2013


Good morning, folks:

I've been publishing a few packages for Repoforge and sent occasional
updates to EPEL, and I'd be happy to start getting them into Fedora.
While I work out how koji works, I note that the new use of systemd
means that the same SRPM cannot be used for both Fedora 18, and for
anything that runs a daemon and should be ported to EPEL.

I'm happy to write tools that use init scripts, or systemd scripts,
based on OS version. But are there best practices? Is anyone else
actually testing the code on RHEL or CentOS for cross compatibility,
to ease EPEL work and backporting to RHEL releases?

There's an example in my working backport of Samba 4.0.3 to RHEL 6, at

          https://github.com/nkadel/samba-4.0.3-srpm/blob/master/samba.spec

The critical code, lifted from the current samba-4.03 package and tweaked, is:

    # Use systemd, not SysV init scripts, as appropriate
    %if 0%{?fedora} > 15 || 0%{?rhel} > 6
    %global with_systemd 1
    %else
    %global with_systemd 0
    %endif

I've also noticed that the use of the "rhel" macro can be a bit
confusing, since it's only been a standard part of RPM setups since
RHEL 6. For older releases such as RHEL 5, it's apparently built into
koji, but needs te be set for individual developers or software build
environments in $HOME/.rpmmacros otherwise. That's not critical for
recent Fedora releases, but may affect people like me who try to
backport tools from Fedora 18 or Fedora 19 to older systems.

Also note that the with_systemd macro *must* be defined as 0 for false
values, or later uses of  this syntax fail miserably on older
operating systems, like RHEL 6.

    %if %with_systemd
    Requires(post): systemd
    Requires(preun): systemd
    Requires(postun): systemd
    %else
    Requires(post): /sbin/chkconfig, /sbin/service
    Requires(preun): /sbin/chkconfig, /sbin/service
    Requires(postun): /sbin/chkconfig, /sbin/service
    %endif

Frankly, I'd prefer to use "%if 0%{with_systemd}", but that's a
syntactic choice I can work with either way. I just want to set and
follow a spec.

That's just an example: the full backport is at
https://github.com/nkadel/samba-4.0.3-srpm/


More information about the devel mailing list