]> TLD Linux GIT Repositories - packages/postfix.git/blob - postfix.init
- postfix 2.10.3
[packages/postfix.git] / postfix.init
1 #!/bin/sh
2 #
3 # postfix       This shell script takes care of starting and stopping
4 #               postfix.
5 #
6 # chkconfig:    345 80 20
7 #
8 # description:  Postfix is a Mail Transport Agent, which is the program \
9 #               that moves mail from one machine to another.
10
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 # Get network config
16 . /etc/sysconfig/network
17
18 # Get service config
19 [ -f /etc/sysconfig/postfix ] && . /etc/sysconfig/postfix
20
21 # Check that networking is up.
22 networking_check() {
23         if is_yes "${NETWORKING}"; then
24                 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
25                         msg_network_down "Postfix"
26                         exit 1
27                 fi
28         else
29                 exit 0
30         fi
31 }
32
33 start() {
34         if [ -f /var/lock/subsys/postfix ]; then
35                 msg_already_running "Postfix"
36                 return
37         fi
38
39         local msg
40         msg_starting "Postfix"
41         busy
42         _daemon_set_ulimits
43         msg=$(nice -n ${SERVICE_RUN_NICE_LEVEL:-${DEFAULT_SERVICE_RUN_NICE_LEVEL:-0}} /usr/sbin/postfix start 2>&1)
44         RETVAL=$?
45         if [ $RETVAL -eq 0 ]; then
46                 ok
47                 touch /var/lock/subsys/postfix
48         else
49                 fail
50                 echo >&2 "$msg"
51         fi
52 }
53
54 stop() {
55         if [ ! -f /var/lock/subsys/postfix ]; then
56                 msg_not_running "Postfix"
57                 return
58         fi
59
60         local msg
61         msg_stopping "Postfix"
62         busy
63         msg=$(/usr/sbin/postfix stop 2>&1)
64         if [ $? -eq 0 ]; then
65                 ok
66         else
67                 fail
68                 echo >&2 "$msg"
69         fi
70         rm -f /var/lock/subsys/postfix >/dev/null 2>&1
71 }
72
73 reload() {
74         if [ ! -f /var/lock/subsys/postfix ]; then
75                 msg_not_running "Postfix"
76                 RETVAL=7
77                 return
78         fi
79
80         local msg
81         msg_reloading "Postfix"
82         busy
83         msg=$(/usr/sbin/postfix reload 2>&1)
84         RETVAL=$?
85         if [ $RETVAL -eq 0 ]; then
86                 ok
87         else
88                 fail
89                 echo >&2 "$msg"
90                 RETVAL=7
91         fi
92 }
93
94 RETVAL=0
95 # See how we were called.
96 case "$1" in
97   start)
98         networking_check
99         start
100         ;;
101   stop)
102         stop
103         ;;
104   restart)
105         networking_check
106         stop
107         start
108         ;;
109   reload|force-reload)
110         networking_check
111         reload
112         ;;
113   rebuilddb)
114         standard_db="access canonical relocated transport virtual"
115         extra_db=$(ls -1 /etc/mail/*.db 2> /dev/null | grep -Ev '/(access|canonical|relocated|transport|virtual|aliases)\.db$')
116
117         echo -n "Rebuilding databases: "
118         for base in $standard_db $extra_db; do
119                 db=$(basename "$base" .db)
120
121                 if [ -f /etc/mail/$db ]; then
122                         echo -n "$db "
123                         /usr/sbin/postmap hash:/etc/mail/$db < /etc/mail/$db
124                 fi
125         done
126         echo "...DONE"
127
128         echo -n "Rebuilding aliases database"
129         /usr/bin/newaliases
130         echo "...DONE"
131         ;;
132   status)
133         status master
134         exit $?
135         ;;
136   *)
137         msg_usage "$0 {start|stop|restart|reload|force-reload|rebuilddb|status}"
138         exit 3
139 esac
140
141 exit $RETVAL