Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
swap on iSCSI, auto-start with systemd
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
mounty1
l33t
l33t


Joined: 06 Jul 2006
Posts: 942
Location: Queensland

PostPosted: Wed Jan 26, 2022 5:49 am    Post subject: swap on iSCSI, auto-start with systemd Reply with quote

I'm trying to get a swap running via iSCSI and hitting the usual barriers with systemd. After this question I found that according to the documentation, you can't specify unit dependencies in /etc/fstab, so it is necessary to write a swap unit file. First I tried:
cat /etc/systemd/system/'dev-disk-by\x2dlabel-swap:Kelvin.swap':
# iSCSI swap device;  start after iscsi.service

[Unit]
#Requires=iscsi.service
WantedBy=default.target
WantedBy=graphical.target
WantedBy=multi-user.target

[Install]
#Requires=iscsi.service
WantedBy=default.target
WantedBy=graphical.target
WantedBy=multi-user.target

[Swap]
What=/dev/disk/by-label/swap:Kelvin
Options=_netdev,nofail
TimeoutSec=20
I couldn't work-out whether the dependencies should be under [Unit] or [Install] but never mind.

The above unit file is enabled with
Code:
systemctl enable 'dev-disk-by\x2dlabel-swap:Kelvin.swap'
but as this screenshot shows, it causes systemd to wait for the device before it is available. Immediately after the last line in the photo times-out, iscsi.service runs, and creates the devices.

I know the Requires lines in the unit file are commented-out but it makes no difference if they are not.

There is no swap line in /etc/fstab.

If after logging-in I run
Code:
systemctl start 'dev-disk-by\x2dlabel-swap:Kelvin.swap'
the swap is instantly added.

It seemed pretty clear to me that the unit is being run/elaborated too early, before iscsi.service has run. Again: it makes no difference if the Requires lines are not commented-out. Another explanation is that systemd groups all .swap units together and elaborates them early, ignoring any dependency specifications. In the usual style of systemd,
there are no obvious error messages to give a hint about what's going wrong.

So I decided to circumvent all the swap stuff and set up the iSCSI swap as a normal service:
cat /etc/systemd/system/iscsi-swap\@.service:
# iSCSI swap device;  start after iscsi.service

[Install]
WantedBy=default.target graphical.target multi-user.target

[Unit]
Requires=iscsi.service dev-disk-by\x2dlabel-swap:%I.device
After=iscsi.service dev-disk-by\x2dlabel-swap:%I.device

[Service]
ExecStart=/sbin/swapon /dev/disk/by-label/swap:%I
ExecStop=/sbin/swapoff /dev/disk/by-label/swap:%I
but it still won't wait:
systemctl status iscsi-swap@Kelvin:
 iscsi-swap@Kelvin.service
     Loaded: loaded (/etc/systemd/system/iscsi-swap@.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Wed 2022-01-26 18:36:54 AEST; 1min 30s ago
    Process: 360 ExecStart=/sbin/swapon /dev/disk/by-label/swap:Kelvin (code=exited, status=255/EXCEPTION)
   Main PID: 360 (code=exited, status=255/EXCEPTION)
        CPU: 1ms

Jan 26 18:36:54 Farenheit systemd[1]: Started iscsi-swap@Kelvin.service.
Jan 26 18:36:54 Farenheit swapon[360]: swapon: cannot open /dev/disk/by-label/swap:Kelvin: No such file or directory
Jan 26 18:36:54 Farenheit systemd[1]: iscsi-swap@Kelvin.service: Main process exited, code=exited, status=255/EXCEPTION
Jan 26 18:36:54 Farenheit systemd[1]: iscsi-swap@Kelvin.service: Failed with result 'exit-code'.
even though
Code:
systemctl restart iscsi-swap@Kelvin
works instantly. So what now?
_________________
Michael Mounteney
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum