[systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Christian Seiler
Hello,

one of the most-requested features that is not present in systemd
currently is a true rc.local-type functionality that runs after all
other services.

I haven't read all past discussions, but from what I've gathered the
main objection from the systemd developers is that having a catch-all
After=* dependency would not be the sane thing to do.

That said, the frequency of people requesting this feature indicates
that there are valid use cases for this kind of functionality. To give a
few examples:

 - remove /etc/nologin after everything is started
   (some administrators may want this as a policy,
while other's don't)

 - send an email to the admin btw. computer XYZ just
   finished rebooting and here are the log entries generated
   from the boot process

 - in linux HA you may want to defer the node rejoining the
   cluster to the point when you know that the server has
   correctly booted and none of the core services failed in
   the process

I'm sure there are quite a few more.

Current solutions are type=idle units (which don't really work for many
of the above use cases, since type=idle is essentially type=simple) or
setting SysVStartPriority to 99 (as done in Fedora), but that only
orders relative to sysv services, not to native services - and in a
setup where most if not all services are native, this will not have the
desired effect.

In order to implement this feature in systemd, I've gone another
direction: Instead of having a service for which some ordering
constraints are ensured, why not have a timer? There is already
OnBootSec=, which is relative to the time when the kernel was activated,
so the idea was to have another timer base for this specific purpose.

The patch I'm going to send as a reply to this email will implement
OnTransactionFinishedSec=. When a timer is started and contains such an
entry, it will tell the manager to ping it as soon as the transaction is
complete. The manager then proceeds to activate all other units in the
transaction and as soon as it reaches manager_check_finished and no jobs
are left in the run_queue, and after it closes the idle pipe to trigger
the type=idle jobs, it pings the timers again. The timers will then
remember the finish time of the current transaction and use that as a
base for all OnTransactionFinishedSec= entries.

This also has some nice semantics if you want to run something not
immediately after boot but e.g. 5 minutes later. If you think, well,
boot time is ~30s, I just put in OnBootSec=330s, this will usually give
the expected results. However, if for some reason you first boot into
rescue.target, then do some stuff for 10 minutes and then run systemctl
isolate default.target, the timer will fire immediately while the system
is still in the process of booting, which may not be what you want. On
the other hand, OnTransactionFinishedSec= will only start counting once
you reach the transaction that started the timer, which usually would be
the boot transaction (if timer is in default.target) but could also be
the isolate transaction in the above scenario.

Anyway, I hope I've provided a rationale why this can be a useful
feature to have in systemd. The patch will follow in a reply to this mail.

Regards,
Christian
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Jóhann B. Guðmundsson

On 09/27/2012 08:33 AM, Christian Seiler wrote:

one of the most-requested features that is not present in systemd
currently is a true rc.local-type functionality that runs after all
other services.


Any particular reason why those user just dont create type oneshot unit 
then order it as they see fit with after and or before?


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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Frederic Crozat
Le jeudi 27 septembre 2012 à 11:07 +, Jóhann B. Guðmundsson a
écrit :
 On 09/27/2012 08:33 AM, Christian Seiler wrote:
  one of the most-requested features that is not present in systemd
  currently is a true rc.local-type functionality that runs after all
  other services.
 
 Any particular reason why those user just dont create type oneshot unit 
 then order it as they see fit with after and or before?

Mostly because many users have no idea after which units they should
schedule their target. And they are used to having a run as last
script in their distribution (see
https://bugzilla.novell.com/show_bug.cgi?id=778715 which links to
openSUSE forum on this topic).

-- 
Frederic Crozat fcro...@suse.com
SUSE

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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Reindl Harald


Am 27.09.2012 13:07, schrieb Jóhann B. Guðmundsson:
 On 09/27/2012 08:33 AM, Christian Seiler wrote:
 one of the most-requested features that is not present in systemd
 currently is a true rc.local-type functionality that runs after all
 other services.
 
 Any particular reason why those user just dont create type oneshot unit then 
 order it as they see fit with after
 and or before?

because systemd is the software who knows the complete ordering
of all services and could easily decide what is after
independent of which servcies are active now and maybe installed
later and has to be added manually after install them?



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Christian Seiler

Am 27.09.2012 12:07, schrieb Jóhann B. Guðmundsson:

On 09/27/2012 08:33 AM, Christian Seiler wrote:

one of the most-requested features that is not present in systemd
currently is a true rc.local-type functionality that runs after all
other services.


Any particular reason why those user just dont create type oneshot
unit then order it as they see fit with after and or before?


Let's say I have a couple of servers lying around, each with different
services installed. Now I want to distribute a single unit file that is
always run at the end sending me an email that the system has rebooted
and sending me all log messages generated in the boot process so I can
see if everything went correctly. Obviously, I can add lots and lots of
different units to After= of that service, but as soon as some other
service is added to the list, I have to adjust it. Also, the After=
dependency isn't really correct here: Such a script doesn't
specifically depend on e.g. After=apache.service (it doesn't really
care about that) but rather something that should run at a certain
time, thus the idea of using a timer for this feature.

Christian

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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Colin Guthrie
'Twas brillig, and Christian Seiler at 27/09/12 09:33 did gyre and gimble:
 Hello,
 
 one of the most-requested features that is not present in systemd
 currently is a true rc.local-type functionality that runs after all
 other services.
 
 I haven't read all past discussions, but from what I've gathered the
 main objection from the systemd developers is that having a catch-all
 After=* dependency would not be the sane thing to do.

Can you just use a Type=idle unit?

From man systemd.service:

  Behavior of idle is very similar to simple, however actual execution
of a the service binary is delayed
  until all jobs are dispatched. This may be used to avoid interleaving
of output of shell services with the
  status output on the console.


This isn't necessarily guaranteed to be last but I think it would
generally be the case... unless I've misunderstood it.

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited http://www.tribalogic.net/
Open Source:
  Mageia Contributor http://www.mageia.org/
  PulseAudio Hacker http://www.pulseaudio.org/
  Trac Hacker http://trac.edgewall.org/

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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Christian Seiler

I haven't read all past discussions, but from what I've gathered the
main objection from the systemd developers is that having a 
catch-all

After=* dependency would not be the sane thing to do.


Can you just use a Type=idle unit?

From man systemd.service:

  Behavior of idle is very similar to simple, however actual 
execution

of a the service binary is delayed
  until all jobs are dispatched. This may be used to avoid 
interleaving

of output of shell services with the
  status output on the console.


The problem here is that a Type=idle service is basically a type=simple
service and you might want to have Type=forking or Type=oneshot 
services

which you want to start.

Also, my patch is more generic - it allows an arbitrary time to pass
before actually running the event. My patch basically implements
Type=idle for timers.


This isn't necessarily guaranteed to be last but I think it would
generally be the case... unless I've misunderstood it.


Sure, there's no guarantee that it is the last, since all are executed
in parallel - just like Type=idle services.

Christian

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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Christian Seiler

If you want to run a script in the very end of everything you simply
order it after the default target as in

[Unit]
Description=My custom script
After=default.target

[Service]
Type=oneshot
ExecStart=/path/to/my/custom/script

[Install]
WantedBy=default.target


Hmmm, I remember vaguely that this didn't produce the desired results
for some people and that there's a reason why Fedora's rc-local.service
only uses the SysVPriority=99 hack and not After=default.target.

But perhaps I'm wrong, I'll look into that.

Christian

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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Jóhann B. Guðmundsson

On 09/27/2012 11:17 AM, Frederic Crozat wrote:

Le jeudi 27 septembre 2012 à 11:07 +, Jóhann B. Guðmundsson a
écrit :

On 09/27/2012 08:33 AM, Christian Seiler wrote:

one of the most-requested features that is not present in systemd
currently is a true rc.local-type functionality that runs after all
other services.

Any particular reason why those user just dont create type oneshot unit
then order it as they see fit with after and or before?

Mostly because many users have no idea after which units they should
schedule their target. And they are used to having a run as last
script in their distribution


Ordering it after the default target should suffice.

In Fedora we still support rc.local we just dont ship it by default so 
if you want/prefer the old behavior.

you only need to create it and set it up correctly as in

# echo '#!/bin/sh'  /etc/rc.d/rc.local  chmod 755 /etc/rc.d/rc.local

and systemd will pick it but it wont give you the same flexibility as 
native systemd units can do.



  (see
https://bugzilla.novell.com/show_bug.cgi?id=778715 which links to
openSUSE forum on this topic).



Out of the four forum samples in comment 2 on this bug, 3 of the forum 
post ( from the look of it ) are workarounds for genuine bugs and one 
should belong in a rule-*/route-* files under /etc/sysconfig/network 
which would be picked up by networking scripts ( given that suse 
networking scripts support that ) .


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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Frederic Crozat
Le jeudi 27 septembre 2012 à 12:55 +, Jóhann B. Guðmundsson a
écrit :
 On 09/27/2012 11:17 AM, Frederic Crozat wrote:
  Le jeudi 27 septembre 2012 à 11:07 +, Jóhann B. Guðmundsson a
  écrit :
  On 09/27/2012 08:33 AM, Christian Seiler wrote:
  one of the most-requested features that is not present in systemd
  currently is a true rc.local-type functionality that runs after all
  other services.
  Any particular reason why those user just dont create type oneshot unit
  then order it as they see fit with after and or before?
  Mostly because many users have no idea after which units they should
  schedule their target. And they are used to having a run as last
  script in their distribution
 
 Ordering it after the default target should suffice.

I tested that a loong time ago and it wasn't working as expected (but I
should re-test that).

 In Fedora we still support rc.local we just dont ship it by default so 
 if you want/prefer the old behavior.

We also have boot.local (which is equivalent to rc.local) and correctly
handled by systemd.

(see
  https://bugzilla.novell.com/show_bug.cgi?id=778715 which links to
  openSUSE forum on this topic).
 
 
 Out of the four forum samples in comment 2 on this bug, 3 of the forum 
 post ( from the look of it ) are workarounds for genuine bugs and one 
 should belong in a rule-*/route-* files under /etc/sysconfig/network 
 which would be picked up by networking scripts ( given that suse 
 networking scripts support that ) .

I didn't had time to reply to this bug, yet. I think we (systemd
community) need to improve documentation for people who need to write
workarounds (or whatever we call them) and were used to after.local (or
whatever it is called in various distributions).

-- 
Frederic Crozat fcro...@suse.com
SUSE

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


Re: [systemd-devel] Have timers fire after boot is complete

2012-09-27 Thread Tomasz Torcz
On Thu, Sep 27, 2012 at 01:43:34PM +0100, Christian Seiler wrote:
 
 The problem here is that a Type=idle service is basically a type=simple
 service and you might want to have Type=forking or Type=oneshot
 services
 which you want to start.

 Maybe sometimes like:
[Service]
Type=idle
RemainAfterExit=yes
ExecStart=/usr/bin/systemctl start iamlate.target

And create this simple iamlate.target and have your after everything services
and scripts have WantedBy=iamlate.target?

-- 
Tomasz Torcz   Never underestimate the bandwidth of a station
xmpp: zdzich...@chrome.plwagon filled with backup tapes. -- Jim Gray

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