[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Aw: Re: systemd automount unit: run only when server is reachable



Hi David,

if I understood you correctly you propose to run a script in the background to check for
the condition I am interested in (is the nfs server available?) and do the changes accordingly.

In fact I am doing this at the moment. But I think its an ugly hack and thought a better solution
should be possible with systemd only. E.g. in my case I have to check the availabilty of the server
every some seconds (same as in your script), while in fact it does need to be checked only in the
case the share is to be mounted. That would be much more elegant and efficient.

Seems systemd is still not used very much actively. I mean most people run it, but they dont write
their own stuff for it. When looking for information on shell scripts, I normally find the solution
on google after 1 min. In case of systemd I googled a long time with no result and even posting to
different mailing lists/forums did not help.

Regards,

Jürgen

> Gesendet: Dienstag, 13. September 2022 um 20:13 Uhr
> Von: "David Wright" <deblis@lionunicorn.co.uk>
> 
> I don't remember the details of the complaint, but there are
> circumstances where systemd kills off jobs that it is controlling.
> 
> You could investigate using cron's @reboot to fire off a number
> of tasks, each mounting one of the shares.
> 
> I use it myself to restart minidlna after I've got around to
> decrypting and mounting /home, which could be any time or not
> at all:
> 
> # crontab -l
> # /root/.cron/crontab-axis last edited 2022-04-25
> # Note that this is root's own crontab so it doesn't need the
> # user field but it does require installing with crontab.
> 
> MAILTO= …
> 
> # check for (dist-)updated packages and provoke an email if any are in the cache
> 0       */3     *       *       *       apt-get -qq -o Acquire::http::Proxy="http://192.168.1.14:3142/"; update && apt-get -qq -d -o Acquire::http::Proxy="http://192.168.1.14:3142/"; dist-upgrade && find /var/cache/apt/archives/ -name '*deb'
> 
> # restart streamer when mounting /home gives it access to served files
> @reboot /root/.cron/mystreamers-restart.sh
> 
>  … …
> 
> # cat .cron/mystreamers-restart.sh 
> #!/bin/bash
> # /root/mystreamers-restart.sh last edited 2022-05-15
> # wait for real /home to be mounted (its lost+found appears)
> # read the directories to be served
> # set the group permissions to allow minidlna to serve the files
> # restart the service
> 
> Conf=/etc/minidlna.conf
> Log=/var/log/minidlna/minidlna.log
> 
> while :; do
>     if [ ! -d /home/lost+found ]; then
>         sleep 60
>     else
>         if [ -f "$Conf" ]; then
>             sed -n '/^media_dir=/s/media_dir=//p' "$Conf" |
>                 while read Served; do
>                     chmod -R go=rX "$Served"
>                 done
>             if [ -f "$Log" ]; then
>                 date +'Root cron restarted %Y-%m-%d %H:%M:%S' >> "$Log"
>             fi
>             systemctl restart minidlna.service
>         fi
>         break
>     fi
> done
> 
> # 
> 
> Cheers,
> David.
> 
>


Reply to: