1 | #!/bin/sh |
---|
2 | |
---|
3 | umask 066 # user read/write |
---|
4 | |
---|
5 | seperator() { |
---|
6 | echo "*************************************** $*" |
---|
7 | } |
---|
8 | |
---|
9 | err () { |
---|
10 | seperator ERROR 1>&2 |
---|
11 | echo "`basename $0`: $@" 1>&2 |
---|
12 | exit 1 |
---|
13 | } |
---|
14 | |
---|
15 | |
---|
16 | chooser="/tmp/arb_pids_${USER}_*" |
---|
17 | |
---|
18 | seperator PANIC |
---|
19 | echo " This Module tries to save a running database" |
---|
20 | echo " There may be more than one database server (ARB_NT):" |
---|
21 | echo " --------------------------------" |
---|
22 | |
---|
23 | for i in $chooser ; do |
---|
24 | /bin/echo " - >" `ls $i` "<"; |
---|
25 | done |
---|
26 | echo " --------------------------------" |
---|
27 | |
---|
28 | seperator |
---|
29 | echo "Please choose one line and enter the rightmost number" |
---|
30 | |
---|
31 | read ARB_PID |
---|
32 | if [ ! -f /tmp/arb_pids_${USER}_${ARB_PID} ]; then |
---|
33 | err "Incorrect Choice" |
---|
34 | fi |
---|
35 | |
---|
36 | seperator |
---|
37 | echo "Please enter full path (to save DB):" |
---|
38 | read FILE |
---|
39 | |
---|
40 | panicfile="/tmp/arb_panic_${USER}_${ARB_PID}" |
---|
41 | rm -f $panicfile |
---|
42 | echo "$FILE" >$panicfile |
---|
43 | ok=false |
---|
44 | for i in `cat /tmp/arb_pids_${USER}_${ARB_PID}`; do |
---|
45 | echo "[Sending SIGHUP to pid $i]" |
---|
46 | if kill -HUP $i 2>/dev/null; then |
---|
47 | ok=true |
---|
48 | echo "[Process $i accepted HUP]" |
---|
49 | break |
---|
50 | fi |
---|
51 | done |
---|
52 | |
---|
53 | if [ "$ok" = "false" ]; then |
---|
54 | err "Sorry could not find a running server" |
---|
55 | fi |
---|
56 | seperator |
---|
57 | echo "Wait until database is saved (or press <ctrl-c> to abort)" |
---|
58 | while [ -f $panicfile ]; do |
---|
59 | echo "[waiting]" |
---|
60 | sleep 1 |
---|
61 | if [ -f $panicfile] ; then |
---|
62 | sleep 1 |
---|
63 | if [ -f $panicfile] ; then |
---|
64 | sleep 1 |
---|
65 | if [ -f $panicfile] ; then |
---|
66 | sleep 1 |
---|
67 | if [ -f $panicfile] ; then |
---|
68 | sleep 1 |
---|
69 | fi |
---|
70 | fi |
---|
71 | fi |
---|
72 | fi |
---|
73 | done |
---|
74 | |
---|
75 | seperator |
---|
76 | echo "enter 'kill' if you want to kill the server and its clients" |
---|
77 | echo "enter 'killall' if you want to kill ALL servers and clients" |
---|
78 | |
---|
79 | read ki |
---|
80 | |
---|
81 | if [ "$ki" = "kill" ] ; then |
---|
82 | echo "[Sending SIGTERM to pid $i]" |
---|
83 | kill -TERM $i |
---|
84 | fi |
---|
85 | if [ "$ki" = "killall" ] ; then |
---|
86 | arb_clean |
---|
87 | fi |
---|