[systemd-devel] Best practice for prepopulating the CacheDirectory of dynamic users
Lennart Poettering
lennart at poettering.net
Wed Feb 28 17:59:41 UTC 2018
On Mi, 28.02.18 18:22, Antoine Pietri (antoine.pietri1 at gmail.com) wrote:
> On Wed, Feb 28, 2018 at 6:13 PM, Lennart Poettering
> <lennart at poettering.net> wrote:
> >> Okay! Does that also apply to the other possible approach I sent in my
> >> second mail? (Running a `dummy sh -c read` service with systemd-run,
> >> do the setup and kill it when the setup is done). The advantage of
> >> that one is that you can do any arbitrary processing while staying in
> >> the Python code.
> >
> > I am not sure I follow?
>
> If you run from the script:
>
> systemd-run -P -p DynamicUser=yes -p CacheDirectory=mywrapper sh -c read
>
> This will do all the setup with the symlink to /var/cache/private, and
> then just hang. While the process is hanging, you can do the
> processing you need in the cache directory, including populating it
> with whatever you want.
>
> Once your processing is over, you can kill the systemd-run process. On
> subsequent calls to systemd-run, the files you added will just be
> recursively chmod()ed by systemd, so you should just get back the
> directory populated with your files with the correct permissions.
Not sure I follow. Why do you let the service hang around? If all you
want to do is have it create the directory for you you could just run:
# systemd-run -P -p DynamicUser=yes -p CacheDirectory=mywrapper --wait true
That would be synchronous, would set up the dir and immediately
return.
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list