source: npl/mailserver/netqmail_conf/root/var/qmail/bin/qmailctl

Last change on this file was 4f7cda5, checked in by Edwin Eefting <edwin@datux.nl>, 7 years ago

upgrade to netqmail 1.06 with Roberto Puzzanghera's patch (http://notes.sagredo.eu/en/qmail-notes-185/patching-qmail-82.html)

  • Property mode set to 100755
File size: 5.4 KB
Line 
1#!/bin/sh
2#
3# tx Sam Tang
4
5# Put here the services you want to manage
6svclist="qmail-smtpd qmail-submission qmail-send vpopmaild"
7# Put here the services want monitoring
8servicelist="dovecot clamd freshclam spamd vusaged httpd mariadb fail2ban"
9
10PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
11export PATH
12
13QMAILDUID=`id -u qmaild`
14NOFILESGID=`id -g qmaild`
15
16function show_uptime() {
17        org="$(svstat /service/$1 | awk '{print $2,$3,$4;}' | sed 's/up/[ up ]/g' | sed 's/down/[ down ]/g' | sed ''/up/s//`printf "\033[1\;32mup\033[0m"`/'' | sed ''/down/s//`printf "\033[1\;31mdown\033[0m"`/'')"
18        sec="$(svstat /service/$1 | awk '{print $5;}')"
19        d=$(( $sec / 86400))
20        h=$(( $(($sec - $d * 86400)) / 3600 ))
21        m=$(( $(($sec -d * 86400 - $h * 3600)) / 60 ))
22        s=$(($sec -d * 86400 - $h * 3600 - $m * 60))
23        if [ $sec -le 60 ]; then
24                printf "%-22s %s %s %s %s %s %s seconds\n" "$1:" $org $s
25        else
26                printf "%-22s %s %s %s %s %s %3s day(s), %02d:%02d:%02d\n" "$1:" $org $d $h $m $s
27        fi
28}
29
30case "$1" in
31  start)
32    echo "Starting qmail"
33
34    for svc in $svclist ; do
35        if svok /service/$svc ; then
36                svc -u /service/$svc
37        else
38                echo $svc service not running
39        fi
40    done
41
42    if [ -d /var/lock/subsys ]; then
43      touch /var/lock/subsys/qmail
44    fi
45    ;;
46  stop)
47    echo "Stopping qmail..."
48    for svc in $svclist ; do
49      echo " $svc"
50      svc -d /service/$svc
51    done
52    if [ -f /var/lock/subsys/qmail ]; then
53    rm /var/lock/subsys/qmail
54    fi
55    ;;
56  stat)
57    for svc in $svclist ; do
58      show_uptime $svc
59      show_uptime "$svc/log"
60    done
61    echo ""
62    for service in $servicelist ; do
63      printf "%-22s " "$service status:"
64      if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
65      then
66          echo -e "[ \033[1;32mup\033[m ]"
67      else
68          echo -e "[ \033[1;31mdown\033[m ]"
69      fi
70    done
71    if [ -f /var/qmail/control/simversions.cdb ]; then
72        printf "\nClamAV database updated at: "
73        stat --printf=%y /var/qmail/control/simversions.cdb | cut -d. -f1
74    fi
75    if [ -f /var/qmail/users/assign ]; then
76        printf "Total Domains: "
77        wc -l < /var/qmail/users/assign
78    fi
79    echo ""
80    qmail-qstat
81    ;;
82  doqueue|alrm|flush)
83    echo "Sending ALRM signal to qmail-send."
84    svc -a /service/qmail-send
85    ;;
86  queue)
87    qmail-qstat
88    qmail-qread
89    ;;
90  reload|hup)
91    echo "Sending HUP signal to qmail-send."
92    svc -h /service/qmail-send
93    ;;
94  pause)
95    for svc in $svclist ; do
96      echo "Pausing $svc"
97      svc -p /service/$svc
98    done
99    ;;
100  cont)
101          for svc in $svclist ; do
102            echo "Continuing $svc"
103            svc -c /service/$svc
104          done
105    ;;
106  restart)
107    echo "Restarting qmail:"
108    for svc in $svclist ; do
109      if [ "$svc" != "qmail-send" ] ; then
110        echo "* Stopping $svc."
111        svc -d /service/$svc
112      fi
113    done
114    echo "* Sending qmail-send SIGTERM and restarting."
115    svc -t /service/qmail-send
116    for svc in $svclist ; do
117      if [ "$svc" != "qmail-send" ] ; then
118        echo "* Restarting $svc."
119        svc -u /service/$svc
120      fi
121    done
122    ;;
123  cdb)
124    if ! grep '\#define POP_AUTH_OPEN_RELAY 1' ~vpopmail/include/config.h >/dev/null; then
125      (cd ~vpopmail/etc ; cat tcp.smtp | tcprules tcp.smtp.cdb tcp.smtp.tmp)
126      echo "Updated tcp.smtp.cdb."
127      (cd ~vpopmail/etc ; cat tcp.submission | tcprules tcp.submission.cdb tcp.submission.tmp)
128      echo "Updated tcp.submission.cdb."
129    else
130      ~vpopmail/bin/clearopensmtp
131      echo "Ran clearopensmtp."
132    fi
133    ;;
134  clear)
135    echo "Clearing readproctitle service errors with ................."
136    svc -o /service/clear
137    ;;
138  kill)
139    echo "First stopping services ... "
140    for svc in $svclist ; do
141        if svok /service/$svc ; then
142            svc -d /service/$svc
143            svc -d /service/$svc/log
144        fi
145    done
146    echo "Now sending processes the kill signal ... "
147        killall -g svscanboot
148    echo "done"
149    ;;
150  boot)
151    echo "Starting qmail"
152    /command/svscanboot &
153    ;;
154  reboot)
155    echo "First stopping services ... "
156    for svc in $svclist ; do
157        if svok /service/$svc ; then
158            svc -d /service/$svc
159            svc -d /service/$svc/log
160        fi
161    done
162    echo "Now sending processes the kill signal ... "
163        killall -g svscanboot
164    echo "done"
165    echo "Starting qmail"
166    /command/svscanboot &
167    ;;
168  help)
169    cat <<HELP
170    stop -- stops mail service (smtp connections refused, nothing goes out)
171   start -- starts mail service (smtp connection accepted, mail can go out)
172   pause -- temporarily stops mail service (connections accepted, nothing leaves)
173    cont -- continues paused mail service
174    stat -- displays status of mail service
175     cdb -- rebuild the tcpserver cdb file for smtp
176 restart -- stops and restarts smtp, sends qmail-send a TERM & restarts it
177 doqueue -- sends qmail-send ALRM, scheduling queued messages for delivery
178  reload -- sends qmail-send HUP, rereading locals and virtualdomains
179   queue -- shows status of queue
180    alrm -- same as doqueue
181   flush -- same as doqueue
182     hup -- same as reload
183   clear -- clears the readproctitle service errors with .....................
184    kill -- svc -d processes in svclist, then do 'killall -g svscanboot'
185    boot -- Boots qmail and all services in /service running /command/svscanboot
186  reboot -- kill & boot commands in sequence
187HELP
188    ;;
189  *)
190    echo "Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|clear|kill|boot|reboot|help}"
191    exit 1
192    ;;
193esac
194
195exit 0
Note: See TracBrowser for help on using the repository browser.