Service restart doing some strange things to bound services

34 views
Skip to first unread message

Brian Picciano

unread,
Dec 14, 2015, 5:57:07 PM12/14/15
to Ansible Project
[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?



 

Brian Picciano

unread,
Dec 14, 2015, 6:08:49 PM12/14/15
to Ansible Project
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.
...
Reply all
Reply to author
Forward
0 new messages