]> git.pld-linux.org Git - packages/postfix.git/blob - postfix.init
- use functions; only starting and restarting requires networking check.
[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 30
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_starting Postfix
36                 busy
37                 MSG="`/usr/sbin/postfix start 2>&1`"
38                 if [ $? -eq 0 ]; then
39                         ok
40                         touch /var/lock/subsys/postfix
41                 else
42                         RETVAL=1
43                         fail
44                         echo "$MSG"
45                 fi
46         else
47                 msg_already_running Postfix
48         fi
49 }
50
51 stop() {
52         if [ -f /var/lock/subsys/postfix ]; then
53                 msg_stopping Postfix
54                 busy
55                 MSG="`/usr/sbin/postfix stop 2>&1`"
56                 if [ $? -eq 0 ]; then
57                         ok
58                 else
59                         fail
60                         echo "$MSG"
61                 fi
62                 rm -f /var/lock/subsys/postfix
63         else
64                 msg_not_running Postfix
65         fi
66 }
67
68 RETVAL=0
69 # See how we were called.
70 case "$1" in
71   start)
72         networking_check
73         start
74         ;;
75   stop)
76         stop
77         ;;
78   restart)
79         networking_check
80         stop
81         start
82         exit $?
83         ;;
84   reload|force-reload)
85         networking_check
86         if [ -f /var/lock/subsys/postfix ]; then
87                 msg_reloading Postfix
88                 daemon /usr/sbin/postfix reload
89                 RETVAL=$?
90                 [ $RETVAL -ne 0 ] && RETVAL=7
91         else
92                 msg_not_running Postfix
93                 exit 7
94         fi
95         ;;
96   status)
97         status master
98         exit $?
99         ;;
100   rebuilddb)
101         standard_db="access canonical relocated transport virtual"
102         extra_db=$(ls -1 /etc/mail/*.db 2> /dev/null | grep -v aliases.db | sed -e 's#.db$##')
103         for base in $standard_db $extra_db; do
104                 I=$(basename "$base")
105                 if [ -f /etc/mail/$I ]; then
106                         /usr/sbin/postmap hash:/etc/mail/$I < /etc/mail/$I
107                 fi
108         done
109         /usr/bin/newaliases
110         ;;
111   *)
112         msg_usage "$0 {start|stop|restart|reload|force-reload|rebuilddb|status}"
113         exit 3
114 esac
115
116 exit $RETVAL
This page took 0.087585 seconds and 4 git commands to generate.