Re: [systemd-devel] Help: Questions regarding systemd service order
On Tue, Nov 12, 2024 at 1:13 PM Tony Rodriguez wrote: > > B) How can I make my service run after all .mount(s) within > local-fs-pre.target, before local-fs.target, especially if I don't know > all the .mount(s)? The .mount files are located within > /var/run/systemd/generator/* > > ls -l /var/run/systemd/generator/*.mount > -rw-r--r-- 1 root root 390 Nov 12 00:59 > /var/run/systemd/generator/boot-efi.mount > -rw-r--r-- 1 root root 449 Nov 12 00:59 > /var/run/systemd/generator/boot.mount > -rw-r--r-- 1 root root 428 Nov 12 00:59 > /var/run/systemd/generator/home.mount > -rw-r--r-- 1 root root 239 Nov 12 00:59 /var/run/systemd/generator/-.mount > -rw-r--r-- 1 root root 424 Nov 12 00:59 /var/run/systemd/generator/tmp.mount > -rw-r--r-- 1 root root 241 Nov 12 00:59 /var/run/systemd/generator/usr.mount > -rw-r--r-- 1 root root 424 Nov 12 00:59 /var/run/systemd/generator/var.mount > > -rw-r--r-- 1 root root 424 Nov 12 00:59 > /var/run/systemd/generator/test.mount > > > Appears the UNIT section doesn't support a wildcard for .mount(s) > You can have a drop-in under e.g. /ets/systemd/system/-.mount.d. It will apply to *all* mount points. You could add a generator that explicitly adds needed dependency to every filesystem in /etc/fstab if you want to exclude some mount points. > This doesn't work > > #After=local-fs-pre.target *.mount > > The following works, but have to hard code mounts. Would like to > dynamically populate mounts for "After=" within my service file. > > After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount > var.mount tmp.mount home.mount > Before=local-fs.target > > [Unit] > Description=mytest.service > DefaultDependencies=no > Wants=local-fs-pre.target > After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount > var.mount tmp.mount home.mount test.mount > Before=local-fs.target >
Re: [systemd-devel] Help: Questions regarding systemd service order
Am Dienstag, dem 12.11.2024 um 02:13 -0800 schrieb Tony Rodriguez: > ``` > Hoping I can accomplish the following via a simple UNIT modification or > service script? > > > Questions: > > A) How can my service always runs "last" within local-fs-pre.target? > > For Example: > > Need my service to always run last within the local-fs-pre.target, even > if others add another services later within local-fs-pre.target. Still > want my service to always run last within this local-fs-pre.target. > > Note: I will not know services others may later add within the > local-fs-pre.target > > > B) How can I make my service run after all .mount(s) within > local-fs-pre.target, before local-fs.target, especially if I don't know > all the .mount(s)? The .mount files are located within > /var/run/systemd/generator/* > > ls -l /var/run/systemd/generator/*.mount > -rw-r--r-- 1 root root 390 Nov 12 00:59 > /var/run/systemd/generator/boot-efi.mount > -rw-r--r-- 1 root root 449 Nov 12 00:59 > /var/run/systemd/generator/boot.mount > -rw-r--r-- 1 root root 428 Nov 12 00:59 > /var/run/systemd/generator/home.mount > -rw-r--r-- 1 root root 239 Nov 12 00:59 /var/run/systemd/generator/-.mount > -rw-r--r-- 1 root root 424 Nov 12 00:59 /var/run/systemd/generator/tmp.mount > -rw-r--r-- 1 root root 241 Nov 12 00:59 /var/run/systemd/generator/usr.mount > -rw-r--r-- 1 root root 424 Nov 12 00:59 /var/run/systemd/generator/var.mount > > -rw-r--r-- 1 root root 424 Nov 12 00:59 > /var/run/systemd/generator/test.mount > > > Appears the UNIT section doesn't support a wildcard for .mount(s) > > This doesn't work > > #After=local-fs-pre.target *.mount > > The following works, but have to hard code mounts. Would like to > dynamically populate mounts for "After=" within my service file. > > After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount > var.mount tmp.mount home.mount > Before=local-fs.target > > [Unit] > Description=mytest.service > DefaultDependencies=no > Wants=local-fs-pre.target > After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount > var.mount tmp.mount home.mount test.mount > Before=local-fs.target > ``` Hi Tony, there is no "last", because every dependency can exists multiple times, but you can't have multiple "last". Doesn't make sense. My suggestion would either be (via ) or [RequiresMountsFor=](man:systemd.unit). For further help we would need to know what you actually want to achieve with your unit. BR Silvio
Re: [systemd-devel] Help: Questions regarding systemd service order
On Tue, Nov 12, 2024 at 12:13 PM Tony Rodriguez wrote: > Hoping I can accomplish the following via a simple UNIT modification or > service script? > > > Questions: > > A) How can my service always runs "last" within local-fs-pre.target? > > For Example: > > Need my service to always run last within the local-fs-pre.target, even > if others add another services later within local-fs-pre.target. Still > want my service to always run last within this local-fs-pre.target. > > Note: I will not know services others may later add within the > local-fs-pre.target > Systemd deliberately doesn't have a definite concept of "last" or "first". (More importantly, what happens if another service also wants to be "last"?) It's specifically the purpose of targets themselves to be used as barriers. Instead of "After=*.mount" you would have "After=local-fs.target" because all those mounts are in local-fs.target. > > > B) How can I make my service run after all .mount(s) within > local-fs-pre.target, before local-fs.target, especially if I don't know > all the .mount(s)? The .mount files are located within > /var/run/systemd/generator/* > > ls -l /var/run/systemd/generator/*.mount > -rw-r--r-- 1 root root 390 Nov 12 00:59 > /var/run/systemd/generator/boot-efi.mount > -rw-r--r-- 1 root root 449 Nov 12 00:59 > /var/run/systemd/generator/boot.mount > -rw-r--r-- 1 root root 428 Nov 12 00:59 > /var/run/systemd/generator/home.mount > -rw-r--r-- 1 root root 239 Nov 12 00:59 /var/run/systemd/generator/-.mount > -rw-r--r-- 1 root root 424 Nov 12 00:59 > /var/run/systemd/generator/tmp.mount > -rw-r--r-- 1 root root 241 Nov 12 00:59 > /var/run/systemd/generator/usr.mount > -rw-r--r-- 1 root root 424 Nov 12 00:59 > /var/run/systemd/generator/var.mount > > -rw-r--r-- 1 root root 424 Nov 12 00:59 > /var/run/systemd/generator/test.mount > > > Appears the UNIT section doesn't support a wildcard for .mount(s) > > This doesn't work > > #After=local-fs-pre.target *.mount > > The following works, but have to hard code mounts. Would like to > dynamically populate mounts for "After=" within my service file. > > After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount > var.mount tmp.mount home.mount > Before=local-fs.target > > [Unit] > Description=mytest.service > DefaultDependencies=no > Wants=local-fs-pre.target > After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount > var.mount tmp.mount home.mount test.mount > Before=local-fs.target > > How come your home.mount is in local-fs-pre? That is exactly the kind of mount that would be in local-fs. In fact, why do you have *any* mounts in local-fs-pre? -- Mantas Mikulėnas
[systemd-devel] Help: Questions regarding systemd service order
Hoping I can accomplish the following via a simple UNIT modification or service script? Questions: A) How can my service always runs "last" within local-fs-pre.target? For Example: Need my service to always run last within the local-fs-pre.target, even if others add another services later within local-fs-pre.target. Still want my service to always run last within this local-fs-pre.target. Note: I will not know services others may later add within the local-fs-pre.target B) How can I make my service run after all .mount(s) within local-fs-pre.target, before local-fs.target, especially if I don't know all the .mount(s)? The .mount files are located within /var/run/systemd/generator/* ls -l /var/run/systemd/generator/*.mount -rw-r--r-- 1 root root 390 Nov 12 00:59 /var/run/systemd/generator/boot-efi.mount -rw-r--r-- 1 root root 449 Nov 12 00:59 /var/run/systemd/generator/boot.mount -rw-r--r-- 1 root root 428 Nov 12 00:59 /var/run/systemd/generator/home.mount -rw-r--r-- 1 root root 239 Nov 12 00:59 /var/run/systemd/generator/-.mount -rw-r--r-- 1 root root 424 Nov 12 00:59 /var/run/systemd/generator/tmp.mount -rw-r--r-- 1 root root 241 Nov 12 00:59 /var/run/systemd/generator/usr.mount -rw-r--r-- 1 root root 424 Nov 12 00:59 /var/run/systemd/generator/var.mount -rw-r--r-- 1 root root 424 Nov 12 00:59 /var/run/systemd/generator/test.mount Appears the UNIT section doesn't support a wildcard for .mount(s) This doesn't work #After=local-fs-pre.target *.mount The following works, but have to hard code mounts. Would like to dynamically populate mounts for "After=" within my service file. After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount var.mount tmp.mount home.mount Before=local-fs.target [Unit] Description=mytest.service DefaultDependencies=no Wants=local-fs-pre.target After=local-fs-pre.target boot.mount boot-efi.mount -.mount usr.mount var.mount tmp.mount home.mount test.mount Before=local-fs.target
