1

I'm working on an embedded linux based on yocto. The system is mounted as read only, and I want to manage applications installed by opkg in a data partition with systemd.

In order to do that, I've created a target, changed the default.target link to point on my own target. That is working, and I can run services installed in the /etc/systemd/system/ folder.

The next step is to run services installed in a folder with a path like /data/etc/systemd/system/.

I've found, in the systemd documentation, the possibility to set the SYSTEMD_UNIT_PATH variable to extend the folders where systemd is looking for services. But after many tests I've not found the way to set properly this variable and systemd never find my service.

Can you help me to resolve this issue ?

Edit : If you have a way to do that without adding it to the kernel command line, that will be perfect.

Thank you.

6
  • try setting it on the kernel command line? Apr 28 '21 at 1:35
  • Is there another way to set this variable ? Changing the kernel command line needs reflash the read only partition... If there is not another way, I'll do that.
    – gilou
    Apr 29 '21 at 7:58
  • If you have an initrd, you might be able to do it in there ... Apr 29 '21 at 11:29
  • I've not an initrd on my distribution, actually. I tried to extend the system unit path by adding systemd.setenv='SYSTEMD_UNIT_PATH=/data/j.local/etc/systemd/system/:' to the kernel command line without success. Do I do something wrong ?
    – gilou
    Apr 30 '21 at 12:55
  • I would have tried just SYSTEMD_UNIT_PATH=/data/j.local/etc/systemd/system/: on its own on the kernel command line ... May 9 '21 at 2:22
0

AFAIK the SYSTEMD_UNIT_PATH variable is obeyed by systemd only when it first starts and then no longer, even if you change it later on through a systemctl set-environment command.

Also, that variable actually does not provide an additional path to look for service files into, it rather functions as a complete override of the standard paths. That is, when you start a systemd instance with that variable set in its environment, that systemd instance will look for service files in that path only, disregarding the usual /etc/systemd and all other lower priority paths.

Technically there might be a couple or three variably complex (and complicated) solutions for your case, but I reckon the best and simplest one by far is to just do like distro vendors do: place your additional service files into /lib/systemd/ and below paths. Essentially that path mirrors the /etc/systemd one, and is meant precisely for vendors to place their own systemd Unit files. After all, for your Yocto project you are the distro vendor.

3
  • Thank you for your reply, my problem is because we mount the base filesystem as read only. After starting our product connect to a server and download a usecase. This usecase install, via opkg, packages in a data partition. I'm now looking to have a way to start and stop services installed in a folder contained in this data partition and not in the root filesystem. I've tried to use a symlink in /etc/systemd/system/ to point to a folder in the data partition without result. Systemd can't find services contained in a subfolder ? Thank you for your help, I will try with the /lib/systemd/ folder.
    – gilou
    Apr 29 '21 at 15:07
  • @gilou systemd only looks in the directories indicated in systemd.unit(5) and those only, it won't go into subfolders therein nor anywhere else. There can (and indeed are) subfolders in there, but only for the so-called "drop-ins", as described in the manpage above. The exact directory that you (as the vendor of your project) are supposed to use for your units is /lib/systemd/system (for system-wide units). See that manpage for details.
    – LL3
    Apr 29 '21 at 21:10
  • Effectively, I've not found a way to start services who are not in a classical folder. I've tried to use a system-generator script to extend the units' path without success.
    – gilou
    Apr 30 '21 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.