[opensuse-factory] systemd and unit dependencies: How to ensure a script is completed before login prompts or X are started?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear all, second systemd question: I need to change the boot process on one of my machines. I added a backup job, that takes a while. To avoid errors, I'd like to get the system to wait until the script is finished, before showing login prompts or the display manager. The script itself looks something like this: - ----------------
[Unit] Description="some description" ConditionFileIsExecutable=/path/to/script.sh After=basic.target
[Service] Type=oneshot ExecStart=/path/to/script.sh TimeoutSec=0 RemainAfterExit=yes
[Install] WantedBy=getty.target
I rtfm'ed that I have to add a Requires:-line to one of the later units, to get that unit to really wait for the script (or rather override the definition of that unit, but that is the first question in a separate mail... ;-) ). Which units would I have to change to get the login prompts and the display manager to wait? I tried some, including display-manager.service, but still I get an X-Server very early. The login prompts are appearing long after the X-server started, but the script might still be running (shown in process list). Thanks in advance! Regards, Johannes - -- Multiple exclamation marks are a sure sign of diseased mind. (Terry Pratchett) -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with SeaMonkey - http://www.enigmail.net/ iEYEARECAAYFAlTw6PMACgkQzi3gQ/xETbJNWgCfRgVGKDpB23Y54caukF//2Ev7 WBIAn1zNUDe8DgV0ydmOcYVdBRV9GuiX =+Cgy -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Fri, Feb 27, 2015 at 7:00 PM, Johannes Kastl <mail@ojkastl.de> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Dear all,
second systemd question:
I need to change the boot process on one of my machines. I added a backup job, that takes a while. To avoid errors, I'd like to get the system to wait until the script is finished, before showing login prompts or the display manager.
The script itself looks something like this: - ----------------
[Unit] Description="some description" ConditionFileIsExecutable=/path/to/script.sh After=basic.target
[Service] Type=oneshot ExecStart=/path/to/script.sh TimeoutSec=0 RemainAfterExit=yes
[Install] WantedBy=getty.target
Make the service of Type=notify , execute systemd-notify --ready when the task has completed and then exit 0; Make the display-manager.service start After=yourservice.. Note that if your service takes a while, it might timeout, so you need to adjust the timeouts accordingly, or better.. find a way that does not require this hack. -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 28.02.2015 Cristian Rodríguez wrote:
Make the service of Type=notify , execute systemd-notify --ready when the task has completed and then exit 0; Make the display-manager.service start After=yourservice..
Forgive me if I ask: My setup seems to work with type=oneshot. What is the advantage of using notify? I just found descriptions, that this type exists, but found no advantages or disadvantages.
Note that if your service takes a while, it might timeout, so you need to adjust the timeouts accordingly, or better.. find a way that does not require this hack.
I thought "TimeoutSec=0" (or 600 or ...) was exactly for this kind of long running commands? What would be the other options, apart from not doing a backup that takes its time? ;-) Regards, Johannes - -- Lupin burst out laughing. `Sometimes you remind me a lot of James. He called it my 'furry little problem' in company. Many people were under the impression that I owned a badly behaved rabbit.´ (Remus Lupin in Harry Potter and the Half-Blood Prince) -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with SeaMonkey - http://www.enigmail.net/ iEYEARECAAYFAlTxomIACgkQzi3gQ/xETbItRgCfUyaqbhkGmtbFuF+sZI4u+VHB s2EAniNweJoSxlHuOdzjI6BFemJ7b04N =j6t3 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
On Sat, Feb 28, 2015 at 8:11 AM, Johannes Kastl <mail@ojkastl.de> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 28.02.2015 Cristian Rodríguez wrote:
Make the service of Type=notify , execute systemd-notify --ready when the task has completed and then exit 0; Make the display-manager.service start After=yourservice..
Forgive me if I ask:
My setup seems to work with type=oneshot. What is the advantage of using notify? I just found descriptions, that this type exists, but found no advantages or disadvantages.
In this case, the services ordered After= your custom service will not start until it PID1 gets notifed that the startup of your service is complete.
Note that if your service takes a while, it might timeout, so you need to adjust the timeouts accordingly, or better.. find a way that does not require this hack.
I thought "TimeoutSec=0" (or 600 or ...) was exactly for this kind of long running commands?
TimeoutStartSec= in this case. -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
В Sun, 1 Mar 2015 01:55:50 -0300 Cristian Rodríguez <crrodriguez@opensuse.org> пишет:
On Sat, Feb 28, 2015 at 8:11 AM, Johannes Kastl <mail@ojkastl.de> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 28.02.2015 Cristian Rodríguez wrote:
Make the service of Type=notify , execute systemd-notify --ready when the task has completed and then exit 0; Make the display-manager.service start After=yourservice..
Forgive me if I ask:
My setup seems to work with type=oneshot. What is the advantage of using notify? I just found descriptions, that this type exists, but found no advantages or disadvantages.
In this case, the services ordered After= your custom service will not start until it PID1 gets notifed that the startup of your service is complete.
This is oneshot service - systemd waits until it is *finished* before starting dependent services.
Note that if your service takes a while, it might timeout, so you need to adjust the timeouts accordingly, or better.. find a way that does not require this hack.
I thought "TimeoutSec=0" (or 600 or ...) was exactly for this kind of long running commands?
TimeoutStartSec= in this case.
But it is disabled for oneshot services anyway. -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01.03.2015 Andrei Borzenkov wrote:
В Sun, 1 Mar 2015 01:55:50 -0300 Cristian Rodríguez <crrodriguez@opensuse.org> пишет:
[advantages/disadvantages of type=notify over type=oneshot]
In this case, the services ordered After= your custom service will not start until it PID1 gets notifed that the startup of your service is complete.
Which is what I want to achieve. And what oneshot does, too, right?
This is oneshot service - systemd waits until it is *finished* before starting dependent services.
I'm confused.
I thought "TimeoutSec=0" (or 600 or ...) was exactly for this kind of long running commands?
TimeoutStartSec= in this case.
But it is disabled for oneshot services anyway.
More confused. For the record, or the next one as confused as I am, this worked (where foobar.service is my service of type oneshot): - -----------------------
$systemctl cat display-manager.service # /usr/lib/systemd/system/display-manager.service [Unit] Description=X Display Manager Requires=var-run.mount After=ypbind.service gpm.service time-sync.target winbind.service acpid.service Wants=remote-fs.target dbus.socket systemd-user-sessions.service After=remote-fs.target dbus.socket systemd-user-sessions.service
[Service] Type=forking PIDFile=/var/run/displaymanager.pid ExecStart=/usr/lib/X11/display-manager start ExecStop=/usr/lib/X11/display-manager stop ExecReload=/usr/lib/X11/display-manager reload KillMode=process
[Install] WantedBy=graphical.target Alias=xdm.service
# /etc/systemd/system/display-manager.service.d/wait_for_foobar.conf [Unit] Requires=foobar.service After=remote-fs.target dbus.socket systemd-user-sessions.service foobar.service
$systemctl cat foobar.service [Unit] Description="foobar" ConditionFileIsExecutable=/path/to/script.sh After=basic.target
[Service] Type=oneshot ExecStart=/path/to/script.sh TimeoutSec=0 RemainAfterExit=yes
[Install] WantedBy=multi-user.target
Regards, Johannes - -- Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. (Groucho Marx) -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with SeaMonkey - http://www.enigmail.net/ iEYEARECAAYFAlTytWgACgkQzi3gQ/xETbI+4ACfa3NRRbIc+v4y/B+jAHnZ5moa pycAmwfrYoWiMDuDQGjHJALRckJI/aPh =GTT/ -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 В Sun, 01 Mar 2015 07:45:02 +0100 Johannes Kastl <mail@ojkastl.de> пишет:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 01.03.2015 Andrei Borzenkov wrote:
В Sun, 1 Mar 2015 01:55:50 -0300 Cristian Rodríguez <crrodriguez@opensuse.org> пишет:
[advantages/disadvantages of type=notify over type=oneshot]
In this case, the services ordered After= your custom service will not start until it PID1 gets notifed that the startup of your service is complete.
Which is what I want to achieve. And what oneshot does, too, right?
No. For oneshot services systemd starts service and waits until it is finishes before continuing with any other service that depends on it. It is difference between starting long running background services and doing one time job.
This is oneshot service - systemd waits until it is *finished* before starting dependent services.
I'm confused.
What about? Behavior of oneshot is similar to simple; however, it is expected that the process has to exit before systemd starts follow-up units. What is confusing here?
I thought "TimeoutSec=0" (or 600 or ...) was exactly for this kind of long running commands?
TimeoutStartSec= in this case.
But it is disabled for oneshot services anyway.
More confused.
TimeoutStartSec= ... Defaults to TimeoutStartSec= from the manager configuration file, except when Type=oneshot is used, in which case the timeout is disabled by default.
For the record, or the next one as confused as I am, this worked (where foobar.service is my service of type oneshot):
- -----------------------
$systemctl cat display-manager.service # /usr/lib/systemd/system/display-manager.service [Unit] Description=X Display Manager Requires=var-run.mount After=ypbind.service gpm.service time-sync.target winbind.service acpid.service Wants=remote-fs.target dbus.socket systemd-user-sessions.service After=remote-fs.target dbus.socket systemd-user-sessions.service
[Service] Type=forking PIDFile=/var/run/displaymanager.pid ExecStart=/usr/lib/X11/display-manager start ExecStop=/usr/lib/X11/display-manager stop ExecReload=/usr/lib/X11/display-manager reload KillMode=process
[Install] WantedBy=graphical.target Alias=xdm.service
# /etc/systemd/system/display-manager.service.d/wait_for_foobar.conf [Unit] Requires=foobar.service After=remote-fs.target dbus.socket systemd-user-sessions.service foobar.service
$systemctl cat foobar.service [Unit] Description="foobar" ConditionFileIsExecutable=/path/to/script.sh After=basic.target
[Service] Type=oneshot ExecStart=/path/to/script.sh TimeoutSec=0 RemainAfterExit=yes
[Install] WantedBy=multi-user.target
Regards, Johannes - -- Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read. (Groucho Marx) -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with SeaMonkey - http://www.enigmail.net/
iEYEARECAAYFAlTytWgACgkQzi3gQ/xETbI+4ACfa3NRRbIc+v4y/B+jAHnZ5moa pycAmwfrYoWiMDuDQGjHJALRckJI/aPh =GTT/ -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlTyvEgACgkQR6LMutpd94ypcACfezsAIZktXiBwy9ONxeAwYcHc TwcAn1AHThwozlbHqloml0DKe1Ar1yeR =GPFd -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01.03.2015 Andrei Borzenkov wrote:
No. For oneshot services systemd starts service and waits until it is finishes before continuing with any other service that depends on it.
And for notify it waits for the notify before starting other services. At least that is how I understood Cristian's statement.
It is difference between starting long running background services and doing one time job.
What is confusing here?
I'll try to get this straight: With oneshot, systemd waits for the task to *exit* before starting other services that Require/Want/After this task. With notify, systemd waits until it gets notified before starting these tasks. Right so far? In my use case, a long running backup, I could do the notify at the end, when my backup is finished. But the end result would be the same, the following tasks would start when my backup is finished. So I do not see the advantage of using one over the other.
TimeoutStartSec= ... Defaults to TimeoutStartSec= from the manager configuration file, except when Type=oneshot is used, in which case the timeout is disabled by default.
Andrei, these are all very fine and I thank both you and Cristian for your answers. But I still don't get why Cristian would call setting a Timeout (no matter which one) as a hack. Regards, Johannes - -- "NOBODY expects the Spanish Inquisition! Our chief weapon is surprise ... surprise and fear ... fear and surprise ... Our two weapons are fear and surprise ... and ruthless efficiency ... Our *three* weapons are fear, surprise, and ruthless efficiency..." (Monthy Python) -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with SeaMonkey - http://www.enigmail.net/ iEYEARECAAYFAlTywA8ACgkQzi3gQ/xETbLPNACfQBBsB8VPmZQuV4I4nmBVwU1b ibEAn2Vn9alQnIV63PhMSk0rhVFqrYuM =XyZt -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 В Sun, 01 Mar 2015 08:30:29 +0100 Johannes Kastl <mail@ojkastl.de> пишет:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 01.03.2015 Andrei Borzenkov wrote:
No. For oneshot services systemd starts service and waits until it is finishes before continuing with any other service that depends on it.
And for notify it waits for the notify before starting other services. At least that is how I understood Cristian's statement.
It is difference between starting long running background services and doing one time job.
What is confusing here?
I'll try to get this straight:
With oneshot, systemd waits for the task to *exit* before starting other services that Require/Want/After this task.
With notify, systemd waits until it gets notified before starting these tasks.
Right so far?
In my use case, a long running backup, I could do the notify at the end, when my backup is finished. But the end result would be the same, the following tasks would start when my backup is finished.
So I do not see the advantage of using one over the other.
"oneshot" does not require useless program modification and conveys clear meaning that this is one time job. Otherwise as usual there are many ways to skin a cat. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlTyxeIACgkQR6LMutpd94zRSACePZnhofkVtZMLfALqyGS/LwME Y9wAoJINVuM3H1S1z7TE2dz8cuIX+eCG =H2Nm -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 В Fri, 27 Feb 2015 23:00:19 +0100 Johannes Kastl <mail@ojkastl.de> пишет:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Dear all,
second systemd question:
I need to change the boot process on one of my machines. I added a backup job, that takes a while. To avoid errors, I'd like to get the system to wait until the script is finished, before showing login prompts or the display manager.
The script itself looks something like this: - ----------------
[Unit] Description="some description" ConditionFileIsExecutable=/path/to/script.sh After=basic.target
[Service] Type=oneshot ExecStart=/path/to/script.sh TimeoutSec=0 RemainAfterExit=yes
[Install] WantedBy=getty.target
I rtfm'ed that I have to add a Requires:-line to one of the later units, to get that unit to really wait for the script (or rather override the definition of that unit, but that is the first question in a separate mail... ;-) ).
No, you are wrong. Requires does not affect ordering of units (OK, there are some implicit dependencies for target units, but let's this is exception). Ordering of units is specified using Before or After parameters. They are symmetrical - having "After: B" in unit A definition is the same as having "Before: A" in B definition. So you just need to add "Before: some-correct-unit" to your backup service.
Which units would I have to change to get the login prompts and the display manager to wait? I tried some, including display-manager.service, but still I get an X-Server very early. The login prompts are appearing long after the X-server started, but the script might still be running (shown in process list).
If you added "Requires" this is expected :) Try simply adding Before: display-manager.service to your unit. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEUEARECAAYFAlTxYtoACgkQR6LMutpd94zWzgCXQFBHtZ69sRpTev58PTBp4Nji IwCfVO9L/sXEvRk5Xz4UgACf3faWbAs= =jddi -----END PGP SIGNATURE----- N�����r��y隊Z)z{.���r�+�맲��r��z�^�ˬz��N�(�֜��^� ޭ隊Z)z{.���r�+��0�����Ǩ�
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 28.02.2015 Andrei Borzenkov wrote:
Ordering of units is specified using Before or After parameters. They are symmetrical - having "After: B" in unit A definition is the same as having "Before: A" in B definition. So you just need to add "Before: some-correct-unit" to your backup service.
Thanks for the hints, I obviously got the whole After-Before-Requires-Wants-Thingy mixed up. I misread a statement about After and Before being reversed at shutdown, and took that as Before being used for shutdown and After for startup. My bad. Regards, Johannes - -- Elisabeth's safe, just as I promised. And she's going to marry Norrington, just as she promised, and you are going to die for her, just as you promised. So we're all men of our word really, except Elizabeth, who is, in fact, a woman. (Pirates of the Caribbean) -----BEGIN PGP SIGNATURE----- Comment: Using GnuPG with SeaMonkey - http://www.enigmail.net/ iEYEARECAAYFAlTxre4ACgkQzi3gQ/xETbI+pACfVTc8V752SiOhAbf3RdbxMp2C D8kAnRsvADVZgC3NHKNiKgWkGFmzA954 =VM1W -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse-factory+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-factory+owner@opensuse.org
participants (3)
-
Andrei Borzenkov
-
Cristian Rodríguez
-
Johannes Kastl