Eu tenho um serviço systemd (vamos chamá-lo de first.service ) que chama um script bash.
Nesse primeiro script, paro e inicio outro serviço com systemctl (por exemplo, systemctl start another.service .
Tenho notado que quando executo meu script em um shell, tudo funciona corretamente e another.service está sendo interrompido e depois iniciado.
Quando eu chamo systemctl restart first.service systemd pára o " another.service " corretamente, mas trava ao iniciá-lo.
Quando eu verifico o resultado de ps ele diz que ambas as chamadas systemctl estão funcionando, ou seja, systemctl restart first.service e systemctl start another.service .
Eu uso systemd 230
Esse comportamento é conhecido? Como posso consertar isso?
Existe alguma maneira melhor de lidar com (re) iniciar os serviços do systemd dentro de um serviço?
EDITAR :
Meu arquivo first.service :
[Unit]
Description=First service
#Before=local-fs.target apache2.service rsyslog.service
[Service]
Type=oneshot
ExecStart=/usr/bin/test.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Meu arquivo another.service :
[Unit]
Description=Test service
[Service]
Type=oneshot
ExecStart=/bin/bash -c "while ( true ) ; do { date ; echo 'It works!' ; sleep 10 ; } done"
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
e meu script bash:
#!/bin/bash
echo stopping
systemctl stop another.service
echo "result of stop = $?"
echo starting
systemctl start another.service
echo "result of start = $?"
echo DONE
Depois de pendurar, recebo a seguinte saída de ps :
[piotr@/etc/systemd/system] $ ps -aux | grep systemctl
root 7801 0.0 0.0 27696 1336 pts/21 S+ 16:06 0:00 systemctl restart first
root 7807 0.0 0.0 27696 1320 ? S 16:06 0:00 systemctl start another.service
piotr 7915 0.0 0.0 15752 968 pts/22 S+ 16:06 0:00 grep --color=auto systemctl
EDIT2 :
Estou postando systemctl status de ambos os serviços no exato momento em que em outro console eu chamei systemctl restart first .
Também adicionei a verificação do valor de retorno no meu script bash. Atualizado acima.
first.service :
● first.service - First service
Loaded: loaded (/etc/systemd/system/first.service; disabled; vendor preset: enabled)
Active: activating (start) since Wed 2017-04-19 16:34:43 CEST; 46s ago
Main PID: 12761 (test.sh)
CGroup: /system.slice/first.service
├─12761 /bin/bash /usr/bin/test.sh
└─12766 systemctl start another.service
Apr 19 16:34:43 piotr-ideapad systemd[1]: Starting First service...
Apr 19 16:34:43 piotr-ideapad test.sh[12761]: stopping
Apr 19 16:34:43 piotr-ideapad test.sh[12761]: result of stop = 0
Apr 19 16:34:43 piotr-ideapad test.sh[12761]: starting
another.service :
● another.service - Test service
Loaded: loaded (/etc/systemd/system/another.service; disabled; vendor preset: enabled)
Active: activating (start) since Wed 2017-04-19 16:34:43 CEST; 1min 40s ago
Main PID: 12767 (bash)
CGroup: /system.slice/another.service
├─12767 /bin/bash -c while ( true ) ; do { date ; echo 'It works!' ; sleep 10 ; } done
└─13066 sleep 10
Apr 19 16:35:43 piotr-ideapad bash[12767]: Mi 19. Apr 16:35:43 CEST 2017
Apr 19 16:35:43 piotr-ideapad bash[12767]: It works!
Apr 19 16:35:53 piotr-ideapad bash[12767]: Mi 19. Apr 16:35:53 CEST 2017
Apr 19 16:35:53 piotr-ideapad bash[12767]: It works!
Apr 19 16:36:03 piotr-ideapad bash[12767]: Mi 19. Apr 16:36:03 CEST 2017
Apr 19 16:36:03 piotr-ideapad bash[12767]: It works!
Apr 19 16:36:13 piotr-ideapad bash[12767]: Mi 19. Apr 16:36:13 CEST 2017
Apr 19 16:36:13 piotr-ideapad bash[12767]: It works!
Apr 19 16:36:23 piotr-ideapad bash[12767]: Mi 19. Apr 16:36:23 CEST 2017
Apr 19 16:36:23 piotr-ideapad bash[12767]: It works!
EDIT3 : Depois de trocar alguns comentários, tentarei reformular o problema.
Diga que nenhum dos meus processos listados acima está ativado ou iniciado. Quando eu chamo systemctl status neles - eles são loaded mas inactive .
Em seguida, chamo systemctl start first e esse comando do terminal não é concluído.
Se eu chamar systemctl status nesses serviços, recebo esse status de Active: para ambos, é activating (start) , mas minha execução de systemctl start first no terminal ainda não foi encerrada e ela é interrompida indefinidamente.
Acho que ambos os processos estão na fila e systemctl start another no meu script espera o systemctl start first terminar antes de terminar sozinho e aqui temos um impasse.