# Service restart doing some strange things to bound services

**URL:** <https://forum.ansible.com/t/service-restart-doing-some-strange-things-to-bound-services/20009>\
**Category:** Ansible Project\
**Created:** [December 14, 2015, 10:57pm UTC](https://forum.ansible.com/t/service-restart-doing-some-strange-things-to-bound-services/20009 "2015-12-14T22:57:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Picciano](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@Brian\_Picciano](https://forum.ansible.com/u/Brian_Picciano)\
**Post date:** [December 14, 2015, 10:57pm UTC](https://forum.ansible.com/t/service-restart-doing-some-strange-things-to-bound-services/20009/1 "2015-12-14T22:57:07Z")

</div>

`  
[vagrant@brian ansible-repo]$ uname -r  
3.10.0-229.14.1.el7.x86\_64

[vagrant@brian ansible-repo]$ ansible --version  
ansible 1.9.2  
`

I have two processes set up, one bound to the other so that if the “parent” one dies or is stopped it will also. They look like this:

Parent:

`  
[Unit]  
Description=nginx - high performance web server  
After=network.target remote-fs.target nss-lookup.target

[Service]  
StartLimitInterval=0  
RestartSec=1s  
Restart=on-failure  
TimeoutStartSec=5  
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf  
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf  
User=root  
PrivateTmp=true

[Install]  
WantedBy=multi-user.target

`

Child:

`  
[Unit]  
Description=foo  
After=nginx.service  
Requires=nginx.service  
PartOf=nginx.service

[Service]  
StartLimitInterval=0  
RestartSec=1s  
User=vagrant  
Restart=on-failure  
TimeoutStartSec=5  
ExecStart=/bin/sh -c ‘echo FOO STARTED; while [1]; do sleep 1; done’

[Install]  
WantedBy=multi-user.target  
`

(I’m aware of the BindTo command for systemd, it doesn’t actually do what we want it to though. This combination of After/Requires/PartOf seems to behave in the way we want)

Anyway, if I restart nginx normally then foo is restarted normally as well:

`  
[vagrant@brian ansible-repo]$ sudo systemctl restart nginx

Dec 14 22:49:16 brian systemd[1]: Stopping foo…  
Dec 14 22:49:16 brian systemd[1]: Stopping nginx - high performance web server…  
Dec 14 22:49:16 brian systemd[1]: Starting nginx - high performance web server…  
Dec 14 22:49:16 brian nginx[14714]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
Dec 14 22:49:16 brian nginx[14714]: nginx: configuration file /etc/nginx/nginx.conf test is successful  
Dec 14 22:49:16 brian systemd[1]: Started nginx - high performance web server.  
Dec 14 22:49:16 brian systemd[1]: Starting foo…  
Dec 14 22:49:16 brian systemd[1]: Started foo.  
Dec 14 22:49:16 brian sh[14719]: FOO STARTED  
`

But if I use ansible to restart nginx, the following happens:

`  
[vagrant@brian ansible-repo]$ ansible -c local -m service -a ‘name=nginx state=restarted’ vagrant  
vagrant | success \>\> {  
“changed”: true,  
“name”: “nginx”,  
“state”: “started”  
}

Dec 14 22:52:02 brian systemd[1]: Stopping foo…  
Dec 14 22:52:02 brian systemd[1]: Stopped foo.  
Dec 14 22:52:02 brian systemd[1]: Stopping nginx - high performance web server…  
Dec 14 22:52:02 brian systemd[1]: Stopped nginx - high performance web server.  
Dec 14 22:52:02 brian systemd[1]: Starting nginx - high performance web server…  
Dec 14 22:52:02 brian nginx[15208]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
Dec 14 22:52:02 brian nginx[15208]: nginx: configuration file /etc/nginx/nginx.conf test is successful  
Dec 14 22:52:02 brian systemd[1]: Started nginx - high performance web server.  
`

And that’s it, foo is never actually started. Calling `sudo systemctl restart nginx` again doesn’t start foo either.

Any ideas as to what I could be doing wrong? Or is this some kind of bug in how ansible is handling service restarts?

---

<div class="post-metadata">

**Author:** ![Brian\_Picciano](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@Brian\_Picciano](https://forum.ansible.com/u/Brian_Picciano)\
**Post date:** [December 14, 2015, 11:08pm UTC](https://forum.ansible.com/t/service-restart-doing-some-strange-things-to-bound-services/20009/2 "2015-12-14T23:08:49Z")

</div>

To follow up, it appears that ansible is not actually calling systemctl restart, but is instead doing a stop then a start, which is causing this weirdness. The comments in the source mention that some services don’t support restart, and that’s why it’s doing a stop/start. Is this actually true? Are there systemd services which don’t support restart? I was under the impressions systemd could do a restart on any service which could be stopped then started.
