summaryrefslogtreecommitdiff
path: root/shutdownasap.in
blob: 378e70ca024faba3af305963ff4b8b70a93f75b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash

# shutdownasap version #VERSION#

. #ETCDIR#/shutdownasap.conf

[ -r "${pidFile}" ] && ps aux | grep -q "^\S\+\s\+$(cat "${pidFile}") " && exit

echo $$ > "${pidFile}"

beforeWatchHook

i=1
while [ ${i} -gt 0 ]
do
  sleep 1
  prozesse="$(ps aux | grep -v grep)"

  nochwarten=false

  if [ -d "${waitForDir}" ] && ls -1A "${waitForDir}" | grep -q "."
  then
    nochwarten=true
    echo ".warteauf: "
    ls -1A "${waitForDir}"
  fi

  if users | grep -q "."
  then
    nochwarten=true
    echo -n "users: "
    users
  fi

  for synActFile in /sys/block/md*/md/sync_action
  do
    if [ -r "${synActFile}" ] && ! grep -q "^idle\$" "${synActFile}"
    then
      nochWarten=true
      echo -n "raid ${synActFile}: "
      cat "${synActFile}"
    fi
  done

  for s in "${!shutDownNoGos[@]}"
  do
    if [ -e "${shutDownNoGos[${s}]}" ] || echo "${prozesse}" | grep -q "\(\s\|/\)${shutDownNoGos[${s}]}\(\$\|\s\)"
    then
      nochwarten=true
      echo "prozess: ${s}"
    fi
  done

  if ${nochwarten}
  then
    echo "warten ..."
    i=10
    continue
  else
    echo "noch ${i} Sekunden"
  fi
  i=$[${i}-1]
done

beforeShutDownHook

sudo /sbin/poweroff