Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-06-01 Thread Bao Nguyen
Hi Michael,

Thanks for your comments, looks like it will work. I will try it.

Just adding a question, if my specific is written in old style
(SystemVinit), it has LSB header, how can I modify it to make it depend on
multi-user.target.

Thanks,

Brs

On Wed, May 25, 2016 at 5:09 PM, Michael Chapman 
wrote:

> On Thu, 19 May 2016, Bao Nguyen wrote:
>
>> Hi everyone,
>>
>> When the system is shutdown, systemd will terminate all services in
>> parallel manner, could you let me know if there is any ways to tell
>> systemd
>> to shutdown a specific service first, then shutdown all remaining
>> services?
>>
>
> Hello,
>
> I haven't tested it, but as far as I know all you need to do is ensure
> your special service is After=multi-user.target, i.e.:
>
>   [Unit]
>   Description=Some service that must be started late / stopped early
>   After=multi-user.target
>
>   [Service]
>   # ...
>
>   [Install]
>   WantedBy=multi-user.target
>
> A target unit is automatically After= all the units that it Wants=,
> Requires=, etc., but this automatic dependency is *not* added if that would
> create a dependency loop.
>
> So at shutdown systemd knows it needs to stop all services and targets.
> Because your special service is After=multi-user.target, and
> multi-user.target is After= all *other* normal services, everything gets
> ordered correctly: your service is stopped first, then multi-user.target is
> stopped, then all the other services are stopped.
>
> Now, this isn't the *cleanest* solution -- you really want to be specific
> in your service dependencies rather than depending upon a whole target's
> worth of services, and there's always the chance that multi-user.target
> might be stopped some other way before shutdown -- but it does seem as if
> it goes some way to solving your problem.
>
> - Michael
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-25 Thread Michael Chapman

On Thu, 19 May 2016, Bao Nguyen wrote:

Hi everyone,

When the system is shutdown, systemd will terminate all services in
parallel manner, could you let me know if there is any ways to tell systemd
to shutdown a specific service first, then shutdown all remaining services?


Hello,

I haven't tested it, but as far as I know all you need to do is ensure 
your special service is After=multi-user.target, i.e.:


  [Unit]
  Description=Some service that must be started late / stopped early
  After=multi-user.target

  [Service]
  # ...

  [Install]
  WantedBy=multi-user.target

A target unit is automatically After= all the units that it Wants=, 
Requires=, etc., but this automatic dependency is *not* added if that 
would create a dependency loop.


So at shutdown systemd knows it needs to stop all services and targets. 
Because your special service is After=multi-user.target, and 
multi-user.target is After= all *other* normal services, everything gets 
ordered correctly: your service is stopped first, then multi-user.target 
is stopped, then all the other services are stopped.


Now, this isn't the *cleanest* solution -- you really want to be specific 
in your service dependencies rather than depending upon a whole target's 
worth of services, and there's always the chance that multi-user.target 
might be stopped some other way before shutdown -- but it does seem as if 
it goes some way to solving your problem.


- Michael
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-25 Thread Andrei Borzenkov
On Wed, May 25, 2016 at 9:59 AM, Bao Nguyen  wrote:
> Hi,
>
> Thanks for all your comments.
>
> How do you think if we create a custom target to include all remaining
> services, then add this target to the dependency After= of the specific
> services. This way can make the specific stop before the services in the
> target when the system shutdowns?
>

Keyword here is "all remaining services". If you have fixed number of
services that are known in advance then yes, you can of course
configure arbitrary dependencies between them and order them exactly
as you need.

What is asked at regular interval is doing the same for arbitrary
number of services unknown in advance. This is not possible.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-25 Thread Bao Nguyen
Hi,

Thanks for all your comments.

How do you think if we create a custom target to include all remaining
services, then add this target to the dependency After= of the specific
services. This way can make the specific stop before the services in the
target when the system shutdowns?

Thanks,
BRs,
Natsu

On Mon, May 23, 2016 at 3:54 PM, Lennart Poettering 
wrote:

> On Sun, 22.05.16 15:24, Andrei Borzenkov (arvidj...@gmail.com) wrote:
>
> > 19.05.2016 11:57, Martin Pitt пишет:
> > > Hello Bao,
> > >
> > > Bao Nguyen [2016-05-19 15:52 +0700]:
> > >> When the system is shutdown, systemd will terminate all services in
> > >> parallel manner, could you let me know if there is any ways to tell
> systemd
> > >> to shutdown a specific service first, then shutdown all remaining
> services?
> > >
> > > The concept of "first"/"last" has no well-defined meaning in any
> > > non-serial init systems (not even SysV init with insserv, only with
> > > classic SysV init with manually set priorities). I've heard requests
> > > like "but this needs to be started as the last thing" a lot in the
> > > recent years, and there's no way all the services can simultaneously
> > > be "last" :-)
> >
> > Well, the very good example of service that has to be started/stopped
> > before/after anything else is splash screen (plymouth or anything). It
> > really must appear as soon as user hit ENTER in "systemctl reboot". As
> > it stands now, there is no way to ensure it.
>
> Well, shutting down is asynchronous anyway. Hence, yes, it should be shown
> pretty quickly, but strict, enforced ordering here is not necessary.
>
> This is a different story if you want a smooth transition between some
> graphical login thingy (such as gdm) and the ply shutdown screen, but
> in that case there should really be a direct hand-over so that gdm
> only releases the DRM when it knows that py has taken over. Such logic
> needs to happen directly between ply and gdm however, and in fact does
> already.
>
> > > You should put sufficient After= properties into your service, so that
> > > it gets started after and stopped before the ones you specify.
> >
> > Do you suggest adding dependency on plymouth to *every* service?
>
> No, I'd suggest that you are using the wrong tool here and should use
> something else...
>
> Lennart
>
> --
> Lennart Poettering, Red Hat
> ___
> systemd-devel mailing list
> systemd-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-23 Thread Lennart Poettering
On Sun, 22.05.16 15:24, Andrei Borzenkov (arvidj...@gmail.com) wrote:

> 19.05.2016 11:57, Martin Pitt пишет:
> > Hello Bao,
> > 
> > Bao Nguyen [2016-05-19 15:52 +0700]:
> >> When the system is shutdown, systemd will terminate all services in
> >> parallel manner, could you let me know if there is any ways to tell systemd
> >> to shutdown a specific service first, then shutdown all remaining services?
> > 
> > The concept of "first"/"last" has no well-defined meaning in any
> > non-serial init systems (not even SysV init with insserv, only with
> > classic SysV init with manually set priorities). I've heard requests
> > like "but this needs to be started as the last thing" a lot in the
> > recent years, and there's no way all the services can simultaneously
> > be "last" :-)
> 
> Well, the very good example of service that has to be started/stopped
> before/after anything else is splash screen (plymouth or anything). It
> really must appear as soon as user hit ENTER in "systemctl reboot". As
> it stands now, there is no way to ensure it.

Well, shutting down is asynchronous anyway. Hence, yes, it should be shown
pretty quickly, but strict, enforced ordering here is not necessary.

This is a different story if you want a smooth transition between some
graphical login thingy (such as gdm) and the ply shutdown screen, but
in that case there should really be a direct hand-over so that gdm
only releases the DRM when it knows that py has taken over. Such logic
needs to happen directly between ply and gdm however, and in fact does
already.

> > You should put sufficient After= properties into your service, so that
> > it gets started after and stopped before the ones you specify. 
> 
> Do you suggest adding dependency on plymouth to *every* service?

No, I'd suggest that you are using the wrong tool here and should use
something else...

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-22 Thread Mantas Mikulėnas
On Sun, May 22, 2016 at 3:24 PM, Andrei Borzenkov 
wrote:

> 19.05.2016 11:57, Martin Pitt пишет:
> > Hello Bao,
> >
> > Bao Nguyen [2016-05-19 15:52 +0700]:
> >> When the system is shutdown, systemd will terminate all services in
> >> parallel manner, could you let me know if there is any ways to tell
> systemd
> >> to shutdown a specific service first, then shutdown all remaining
> services?
> >
> > The concept of "first"/"last" has no well-defined meaning in any
> > non-serial init systems (not even SysV init with insserv, only with
> > classic SysV init with manually set priorities). I've heard requests
> > like "but this needs to be started as the last thing" a lot in the
> > recent years, and there's no way all the services can simultaneously
> > be "last" :-)
> >
>
> Well, the very good example of service that has to be started/stopped
> before/after anything else is splash screen (plymouth or anything). It
> really must appear as soon as user hit ENTER in "systemctl reboot". As
> it stands now, there is no way to ensure it.
>

Even before the user's session exits? Seems odd.


> > You should put sufficient After= properties into your service, so that
> > it gets started after and stopped before the ones you specify.
>
> Do you suggest adding dependency on plymouth to *every* service?


The "start" half of this problem seems to have been solved already 
various display managers (e.g. gdm and even agetty) have added explicit
support for connecting to Plymouth and telling it to exit.

-- 
Mantas Mikulėnas 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-22 Thread Andrei Borzenkov
19.05.2016 11:57, Martin Pitt пишет:
> Hello Bao,
> 
> Bao Nguyen [2016-05-19 15:52 +0700]:
>> When the system is shutdown, systemd will terminate all services in
>> parallel manner, could you let me know if there is any ways to tell systemd
>> to shutdown a specific service first, then shutdown all remaining services?
> 
> The concept of "first"/"last" has no well-defined meaning in any
> non-serial init systems (not even SysV init with insserv, only with
> classic SysV init with manually set priorities). I've heard requests
> like "but this needs to be started as the last thing" a lot in the
> recent years, and there's no way all the services can simultaneously
> be "last" :-)
> 

Well, the very good example of service that has to be started/stopped
before/after anything else is splash screen (plymouth or anything). It
really must appear as soon as user hit ENTER in "systemctl reboot". As
it stands now, there is no way to ensure it.

> You should put sufficient After= properties into your service, so that
> it gets started after and stopped before the ones you specify. 

Do you suggest adding dependency on plymouth to *every* service?

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-20 Thread Lennart Poettering
On Fri, 20.05.16 11:24, Bao Nguyen (bao...@gmail.com) wrote:

> Hi Martin,
> 
> Thanks a lot for your answer.
> 
> How about if my specific script is written by SysVinit, it has LSB headers,
> can we still use in LSB header the property lAfter= as in systemd to make
> it start/stop orderly?

Our "sysv-generator" tool that is responsible for turning SysV
services into native systemd services understands the
"X-Start-Before:" and "X-Start-After:" LSB header file stanzas to
declare ordering. This is an extension Debian introduced that we
support too.




> 
> Another solution I think to make it shutdowns "order" when I read
> systemd-halt.service in
> https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html
> 
> "Immediately before executing the actual system halt/poweroff/reboot/kexec
> systemd-shutdown will run all executables in
> /usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "
> halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All
> executables in this directory are executed in parallel, and execution of
> the action is not continued before all executables finished."
> 
> Can I put a script to terminate my specific script in
> /usr/lib/systemd/system-shutdown/?
> As the description, the script will be run to terminate my script before
> executing the actual system shutdown?

No, these executables are run very late, immediately before executing
the actual system halt, as the documentation says pretty explicitly...

> Some people on internet also tried to make a script to do something
> before everything
> else on shutdown with systemd like
> http://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemde
> 
> How do you think if I can make a script to terminate my script before all
> other services shutdown like above to make it "order"?

The concept doesn't exist. If everybody does soemthing like that, how
are we supposed to resolve that? If you have 100 services, and all of
them want to be stopped before all others, how would you ever resolve
that?

Please simply list the right deps instead.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-19 Thread Bao Nguyen
Hi Martin,

Thanks a lot for your answer.

How about if my specific script is written by SysVinit, it has LSB headers,
can we still use in LSB header the property lAfter= as in systemd to make
it start/stop orderly?

Another solution I think to make it shutdowns "order" when I read
systemd-halt.service in
https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html

"Immediately before executing the actual system halt/poweroff/reboot/kexec
systemd-shutdown will run all executables in
/usr/lib/systemd/system-shutdown/ and pass one arguments to them: either "
halt", "poweroff", "reboot" or "kexec", depending on the chosen action. All
executables in this directory are executed in parallel, and execution of
the action is not continued before all executables finished."

Can I put a script to terminate my specific script in
/usr/lib/systemd/system-shutdown/?
As the description, the script will be run to terminate my script before
executing the actual system shutdown?

Some people on internet also tried to make a script to do something
before everything
else on shutdown with systemd like
http://superuser.com/questions/1016827/how-do-i-run-a-script-before-everything-else-on-shutdown-with-systemde

How do you think if I can make a script to terminate my script before all
other services shutdown like above to make it "order"?

Thanks a lot.

Best regards,
Natsu





On Thu, May 19, 2016 at 3:57 PM, Martin Pitt  wrote:

> Hello Bao,
>
> Bao Nguyen [2016-05-19 15:52 +0700]:
> > When the system is shutdown, systemd will terminate all services in
> > parallel manner, could you let me know if there is any ways to tell
> systemd
> > to shutdown a specific service first, then shutdown all remaining
> services?
>
> The concept of "first"/"last" has no well-defined meaning in any
> non-serial init systems (not even SysV init with insserv, only with
> classic SysV init with manually set priorities). I've heard requests
> like "but this needs to be started as the last thing" a lot in the
> recent years, and there's no way all the services can simultaneously
> be "last" :-)
>
> You should put sufficient After= properties into your service, so that
> it gets started after and stopped before the ones you specify. See
> man systemd.unit for details.
>
> Martin
>
> --
> Martin Pitt| http://www.piware.de
> Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
>
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Shutdown a specific service in systemd shutdown

2016-05-19 Thread Martin Pitt
Hello Bao,

Bao Nguyen [2016-05-19 15:52 +0700]:
> When the system is shutdown, systemd will terminate all services in
> parallel manner, could you let me know if there is any ways to tell systemd
> to shutdown a specific service first, then shutdown all remaining services?

The concept of "first"/"last" has no well-defined meaning in any
non-serial init systems (not even SysV init with insserv, only with
classic SysV init with manually set priorities). I've heard requests
like "but this needs to be started as the last thing" a lot in the
recent years, and there's no way all the services can simultaneously
be "last" :-)

You should put sufficient After= properties into your service, so that
it gets started after and stopped before the ones you specify. See
man systemd.unit for details.

Martin

-- 
Martin Pitt| http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel