Why is %systemd_post, used in the spec-file, not enabling or starting the service after installation?

Viewed 2193

I'm having a very simple unit-file which comes with a service which I package to a RPM-file. This RPM-file is built and installed on Fedora 28.

My service-file could not be simpler:

[Unit]
Description=Hello Work

[Service]
ExecStart=/usr/bin/executable

[Install]
WantedBy=multi-user.target

In my spec file I added these sections:

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service

The service file is copied correctly via

mkdir -p %{buildroot}%{_unitdir}/
cp %{name}.service %{buildroot}%{_unitdir}/

in the %install-section.

When I install the package, the service is not started. When I run manually

systemctl enable <service-name>

it works.

Where is my mistake that the installation does not enable and start my service?

1 Answers

When looking at the documentation, it does not say that %systemd_post starts your service. They refer to systemd.preset: you need to define and package a %{name}.preset file that specifies that your service should be enabled by default.

This should enable your package by default.

I'm not entirely sure that now your package will be started by default, but it looks like it :)

Related