My fstab contains the following entry for the network share:
//192.168.7.1/sd /home/userx/Public/.sd cifs _netdev,soft,rw,exec,guest,uid=1001,gid=998,file_mode=0755,dir_mode=0755,vers=3.0,nofail,│
echo_interval=5,actimeo=10 0 0
It works great when running "mount -a" as normal user without sudo after reboot, but same command does not work in @reboot cronjob as it requires sudo. I've tried chatgpt but it always suggest to create a runit service for this.
What is the best way to achieve this in Artix?
Put the same cronjob mount command in /etc/rc.local.
I was assuming rc.local cannot work since the internet runit services such as NetworkManager are not ready yet when it runs. Will try that next thanks.
@Shoun2137 unfortunately adding /usr/bin/mount -a to rc.local does not work, I believe for the reason mentioned above.
Not if it's a root cronjob.
It runs last, on openrc at least, so maybe added a small sleep might help if it really is a race condition ?
@gripped even after adding a 10 seconds sleep in front of it in rc.local, there is still no automount after login:
/usr/bin/sleep 10
/usr/bin/mount -a
I'd check if rc.local is running at all by putting something like
touch /tmp/test-rc.local
in there and checking for it's existence after a reboot.
rc.local is working great, in fact it solved a separate issue I've raised, of mounting a second nvme: https://forum.artixlinux.org/index.php/topic,8532.0.html (https://forum.artixlinux.org/index.php/topic,8532.0.html)
It is mounting my second nvme without problems and the sleep command delays the start for 10 seconds as well, but the mount command just does not work for the network share at all when in rc.local.
Is anything like the "network" service set included in s6 provided for runit? Hooking a `mount -O _netdev` there could work.
Failing that, hooking into a networking service would work. I know dhcpcd (https://man.archlinux.org/man/dhcpcd-run-hooks.8) can do that.
Or making a runit service that, idk, pings every few seconds until it succeeds, mounts the network shares, then execs pause.
There must be a simpler way of doing this. I only need the mount command to run in a @reboot cronjob somehow...
Unless you have the logs to back it up, I doubt it's related to permissions. Both cronie and fcron run as root and don't drop privileges for cronjobs on the root crontab. I'm able to use commands that require root just fine (such as chpst -u, writing to root-owned folders, etc.) here.
You can set up nopasswd rules using visudo (https://www.man7.org/linux/man-pages/man5/sudoers.5.html) so whatever user your cronjobs are running as can call mount.
If cronjobs are running as root (or another user able to mount the network share) and failing due to no network, then you can't avoid scripting a network wait. It can probably be done with a loop in the cronjob itself.
Plug this into
/etc/rc.local just to test if this isnt a fault of
mount -a, because if this is defined in fstab, this shouldve been mounted regardless:
#!/bin/sh
while : ; do
if df | grep -q '/home/userx/Public/.sd' ; then
exit 0
fi
mount -t cifs "//192.168.7.1/sd" "/home/userx/Public/.sd" -o rw,exec,guest,uid=1001,gid=998,file_mode=0755,dir_mode=0755,vers=3.0,soft,echo_interval=5,actimeo=10
sleep 5
done