We're using Ubuntu 16.04 LTS and want to use multiple Tomcat installations which should start at boot time. One of these Tomcats would host a Jenkins which will deploy a webapp onto the other tomcat and restart it.
To start the services, we added systemd service scripts.
What we noticed is that when one tomcat is stopped or killed, the other is stopped as well.
We reduced this to two simple scripts that only use /usr/bin/yes:
Unit A
[Unit]
Description=A
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/yes
ExecStop=/bin/kill -15 $MAINPID
User=tomcat8
Group=tomcat8
[Install]
WantedBy=multi-user.target
Unit B
[Unit]
Description=B
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/yes
ExecStop=/bin/kill -15 $MAINPID
User=tomcat8
Group=tomcat8
[Install]
WantedBy=multi-user.target
What happens:
When a service is killed (kill -9
), both services are gone afterwards.
- Why are both services killed? How can we prevent this?
- Is running more than one service under a single user discouraged, or is this good practice?
EDIT: For clarification – we did also try to do the same when launching the tomcats without systemd. In this instance, the behaviour was as expected: only the killed service was stopped while the other lived on.
EDIT2: The user is not a front-end user that logs in/out at all. It's purely a system user to restrict access of the services.
Best Answer
The changelog for systemd (v230) says:
So this is default behaviour. It also explains what to do to undo the change:
logind.conf
, setKillUserProcesses=
tono
(and--without-kill-user-processes option
toconfigure
)But the changelog also includes a ...
and
That one is more important since it uses the default (kill'm all) with a way to provide exceptions: enable
lingering
.Some more info: