You are not logged in.

#1 2018-07-14 11:55:17

ghorvath
Member
Registered: 2015-10-01
Posts: 130

Autofs unmount is prevented by conky and df

As suggested here I am using df to show all mount points on conky. This is the script that generates the conky text:

#!/bin/dash

## loop over the mounted drives
df -h | grep '/.*%' | while read DEVICE SIZE USED FREE PERCENT MOUNT
do
  ## right aligned by adding appropriate amount of spaces at the beginning
  PERCENT=${PERCENT%?}
  if [ $PERCENT -lt 10 ]
  then
    PERCENT="  $PERCENT%"
  elif [ $PERCENT -lt 60 ]
  then
    PERCENT=" $PERCENT%"
  elif [ $PERCENT -lt 100 ]
  ## use color red if more than 60% of disk is full
  then
    PERCENT=" \${color4}$PERCENT%\${color}"
  else
    PERCENT="\${color4}$PERCENT%\${color}"
  fi

  ## if there are two / in the name, then cut off everything after the last /
  CUTMOUNT=/${MOUNT##*/}
  if [ ${#CUTMOUNT} -lt ${#MOUNT} ]
  then
    MOUNT=${MOUNT##*/}
  fi

  ## right aligned by adding appropriate amount of spaces at the beginning
  N=${#USED}
  if [ $N -eq 1 ]
  then
    USED="   $USED"
  elif [ $N -eq 2 ]
  then
    USED="  $USED"
  elif [ $N -eq 3 ]
  then
    USED=" $USED"
  fi

  ## this prints the line corresponding to the mounted drive
  echo "$MOUNT\${goto 70}$USED\${goto 120}$PERCENT\${alignr}$SIZE"
done
## print Disk IO usage
echo "Disk IO \$alignr\${diskio}/s"
## print a line
echo "\${hr}"

I use autofs to mount nfs drives. However, they never unmount afterwards, not even after timeout, because conky calls df every couple seconds to check on the drives. Does anyone know about a smart way to overcome this?

Offline

#2 2018-07-14 12:08:56

twoion
ほやほや
Registered: 2015-08-10
Posts: 2,230

Re: Autofs unmount is prevented by conky and df

I wonder if the culprit really is df, but: do a lazy unmount (umount -l).

-l, --lazy
              Lazy unmount.  Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore.


Im grünen Wald, dort wo die Drossel singt…

Offline

#3 2018-07-14 19:53:57

ghorvath
Member
Registered: 2015-10-01
Posts: 130

Re: Autofs unmount is prevented by conky and df

twoion wrote:

I wonder if the culprit really is df

It is. If I kill the conky, then the drive unmounts properly.

twoion wrote:

but: do a lazy unmount (umount -l).

-l, --lazy
              Lazy unmount.  Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore.

I guess I could try and write some script which somehow counts until timeout and then does a lazy unmount. But I would rather do it the other way: if someone knows a better way to get the stats of the drives without actually restarting the timeout count. I mean, I do not want to reinvent the wheel that comes with autofs already.

Offline

#4 2018-08-13 21:40:01

ghorvath
Member
Registered: 2015-10-01
Posts: 130

Re: Autofs unmount is prevented by conky and df

I am bumping this thread, maybe someone has some other ideas.

Problem with unmount is that root needs to do it, normal user cannot. Now, autofs would do the unmount if df did not prevent it from happening. So I would need to monitor the hard drives without df, in some way.

I don't want to write some script checking in some weird way whether a drive has been accessed or not, in the meantime storing the details of the last partition size so that conky can print that out, etc. At first glance it looks an awful lot of hassle just to do something that is probably already sorted out somehow, I just don't know about it.

So: does anyone know a monitoring tool which is still usable together with autofs, so that autofs would unmount after timeout?

Offline

#5 2018-08-14 06:02:51

ohnonot
...again
Registered: 2015-09-29
Posts: 3,197
Website

Re: Autofs unmount is prevented by conky and df

maybe you should adapt your conky shell script instead - wrap the whole thing in another if statement (pseudocode):

if (automount is doing stuff); then
    exit
else
    do things
fi

Offline

#6 2018-08-14 21:42:17

ghorvath
Member
Registered: 2015-10-01
Posts: 130

Re: Autofs unmount is prevented by conky and df

Ok, this is where I am at currently:

#!/bin/dash

printDriveInfo() {
  DEVICE=$1
  SIZE=$2
  USED=$3
  FREE=$4
  PERCENT=$5
  MOUNT=$6
  ## right aligned by adding appropriate amount of spaces at the beginning
  PERCENT=${PERCENT%?}
  if [ $PERCENT -lt 10 ]
  then
    PERCENT="  $PERCENT%"
  elif [ $PERCENT -lt 60 ]
  then
    PERCENT=" $PERCENT%"
  elif [ $PERCENT -lt 100 ]
  ## use color red if more than 60% of disk is full
  then
    PERCENT=" \${color4}$PERCENT%\${color}"
  else
    PERCENT="\${color4}$PERCENT%\${color}"
  fi

  ## if there are two / in the name, then cut off everything after the last /
  CUTMOUNT=/${MOUNT##*/}
  if [ ${#CUTMOUNT} -lt ${#MOUNT} ]
  then
    MOUNT=${MOUNT##*/}
  fi

  ## right aligned by adding appropriate amount of spaces at the beginning
  N=${#USED}
  if [ $N -eq 1 ]
  then
    USED="   $USED"
  elif [ $N -eq 2 ]
  then
    USED="  $USED"
  elif [ $N -eq 3 ]
  then
    USED=" $USED"
  fi

  ## this prints the line corresponding to the mounted drive
  echo "$MOUNT\${goto 70}$USED\${goto 120}$PERCENT\${alignr}$SIZE"
}

## loop over the mounted drives
## but only consider those where device starts by /
#cat /proc/mounts | grep '/.*%' | while read DEVICE MOUNT FS OPTIONS
cat /proc/mounts | grep '^/' | while read DEVICE MOUNT FS OPTIONS
do
  ## for non-autofs mounted drives we simply list details by df
  if [ ! "$FS" = "autofs" ]
  then
    ## remove the header which does not contain /
    df -h $MOUNT | grep '/' | while read DEVICE SIZE USED FREE PERCENT MOUNT
    do
      printDriveInfo "$DEVICE" "$SIZE" "$USED" "$FREE" "$PERCENT" "$MOUNT"
    done
  fi
done

echo "Disk IO \$alignr\${diskio}/s"
## print a line
echo "\${hr}"

So accessing /proc/mounts does not access the drive itself, so that is good. Afterwards I can cleanly call df for all the fixed mounted drives, and just not list the autofs filetypes. In this case, autofs unmounts properly.

Now I am wondering if I can get drive information without actually accessing the drive.... I would still like to list autofs drive information. It is not a problem when it is accessed: using lsof I can check if the drive is currently in use (without using the drive itself), and if it is, then I can safely issue a df command on the drive to list it.

Problem with this approach is what do I do when the drive does not show up in lsof? There are two possibilities I can think of. One is to find some kind of a stat file, which contains the drive's information (full space, used space) without accessing the drive itself (similar to /proc/mounts, but that one does not have the size data). Anyone knows such a file?

The other option would be to store the size values from the first df call, and if the drive is not accessed, then read this size value from storage (I need to keep the value between two conky refresh). Now, I do not want to write this to disk, so I would need to put it somewhere into memory. Anyone know how to do that?

PS. a question to the conky experts: neither the percentages, nor the sizes are aligned when they have different character size (even though I put in the additional spaces). Even 11G and 77M are not completely aligned, although the difference is very small. But 660M is completely misaligned with both. I want all of them right aligned. How could I do that?

Offline

#7 2018-08-15 04:26:55

ohnonot
...again
Registered: 2015-09-29
Posts: 3,197
Website

Re: Autofs unmount is prevented by conky and df

ghorvath wrote:
cat /proc/mounts | grep '^/' | while read DEVICE MOUNT FS OPTIONS
do
  ## for non-autofs mounted drives we simply list details by df
  if [ ! "$FS" = "autofs" ]
  then
    ## remove the header which does not contain /
    df -h $MOUNT | grep '/' | while read DEVICE SIZE USED FREE PERCENT MOUNT
    do
      printDriveInfo "$DEVICE" "$SIZE" "$USED" "$FREE" "$PERCENT" "$MOUNT"
    done
  fi
done

useless use of cat & pipes. better:

while read DEVICE MOUNT FS OPTIONS
do
  ## for non-autofs mounted drives we simply list details by df
  if [ "${DEVICE%%/*}" = "" ] && [ ! "$FS" = "autofs" ]
  then
    # stuff
  fi
done </proc/mounts

i still maintain that you need to find out programmatically if automount is doing things, and skip executing the script then, or use old values. don't think this stuff is stored anywhere (but could be wrong), so you'd have to write it to a file.
/dev/shm is a part of the memory and usually user-writeable.

Offline

Board footer

Powered by FluxBB