Home | History | Annotate | Download | only in network_DiskFull
      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 MAX_TIMEOUT_SECONDS=300
      6 
      7 usage() {
      8     echo "$0 <mount point> <timeout seconds>"
      9     exit 1
     10 }
     11 
     12 # Get the size of the filesystem mounted at $1, in bytes.
     13 get_mount_size_bytes() {
     14     local mount_point="$1"
     15 
     16     # Filesystem              1024-blocks  Used Available Capacity Mounted on
     17     # /dev/mapper/encstateful      290968 47492    243476      17% /var
     18     #
     19     # awk uses double-representation internally; we'll hit problems if
     20     # the filesystem has more than 2^53 bytes (8 petabytes).
     21     df -P "$mount_point" |
     22     awk '($6 == "'"$mount_point"'") { printf "%.0f", $2*1024; exit }'
     23 }
     24 
     25 if [ $# -ne 2 ]; then
     26     usage
     27 fi
     28 
     29 mount_point="$1"
     30 timeout_seconds="$2"
     31 
     32 if [ "$timeout_seconds" -gt $MAX_TIMEOUT_SECONDS ]; then
     33     echo "max timeout is "$MAX_TIMEOUT_SECONDS" seconds";
     34     exit 1
     35 fi
     36 
     37 mount_size_bytes=$(get_mount_size_bytes /var)
     38 temp_file=$(mktemp --tmpdir="$mount_point" hog_disk.XXXXXXXXXX)
     39 trap 'rm -f "$temp_file"' EXIT
     40 trap 'exit' HUP INT QUIT TERM
     41 
     42 for i in $(seq 1 $(( timeout_seconds * 10 ))); do
     43     fallocate --length "$mount_size_bytes" "$temp_file" 2>/dev/null || true
     44     sleep 0.1
     45 done
     46