LXC automatic startup and ISCSI mount

Here is my situation, I have a debian stretch host running a few containers, there´s a couple of drives mounted on the host through fstab, and a couple nfs mounts too, many containers have folders from those drives mounted through ‘lxc.mount.entry’, this has worked great so far.
Until I added an ISCSI mount, the problem is that the LXC service starts way before the ISCSI target is mounted, so the containers that have a ‘lxc.mount.entry’ inside that mount fail to start, they do start manually tho.
For now I have a cron @reboot that runs a script with a ‘sleep 45’ before ‘lxc-start mycontainer’, but I think that’s a terrible solution.
What would be the proper way to make sure the LXC service starts only after the ISCSI targets are mounted?
I’ve tried ‘RequiresMountsFor=/mnt/iscsimount’ and ‘ConditionPathIsMountPoint=/mnt/iscsimount’ but those only cause the LXC service to fail and no container is started at all.
Thank you all in advance

Can you make the service that is running the ISCSI mounts run before the LXC service?

You probably want Wants=<iscisi-service> and After=<iscsi-service> in your LXC service then.

1 Like

That’s the idea, although I’m because I don’t know how to do that, and I don’t want to break my system…

I’ll try that asap and report back.

This kind of messing with default settings makes me sweat, I never thought ISCSI mount were so uncommon, I would have thought someone testing ISCSI or LXC should have run in to something like this!

Sadly it didn’t do the trick, just for the sake of clarity, I’m running an up to date version of debian stretch, with the lxc version that comes with it (2.0), the service I’m editing is ‘/lib/systemd/system/lxc.service’ and looks like this:

Description=LXC Container Initialization and Autoboot Code
After=network.target lxc-net.service iscsi-service
Wants=lxc-net.service iscisi-service
Documentation=man:lxc-autostart man:lxc

ExecStart=/usr/lib/x86_64-linux-gnu/lxc/lxc-containers start
ExecStop=/usr/lib/x86_64-linux-gnu/lxc/lxc-containers stop
# Environment=BOOTUP=serial
# Environment=CONSOLETYPE=serial


Which is how it comes by default and I only added the ‘iscisi-service’ in ‘Wants’ and ‘After’.

Also tried After=remote-fs.target to no avail, and I’m running out of ideas…

Is that the name of the iscsi service? In the lines I gave you above <iscsi-service> is supposed to be a placeholder for the actual iscsi service name. You need to figure out what that is and use it instead of the placeholder in the service file.

After another google session, I think the service name is open-iscsi.service, but still doesn’t solve the problem, lxc still starts way before than open-iscsi.service.
I’ve run ‘systemd-analyze plot > test.svg’ and find out that mymountname.mount appears way after lxc.service (33s vs 21s), so I’ve tried again ‘RequiresMountsFor=mymountname.mount’ and ‘ConditionPathIsMountPoint=mymountname.mount’ which did nothing at all.
One detail tho, adding Wants=open-iscsi.service and After=open-iscsi.service made lxc.service start even sooner, instead of after (went from 21s to 7s).
I’m starting to think systemd takes the “wants” and “after” as mere suggestions, and for some reason sometimes just ignores them…