Discussion:
systemctl can't execute stop actually, when service is started by other way
Add Reply
清辰
2017-06-27 05:48:47 UTC
Reply
Permalink
Raw Message
for example: service nscd
1.execute: systemctl stop nscd.service
stop nscd process actually
2.execute: /usr/bin/nscd
start nscd by shell command
3.execute: systemctl status nscd.service
inactive(dead)
systemctl can't know nscd is running
4.excute: systemctl stop nscd.service
nscd process still exist, it seems that systemctl does not execute stop actually


How can I stop nscd.service by systemctl when it is started not by systemctl?


Why I need stop nscd.service by systemctl?
Because when linux reboot or shut down, linux will auto stop service by 'systemctl stop nscd.service'.
If 'systemctl stop nscd.service' does not stop service actually, my service will exit abnormally. That may lead data loss in my service.


Thank you very much
Lennart Poettering
2017-06-27 07:29:32 UTC
Reply
Permalink
Raw Message
Post by 清辰
for example: service nscd
1.execute: systemctl stop nscd.service
stop nscd process actually
2.execute: /usr/bin/nscd
start nscd by shell command
3.execute: systemctl status nscd.service
inactive(dead)
systemctl can't know nscd is running
4.excute: systemctl stop nscd.service
nscd process still exist, it seems that systemctl does not execute stop actually
How can I stop nscd.service by systemctl when it is started not by systemctl?
You cannot. systemd is a service manager. When you tell it to manage
something that means it will start/stop/introspect/... it for you. But
if you manage the service on your own, outside of it, then it won't do
any of that.

Hence: either let systemd the service and then also stop it for you,
or do it yourself, but you cannot let it stop it for you but not start
it in the first place.

Sorry,

Lennart
--
Lennart Poettering, Red Hat
清辰
2017-06-28 08:38:08 UTC
Reply
Permalink
Raw Message
Hi Lennart,


Thank you for your reply.


Is there a way to execute stop actually, even the status is inactive.




------------------ Ô­ÊŒÓÊŒþ ------------------
·¢ŒþÈË: "Lennart Poettering"<***@poettering.net>;
·¢ËÍʱŒä: 2017Äê6ÔÂ27ÈÕ(ÐÇÆÚ¶þ) ÏÂÎç3:29
ÊÕŒþÈË: "Ç峜"<***@qq.com>;
³­ËÍ: "systemd-devel"<systemd-***@lists.freedesktop.org>;
Ö÷Ìâ: Re: [systemd-devel] systemctl can't execute stop actually, whenservice is started by other way
Post by 清辰
for example: service nscd
1.execute: systemctl stop nscd.service
stop nscd process actually
2.execute: /usr/bin/nscd
start nscd by shell command
3.execute: systemctl status nscd.service
inactive(dead)
systemctl can't know nscd is running
4.excute: systemctl stop nscd.service
nscd process still exist, it seems that systemctl does not execute stop actually
How can I stop nscd.service by systemctl when it is started not by systemctl?
You cannot. systemd is a service manager. When you tell it to manage
something that means it will start/stop/introspect/... it for you. But
if you manage the service on your own, outside of it, then it won't do
any of that.

Hence: either let systemd the service and then also stop it for you,
or do it yourself, but you cannot let it stop it for you but not start
it in the first place.

Sorry,

Lennart

--
Lennart Poettering, Red Hat
Amish
2017-06-28 09:45:44 UTC
Reply
Permalink
Raw Message
Post by 清辰
Is there a way to execute stop actually, even the status is inactive.
Post by 清辰
for example: service nscd
1.execute: systemctl stop nscd.service
stop nscd process actually
2.execute: /usr/bin/nscd
start nscd by shell command
Why dont you (or your script) start it with:
systemctl start nscd

Then status and stop will also work as expected.

Amish.
Lennart Poettering
2017-06-28 10:48:12 UTC
Reply
Permalink
Raw Message
Post by 清辰
Hi Lennart,
Thank you for your reply.
Is there a way to execute stop actually, even the status is inactive.
No there is not. system will only allow stopping of services that are
actually started.

Lennart
--
Lennart Poettering, Red Hat
清辰
2017-06-28 11:10:16 UTC
Reply
Permalink
Raw Message
Why? I think that will be more insured in case the status is not correct.




------------------ Ô­ÊŒÓÊŒþ ------------------
·¢ŒþÈË: "Lennart Poettering"<***@poettering.net>;
·¢ËÍʱŒä: 2017Äê6ÔÂ28ÈÕ(ÐÇÆÚÈý) ÍíÉÏ6:48
ÊÕŒþÈË: "Ç峜"<***@qq.com>;
³­ËÍ: "systemd-devel"<systemd-***@lists.freedesktop.org>;
Ö÷Ìâ: Re: »ØžŽ£º [systemd-de vel] systemctl can't execute stop actually,whenservice is started by other way
Post by 清辰
Hi Lennart,
Thank you for your reply.
Is there a way to execute stop actually, even the status is inactive.
No there is not. system will only allow stopping of services that are
actually started.

Lennart

--
Lennart Poettering, Red Hat
Lennart Poettering
2017-06-28 11:29:07 UTC
Reply
Permalink
Raw Message
Post by 清辰
Why? I think that will be more insured in case the status is not correct.
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?

I am sorry, but systemd is simply not intended to be used that
way. Either you run your stuff as systemd service and then tell
systemd to stop it again too, or do not use systemd for service
management, and then tell it somehow else.

Sorry,

Lennart
--
Lennart Poettering, Red Hat
Oliver Neukum
2017-06-29 08:05:08 UTC
Reply
Permalink
Raw Message
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
The check systemd does adds no value. There is a reason to not start
something that is running. The reverse does not apply.

Regards
Oliver
Tomasz Torcz
2017-06-29 08:18:42 UTC
Reply
Permalink
Raw Message
Post by Oliver Neukum
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
The check systemd does adds no value. There is a reason to not start
something that is running. The reverse does not apply.
By starting nscd in some shell session, there's no mapping between
running executable and a service. Systemd has no way of knowing
that random nscd binary is supposed to be killed when 'systemctl stop nscd'
is invoked. How would it know?

That is really the question! How systemd would know that unrelated
binary should be killed when user invokes 'systemctl stop' on service,
service which has not been started? Is systemd supposed to compare full
path of all running binaries to ExecStart= lines in unit files? But what
about situation when you have multiple services with the same ExecStart=?

Maybe user starting random binaries in login session should echo their
PIDs into 'tasks' file in relevant cgroup? What if the cgroup does not exists
yet (because service wasn't started)? This quickly becames a dangerous hackery.

I'm all ears – what's your solution?
--
Tomasz Torcz Morality must always be based on practicality.
xmpp: ***@chrome.pl -- Baron Vladimir Harkonnen
Lennart Poettering
2017-06-29 08:29:37 UTC
Reply
Permalink
Raw Message
Post by Oliver Neukum
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
Because things are technically designed that way. When systemd manages
services it does so ensuring it will get SIGCHLD events for them. it
will also run them in a cgroup, so that it can monitor its lifetime by
enumerating the cgroup's contents, and getting events from it.

Now, if you start stuff outside of systemd nothing of that is
available, so systemd wouldn#t know that is running, and it
couldn't properly stop anything because it can't get ahold of the
processes to terminate.

Lennart
--
Lennart Poettering, Red Hat
Reindl Harald
2017-06-29 09:45:25 UTC
Reply
Permalink
Raw Message
Post by Oliver Neukum
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
The check systemd does adds no value. There is a reason to not start
something that is running. The reverse does not apply
this is nonsense - how in the world should systemmd know what to stop
when it has no clue about the involved processes because it did not
start the service and hence has no tracking at all
Oliver Neukum
2017-06-29 09:51:53 UTC
Reply
Permalink
Raw Message
Post by Reindl Harald
Post by Oliver Neukum
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
The check systemd does adds no value. There is a reason to not start
something that is running. The reverse does not apply
this is nonsense - how in the world should systemmd know what to stop
when it has no clue about the involved processes because it did not
start the service and hence has no tracking at all
So try and fail. That is still no excuse for ruling out that you can
stop a service you have not started. That is pure politics.

Regards
Oliver
Reindl Harald
2017-06-29 10:05:12 UTC
Reply
Permalink
Raw Message
Post by Oliver Neukum
Post by Reindl Harald
Post by Oliver Neukum
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
The check systemd does adds no value. There is a reason to not start
something that is running. The reverse does not apply
this is nonsense - how in the world should systemmd know what to stop
when it has no clue about the involved processes because it did not
start the service and hence has no tracking at all
So try and fail. That is still no excuse for ruling out that you can
stop a service you have not started. That is pure politics.
*try WHAT* - kill random processes?

simple example after that you hopefully understand why this is nonsense

* i have two servcies on several machines
* each of the has "mysqld" as ExecStart using different configs
* "mysqld.service" and "replication.service"

so what do you do when "replication.service" is not started and you say
"systemctl stop replicatiuon.service" - kill my other mysqld?

ps aux | grep openvpn | wc -l
7

what do you do when you issue "systemctl stop openvpn1.service" and it
is not running? kill my other 6 instanes, kill only one of them and if
yes which one

a service manager is not a gambling machine

* if you start a process by hand kill it by hand
* if you start a process as service kill it with systemcl

it's really that easy
Tomasz Torcz
2017-06-29 10:05:47 UTC
Reply
Permalink
Raw Message
Post by Oliver Neukum
Post by Reindl Harald
Post by Oliver Neukum
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
The check systemd does adds no value. There is a reason to not start
something that is running. The reverse does not apply
this is nonsense - how in the world should systemmd know what to stop
when it has no clue about the involved processes because it did not
start the service and hence has no tracking at all
So try and fail. That is still no excuse for ruling out that you can
stop a service you have not started. That is pure politics.
There's no service if it wasn't started by systemd. It's just a random binary.
--
Tomasz Torcz Morality must always be based on practicality.
xmpp: ***@chrome.pl -- Baron Vladimir Harkonnen
Lennart Poettering
2017-07-03 08:34:59 UTC
Reply
Permalink
Raw Message
Post by Oliver Neukum
Post by Reindl Harald
Post by Oliver Neukum
Post by Lennart Poettering
Well, it's a service manager. As such it keeps track of services,
knows when they are started and when they aren't. Why would it stop
services that aren't started?
Because you command it to do so.
The check systemd does adds no value. There is a reason to not start
something that is running. The reverse does not apply
this is nonsense - how in the world should systemmd know what to stop
when it has no clue about the involved processes because it did not
start the service and hence has no tracking at all
So try and fail. That is still no excuse for ruling out that you can
stop a service you have not started. That is pure politics.
Note that stopping services is more than just invoking an ExecStop=
script, as systemd will kill everything remaining after that, and
waits for all processes being gone before considering the service
properly down. All that falls apart if systemd never tracked the
service, as we neither know what to kill nor what to wait for.

In fact, a major chunk of services don't even have ExecStop= anymore,
as it is mostly redundant with this scheme, as just sending SIGTERM covers
80% of how common system services are shut down.

Lennart
--
Lennart Poettering, Red Hat
Loading...