Назад | Перейти на главную страницу

Перезапуск модуля systemd распространяется как 2 перезапуска в зависимом модуле

На моем сервере работает NixOS, У меня есть 2 модуля systemd со следующей конфигурацией.

systemd.services.myservice = {

  serviceConfig = {

    Type = "oneshot";

    ExecStart = ''
      ${pkgs.bash}/bin/bash -c 'echo "Hello World!"'
    '';
  };
};

systemd.services.mytrigger = {

  wantedBy = [
    "multi-user.target"
  ];
  wants = [
    "myservice.service"
  ];
  before = [
    "myservice.service"
  ];

  serviceConfig = {

    Type = "simple";

    ExecStartPre = "${pkgs.bash}/bin/bash -c 'sleep 10'";
    ExecStart = "${pkgs.bash}/bin/bash -c 'sleep 49'";

    TimeoutStartSec = "infinity";
    Restart = "always";
    RestartSec = "1000ms";
  };
};

Эта конфигурация nix преобразуется в следующие файлы vanilla systemd:

[root@myhost:~]# systemctl cat myservice.service
# /nix/store/ppa40x440i4357g7wdxwl3nnffay65xq-unit-myservice.service/myservice.service
[Unit]

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/da0h55nhsipysryz9zcb9i7chbqffa45-glibc-locales-2.30/lib/locale/locale-archive"
Environment="PATH=/nix/store/sn2fzbavnsb9sfff39ylkd6njfmh9gif-coreutils-8.31/bin:/nix/store/0c9izfknmjqgxwlnszi35ps5ds35yfi1-findutils-4.7.0/bin:/nix/store/g9317haqh75hj5x05yq6na2y21xcl2a5-gnugrep-3.4/bin:/nix/store/r540lhrdmgzccx3q6s55w08bikj7z5lr-gnused-4.8/bin:/nix/store/dmw42i5sp8wj7pwrp5fq6z78d37c160i-systemd-243.4/bin:/nix/store/sn2fzbavnsb9sfff39ylkd6njfmh9gif-coreutils-8.31/sbin:/nix/store/0c9izfknmjqgxwlnszi35ps5ds35yfi1-findutils-4.7.0/sbin:/nix/store/g9317haqh75hj5x05yq6na2y21xcl2a5-gnugrep-3.4/sbin:/nix/store/r540lhrdmgzccx3q6s55w08bikj7z5lr-gnused-4.8/sbin:/nix/store/dmw42i5sp8wj7pwrp5fq6z78d37c160i-systemd-243.4/sbin"
Environment="TZDIR=/nix/store/rqzv14x4jnw5025n6r2chr6ar8wadr8g-tzdata-2019c/share/zoneinfo"



ExecStart=/nix/store/1iaxkm0941nj1m4m5g4fxgg4cq5jckf0-bash-4.4-p23/bin/bash -c 'echo "Hello World!"'

Type=oneshot


[root@myhost:~]# systemctl cat mytrigger.service
# /nix/store/bpwnlpisnl8k6zc9r0nlgxbw8aynnp52-unit-mytrigger.service/mytrigger.service
[Unit]
Before=myservice.service
Wants=myservice.service

[Service]
Environment="LOCALE_ARCHIVE=/nix/store/da0h55nhsipysryz9zcb9i7chbqffa45-glibc-locales-2.30/lib/locale/locale-archive"
Environment="PATH=/nix/store/sn2fzbavnsb9sfff39ylkd6njfmh9gif-coreutils-8.31/bin:/nix/store/0c9izfknmjqgxwlnszi35ps5ds35yfi1-findutils-4.7.0/bin:/nix/store/g9317haqh75hj5x05yq6na2y21xcl2a5-gnugrep-3.4/bin:/nix/store/r540lhrdmgzccx3q6s55w08bikj7z5lr-gnused-4.8/bin:/nix/store/dmw42i5sp8wj7pwrp5fq6z78d37c160i-systemd-243.4/bin:/nix/store/sn2fzbavnsb9sfff39ylkd6njfmh9gif-coreutils-8.31/sbin:/nix/store/0c9izfknmjqgxwlnszi35ps5ds35yfi1-findutils-4.7.0/sbin:/nix/store/g9317haqh75hj5x05yq6na2y21xcl2a5-gnugrep-3.4/sbin:/nix/store/r540lhrdmgzccx3q6s55w08bikj7z5lr-gnused-4.8/sbin:/nix/store/dmw42i5sp8wj7pwrp5fq6z78d37c160i-systemd-243.4/sbin"
Environment="TZDIR=/nix/store/rqzv14x4jnw5025n6r2chr6ar8wadr8g-tzdata-2019c/share/zoneinfo"



ExecStart=/nix/store/1iaxkm0941nj1m4m5g4fxgg4cq5jckf0-bash-4.4-p23/bin/bash -c 'sleep 49'
ExecStartPre=/nix/store/1iaxkm0941nj1m4m5g4fxgg4cq5jckf0-bash-4.4-p23/bin/bash -c 'sleep 10'
Restart=always
RestartSec=1000ms
TimeoutStartSec=infinity
Type=simple


При загрузке этой конфигурации nix я заметил, что myservice.service перезапускается в два раза чаще, чем mytrigger.service.

[root@myhost:~]# journalctl -u mytrigger.service -u myservice.service -f -o short-precise
-- Logs begin at Wed 2020-03-04 17:39:45 UTC. --
Mar 31 15:41:16.625846 myhost systemd[1]: Started myservice.service.
Mar 31 15:41:17.836871 myhost systemd[1]: mytrigger.service: Service RestartSec=1s expired, scheduling restart.
Mar 31 15:41:17.837192 myhost systemd[1]: mytrigger.service: Scheduled restart job, restart counter is at 9.
Mar 31 15:41:17.837347 myhost systemd[1]: Stopped mytrigger.service.
Mar 31 15:41:17.838937 myhost systemd[1]: Starting mytrigger.service...
Mar 31 15:41:27.847191 myhost systemd[1]: Started mytrigger.service.
Mar 31 15:41:27.849825 myhost systemd[1]: Starting myservice.service...
Mar 31 15:41:27.860250 myhost bash[79223]: Hello World!
Mar 31 15:41:27.861138 myhost systemd[1]: myservice.service: Succeeded.
Mar 31 15:41:27.861591 myhost systemd[1]: Started myservice.service.
Mar 31 15:42:16.866778 myhost systemd[1]: mytrigger.service: Succeeded.
Mar 31 15:42:16.879803 myhost systemd[1]: Starting myservice.service...
Mar 31 15:42:16.887882 myhost bash[79389]: Hello World!
Mar 31 15:42:16.890526 myhost systemd[1]: myservice.service: Succeeded.
Mar 31 15:42:16.896644 myhost systemd[1]: Started myservice.service.
Mar 31 15:42:18.085273 myhost systemd[1]: mytrigger.service: Service RestartSec=1s expired, scheduling restart.
Mar 31 15:42:18.085657 myhost systemd[1]: mytrigger.service: Scheduled restart job, restart counter is at 10.
Mar 31 15:42:18.085847 myhost systemd[1]: Stopped mytrigger.service.
Mar 31 15:42:18.088149 myhost systemd[1]: Starting mytrigger.service...
Mar 31 15:42:28.097262 myhost systemd[1]: Started mytrigger.service.
Mar 31 15:42:28.103553 myhost systemd[1]: Starting myservice.service...
Mar 31 15:42:28.108918 myhost bash[79445]: Hello World!
Mar 31 15:42:28.109510 myhost systemd[1]: myservice.service: Succeeded.
Mar 31 15:42:28.109922 myhost systemd[1]: Started myservice.service.
Mar 31 15:43:17.116481 myhost systemd[1]: mytrigger.service: Succeeded.
Mar 31 15:43:17.121255 myhost systemd[1]: Starting myservice.service...
Mar 31 15:43:17.125727 myhost bash[79578]: Hello World!
Mar 31 15:43:17.126454 myhost systemd[1]: myservice.service: Succeeded.
Mar 31 15:43:17.126910 myhost systemd[1]: Started myservice.service.
Mar 31 15:43:18.333741 myhost systemd[1]: mytrigger.service: Service RestartSec=1s expired, scheduling restart.
Mar 31 15:43:18.334815 myhost systemd[1]: mytrigger.service: Scheduled restart job, restart counter is at 11.
Mar 31 15:43:18.335410 myhost systemd[1]: Stopped mytrigger.service.
Mar 31 15:43:18.339837 myhost systemd[1]: Starting mytrigger.service...
Mar 31 15:43:28.348049 myhost systemd[1]: Started mytrigger.service.
Mar 31 15:43:28.353353 myhost systemd[1]: Starting myservice.service...
Mar 31 15:43:28.364704 myhost bash[79630]: Hello World!
Mar 31 15:43:28.365681 myhost systemd[1]: myservice.service: Succeeded.
Mar 31 15:43:28.366337 myhost systemd[1]: Started myservice.service.

Я ожидал myservice.service начинать столько раз, сколько mytrigger.service делает. когда myservice.service установлен как После заказ в mytrigger.service, то обе службы перезапускаются одинаковое количество раз.

Зачем myservice.service перезапускается в два раза чаще, чем mytrigger.service?