Results 1 to 5 of 5

Thread: Weird autofs behavior when starting it as systemd service

  1. #1

    Default Weird autofs behavior when starting it as systemd service

    Hello,

    I have a QNAP NAS containing several shares, which I want to automount using autofs, and which I want to wake up using Wake Up on LAN. For this, I have the following entry in auto.master:

    Code:
    /NAS01 /etc/auto.nas01 --timeout=300 --ghost
    /etc/auto.nas01 is an executable bash script, which looks as follows:

    Code:
    #!/bin/bash
    
    # Modify these values
    waittime=900
    host="NAS01"
    hwaddr="00:08:9B:F7:A2:FE"
    fstype="cifs"
    credentials="$HOME/.credentials/${host}.auth"
    sharename=$1
    mountopts="-fstype=$fstype,credentials=$credentials,nodev,nosuid"
    wolcmd="wol"
    
    test -n $sharename -a -r $credentials || exit 0
    
    if ! ping "$host" -nqc1 > /dev/null 2>&1; then
        $wolcmd "$hwaddr" > /dev/null
        for n in `seq 1 $waittime`; do
            ping "$host" -nqc1 > /dev/null 2>&1 && break
            sleep 1
        done
    fi
    
    echo -n "$mountopts"
    echo -n -e " "
    echo -n "://$host/$sharename"
    I'd like to start autofs as a systemd service on boot. The service file looks like this:

    Code:
    Description=Automounts filesystems on demand
    Documentation=man:automount(8) man:autofs(5)
    After=network.target remote-fs.target nss-lookup.target nss-user-lookup.target
    Before=systemd-logind.service
    
    [Service]
    PIDFile=/run/automount.pid
    EnvironmentFile=-/etc/sysconfig/autofs
    ExecStart=/usr/sbin/automount $AUTOFS_OPTIONS -f -p /run/automount.pid
    ExecReload=/usr/bin/kill -HUP $MAINPID
    TimeoutSec=180
    KillMode=mixed
    
    [Install]
    WantedBy=multi-user.target
    Now, I have the following weird behavior:


    • If I start autofs as a service, it is started, but the lookup of shares fails.
    • If I start it manually on the console as a daemon, it works, but it wakes up my NAS when starting.
    • If I start it on the console but in the foreground, it works, and it also does not wake up the NAS when autofs is started.


    The third behavior is the expected one. How can I achieve this behavior when launching autofs as a service?
    Gruß / Regards,
    Patrick
    http://www.klangexellenz.de

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,268
    Blog Entries
    2

    Default Re: Weird autofs behavior when starting it as systemd service

    Maybe try replacing "After" with "Requires"

    Sounds to me when you invoke your autofs service directly instead of how things <might> load in a boot, you haven't guaranteed your network has started... In that case, I don't know how your network shares can work.

    Also, you need to likely take into account that "waking" a system with WOL is triggered by a token hitting the NIC and likely will never naturally bypass that to start your autofs.service, so I don't know how much value there is in invoking your autofs service directly.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  3. #3

    Default Re: Weird autofs behavior when starting it as systemd service

    Here is what I want:

    • I want the automount daemon to be started at boot time.
    • I want the NAS to be woken up when I mount a share, but not when I boot the Linux box.


    How to achieve that reliably?
    Gruß / Regards,
    Patrick
    http://www.klangexellenz.de

  4. #4
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,268
    Blog Entries
    2

    Default Re: Weird autofs behavior when starting it as systemd service

    Quote Originally Posted by pschoenb View Post
    Here is what I want:

    • I want the automount daemon to be started at boot time.
    • I want the NAS to be woken up when I mount a share, but not when I boot the Linux box.


    How to achieve that reliably?
    OK, I see what you're trying to do.
    The problem with automating what you want to do is that the NAS box must be woken up <and serving> before you can do your mount.

    Your problem is common, is why generally speaking Servers are configured to never "go to sleep" and should always be available for clients. Your <client machines> can be configured to go to sleep because generally speaking they aren't providing services for other boxes.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  5. #5

    Default Re: Weird autofs behavior when starting it as systemd service

    But my script waits until the server is up. So, this should be no problem.
    Gruß / Regards,
    Patrick
    http://www.klangexellenz.de

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •