summaryrefslogtreecommitdiff
path: root/shutdownasap.in
blob: 328e7ba4bb1c0c893b13ac48ec01b250e82f5c99 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash

# shutdownasap version #VERSION#

set -e

. #ETCDIR#/shutdownasap.conf

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

echo $$ > "${pidFile}"

quiet=false
if [ $# -eq 1 ] && [ "x$1" = 'x-q' ]; then
  quiet=true
elif [ $# -ne 0 ]; then
  >&2 echo 'usage: shutdownasap [-q]'
  exit 1
fi

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
    if ! ${quiet}; then
      echo ".warteauf: "
      ls -1A "${waitForDir}"
    fi
  fi

  if users | grep -q "."
  then
    nochwarten=true
    if ! ${quiet}; then
      echo -n "users: "
      users
    fi
  fi

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

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

  for s in "${!shutDownNoGoFiles[@]}"
  do
    if [ -e "${shutDownNoGoFiles[${s}]}" ] && echo "${prozesse}" | grep -q "^\S\+\s\+$(cat "${shutDownNoGoFiles[${s}]}")\s"
    then
      nochwarten=true
      if ! ${quiet}; then
        echo "datei: ${s}"
      fi
    fi
  done

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

beforeShutDownHook

sudo /sbin/poweroff