Systemd RequiredBy diretiva é ignorada

1

Este é o meu arquivo de serviço:

[Unit]
Description=Blabla service
Requires=network-online.target nfs-common.service
After=network-online.target nfs-common.service

[Service]
Type=oneshot
ExecStart=/path/to/script
RemainAfterExit=no

[Install]
RequiredBy=php5-fpm.service apache2.service nginx.service

Ao ativar, parece promissor:

# systemctl enable blabla.service 
Created symlink from /etc/systemd/system/php5-fpm.service.requires/blabla.service to /etc/systemd/system/blabla.service.
Created symlink from /etc/systemd/system/apache2.service.requires/blabla.service to /etc/systemd/system/blabla.service.
Created symlink from /etc/systemd/system/nginx.service.requires/blabla.service to /etc/systemd/system/blabla.service.

Em seguida, após o reinício, systemd-analyze me fornece o seguinte:

# systemd-analyze blame
         18.434s blabla.service
          5.942s cloud-init.service
          2.766s networking.service
          1.671s apache2.service
          1.398s cloud-init-local.service
          1.276s newrelic-sysmond.service
           856ms php5-fpm.service
           586ms nginx.service
           .....

De acordo com os documentos Type=oneshot :

Behavior of oneshot is similar to simple; however, it is expected that the process has to exit before systemd starts follow-up units.

Alguma idéia?

    
por NarūnasK 07.03.2017 / 18:20

1 resposta

2

RequiredBy= não implica que um serviço deva iniciar após o outro.

Em man systemd.unit , os documentos para RequiredBy= dizem:

The primary result is that the current unit will be started when the listed unit is started.

Em outras palavras, eles podem acabar em paralelo. Eu acho que você quer uma diretiva Before= na sua seção de instalação. Os documentos em man systemd.unit têm isto a dizer sobre Before= :

If a unit foo.service contains a setting Before=bar.service and both units are being started, bar.service's start-up is delayed until foo.service is started up. Note that this setting is independent of and orthogonal to the requirement dependencies as configured by Requires=.

    
por 07.03.2017 / 18:51