Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-24 Thread Kai Krakow
Am Thu, 24 Nov 2016 10:39:52 +0100
schrieb Benoit SCHMID :

> Hello,
> 
> On 11/23/2016 03:52 PM, Reindl Harald wrote:
> > so why do you strip the whole context and rest of the response?
> >
> > what  is your exactly problem?
> >  
> I think my original question on this thread is clear.
> > it should be no rocket science to define a service, order starting
> > as needed which ensures at the same time that stop services happens
> > in the exactly reverse order
> >  
> It is more than rocket science to have the same behaviour
> for my SAP system behaviour on RH7 like on RH6.
> On RH6 I could boot my server.
> Then a few days after I could manually restart dedicated processes.
> On the next shutdown, I knew my processes would be cleanly stopped.
> 
> With RH7, my commands' executions need to be wrapped by systemd
> service. Otherwise, as L. Poettering said, these daemons are not
> stopped cleanly at shutdown.
> This what I have understood.
> 
> > maybe you should stop looking at old sysv scripts and just start
> > from scratch and define what you need in a proper systemd unit -
> > for many things you will find out that a lot of magic from init
> > scripts is not needed at all
> >  
> This is what I am trying to do :-)
> 
> > for me it ssems what you trying to to is wrap everything from a init
> > script in a native systemd-unit which is wrong from the start in
> > most cases   
> "trying to wrap everything from init script" is not my overall goal.
> My over goal is to administer my SAP systems on my new RH7 servers.
> 
> I have constraints from RH7 and from SAP and from Oracle DB.
> After reading that there is systemv systemd generator,
> I thought that I could have all the old functionalities with systemd.
> It is not the case.
> Therefore I am trying to find the best compromises to run my SAP
> systems. This implies understanding what I can do and what I cannot
> do with systemd. This is why I ask questions like the one on this
> thread.

What exactly is the init script in question doing, not generalizing it
to a simple "echo" and "touch"?

I had once an init script that did dirty user switch hackery to first
setup some things, then switch the user and start the service by using
"su".

This does not seem to work properly as "su" spawns a new session. Your
service executable is then no longer a real part of what systemd knows
about spawning the service. During shutdown, it cannot properly stop it
(actually, it simply ignores the PID from the su session) and will
eventually simply kill it later. That means, the core of your service
looses all stop dependencies defined and will, by definition, killed
too late at shutdown.

Even OpenRC did not properly stop this service when used in cgroup
mode. Using su simply switches to another cgroup as it looked to me and
the service wasn't sent signals properly.

Instead, you should leave the setup and user switching to systemd. That
means setting up directories for example with "RuntimeDirectory", or do
some other stuff with "ExecPre". You can switch the user with a native
systemd directive, even switching only for "Exec" but not "ExecPre".

I my case, I ported the cumbersome script to native systemd mechanics
with proper user switching and now everything went well and was solid.

The original script was something like a start-stop-daemon emulation,
exporting a simple start/stop interface to command line, thus every
init system could be easily wrapped around it. Its core daemon is a
closed source piece of software and the "init" script was just a
convenience compatbility layer to sysvinit systems - but due to its
implementation incompatible with cgroup-based init systems.

-- 
Regards,
Kai

Replies to list-only preferred.

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


Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-24 Thread Lennart Poettering
On Thu, 24.11.16 10:59, Benoit SCHMID (benoit.sch...@unige.ch) wrote:

> Hello,
> 
> On 11/24/2016 12:22 AM, Lennart Poettering wrote:
> > In general, while systemd provides a large degree of SysV compat, in
> > the end we aren't SysV and thus we do not provide 100%. In cases like
> > this this becomes visible.
> 
> You are 100% right :-)
> 
> Right after upgrading my first server,
> I wrongly assumed that systemv scripts
> could be migrated easily.
> I was wrong.

Well, most of them can. It's the exotic ones which can't be that easily.

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] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-24 Thread Benoit SCHMID
Hello,

On 11/24/2016 12:22 AM, Lennart Poettering wrote:
> In general, while systemd provides a large degree of SysV compat, in
> the end we aren't SysV and thus we do not provide 100%. In cases like
> this this becomes visible.

You are 100% right :-)

Right after upgrading my first server,
I wrongly assumed that systemv scripts
could be migrated easily.
I was wrong.

Thanks for all the feedbacks you have provided.

-- 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

 Benoit Schmid  Tel: (+41-22) 379-7209

 University of Geneva - Information Technology Division

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 

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


Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-24 Thread Benoit SCHMID
Hello,

On 11/23/2016 03:52 PM, Reindl Harald wrote:
> so why do you strip the whole context and rest of the response?
>
> what  is your exactly problem?
>
I think my original question on this thread is clear.
> it should be no rocket science to define a service, order starting as
> needed which ensures at the same time that stop services happens in
> the exactly reverse order
>
It is more than rocket science to have the same behaviour
for my SAP system behaviour on RH7 like on RH6.
On RH6 I could boot my server.
Then a few days after I could manually restart dedicated processes.
On the next shutdown, I knew my processes would be cleanly stopped.

With RH7, my commands' executions need to be wrapped by systemd service.
Otherwise, as L. Poettering said, these daemons are not stopped cleanly
at shutdown.
This what I have understood.

> maybe you should stop looking at old sysv scripts and just start from
> scratch and define what you need in a proper systemd unit - for many
> things you will find out that a lot of magic from init scripts is not
> needed at all
>
This is what I am trying to do :-)

> for me it ssems what you trying to to is wrap everything from a init
> script in a native systemd-unit which is wrong from the start in most
> cases 
"trying to wrap everything from init script" is not my overall goal.
My over goal is to administer my SAP systems on my new RH7 servers.

I have constraints from RH7 and from SAP and from Oracle DB.
After reading that there is systemv systemd generator,
I thought that I could have all the old functionalities with systemd.
It is not the case.
Therefore I am trying to find the best compromises to run my SAP systems.
This implies understanding what I can do and what I cannot do with systemd.
This is why I ask questions like the one on this thread.

Regards,

-- 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

 Benoit Schmid  Tel: (+41-22) 379-7209

 University of Geneva - Information Technology Division

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 

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


Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-23 Thread Lennart Poettering
On Wed, 23.11.16 13:42, Benoit SCHMID (benoit.sch...@unige.ch) wrote:

> Hello,
> 
> On 11/23/2016 11:55 AM, Lennart Poettering wrote:
> > The scripts dropped there are executed very late during the shutdown
> > process at a time where all processes have already been killed and all
> > mount points have been unmounted or at least remounted
> > read-only.
> 
> Is there an easy way to create a systemd service that would be stopped
> very early
> at the shutdown and would avoid the other services stop command to be
> executed.

In systemd there's no concept of "very early". There's just a concept
of "stop unit A before unit B", but you have to configure A and B
explicitly, there's no "catchall" unit logic available.

As I understand you, you want to define a system service that is
ordered After= all user logins, so that (following the rule that on
systemd the shutdown order is the inverse of the startup order) the
service is stopped before the sessions are closed. The idea of such a
thing doesn't make too much sense to me though, as it's really not
clear what this should mean. A user logging out manually right before
the system is shutdown and a user forcibly being logged out due to the
system going down would have a very different semantics in this case
but I doubt it should.

But regardless of this: login session unit names cannot really be
guessed in advance, hence you you cannot define the right dependencies
a priori.

It appears to me that you are trying to press semantics into the
systemd dependency tree that really shouldn't be pressed into it. I am
pretty sure that there's a better way to package your service into
systemd units than this.

In general, while systemd provides a large degree of SysV compat, in
the end we aren't SysV and thus we do not provide 100%. In cases like
this this becomes visible.

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] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-23 Thread Reindl Harald



Am 23.11.2016 um 15:19 schrieb Benoit SCHMID:

On 11/23/2016 03:03 PM, Reindl Harald wrote:

than you need only to adjust "DefaultTimeoutStopSec" to ensure it does
not get killed and order services proper


In most of my tests, this is set to 5min.
Therefore the problem is not located on the fact that the stop command
ends too early


so why do you strip the whole context and rest of the response?

what  is your exactly problem?

it should be no rocket science to define a service, order starting as 
needed which ensures at the same time that stop services happens in the 
exactly reverse order


maybe you should stop looking at old sysv scripts and just start from 
scratch and define what you need in a proper systemd unit - for many 
things you will find out that a lot of magic from init scripts is not 
needed at all


for me it ssems what you trying to to is wrap everything from a init 
script in a native systemd-unit which is wrong from the start in most cases

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


Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-23 Thread Benoit SCHMID
Hello,

On 11/23/2016 03:03 PM, Reindl Harald wrote:
> than you need only to adjust "DefaultTimeoutStopSec" to ensure it does
> not get killed and order services proper 

In most of my tests, this is set to 5min.
Therefore the problem is not located on the fact that the stop command
ends too early.

Regards.

-- 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

 Benoit Schmid  Tel: (+41-22) 379-7209

 University of Geneva - Information Technology Division

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 

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


Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-23 Thread Reindl Harald



Am 23.11.2016 um 13:42 schrieb Benoit SCHMID:

Is there an easy way to create a systemd service that would be stopped
very early
at the shutdown and would avoid the other services stop command to be
executed.

In other world, on my XXX server, the most important service is XXX.
Stopping XXX takes time (~1 min per XXX system).


than you need only to adjust "DefaultTimeoutStopSec" to ensure it does 
not get killed and order services proper



Therefore, in case of init 6, I would like to stopxxx
When stopxxx finishes or timeouts then systemd
could start stopping the other services.

Is there an easier way than trying After= and Before= options?

Thanks for the time you have taken to answer my questions


easier then define proper dependencies with Before/after?

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


Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-23 Thread Andrei Borzenkov
On Wed, Nov 23, 2016 at 3:42 PM, Benoit SCHMID  wrote:
> Hello,
>
> On 11/23/2016 11:55 AM, Lennart Poettering wrote:
>> The scripts dropped there are executed very late during the shutdown
>> process at a time where all processes have already been killed and all
>> mount points have been unmounted or at least remounted
>> read-only.
>
> Is there an easy way to create a systemd service that would be stopped
> very early
> at the shutdown and would avoid the other services stop command to be
> executed.
>
> In other world, on my XXX server, the most important service is XXX.
> Stopping XXX takes time (~1 min per XXX system).
>
> Therefore, in case of init 6, I would like to stopxxx
> When stopxxx finishes or timeouts then systemd
> could start stopping the other services.
>


The following may work (untested):

[Unit]
Description=stop very important services and start shutdown
After=list of very important services
Conflicts=list of very important services

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl --no-block shutdown

Now starting your service /should/ result in stopping of listed
services and then triggering actual system shutdown.


> Is there an easier way than trying After= and Before= options?
>
> Thanks for the time you have taken to answer my questions.
>
> --
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
>  Benoit Schmid  Tel: (+41-22) 379-7209
>
>  University of Geneva - Information Technology Division
>
> _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>
> ___
> 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] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-23 Thread Benoit SCHMID
Hello,

On 11/23/2016 11:55 AM, Lennart Poettering wrote:
> The scripts dropped there are executed very late during the shutdown
> process at a time where all processes have already been killed and all
> mount points have been unmounted or at least remounted
> read-only.

Is there an easy way to create a systemd service that would be stopped
very early
at the shutdown and would avoid the other services stop command to be
executed.

In other world, on my XXX server, the most important service is XXX.
Stopping XXX takes time (~1 min per XXX system).

Therefore, in case of init 6, I would like to stopxxx
When stopxxx finishes or timeouts then systemd
could start stopping the other services.

Is there an easier way than trying After= and Before= options?

Thanks for the time you have taken to answer my questions.

-- 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

 Benoit Schmid  Tel: (+41-22) 379-7209

 University of Geneva - Information Technology Division

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 

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


Re: [systemd-devel] Script in /usr/lib/systemd/system-shutdown not executed on init 6

2016-11-23 Thread Lennart Poettering
On Wed, 23.11.16 08:18, Benoit SCHMID (benoit.sch...@unige.ch) wrote:

> Hello,
> 
> I have added a simple script in /usr/lib/systemd/system-shutdown.
> The scripts echo a message (on stdout) and create a file in /var/tmp.
> I manually tested the script before rebooting to ensure that it
> works fine.

The scripts dropped there are executed very late during the shutdown
process at a time where all processes have already been killed and all
mount points have been unmounted or at least remounted
read-only. Touching a file in /var is hence simply not possible.

it's really executed right before the reboot() system call is issued.

See the docs, specifically, systemd-shutdown(8).

Lennart

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