hc
2023-11-22 f743a7adbd6e230d66a6206fa115b59fec2d88eb
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: postfix MTA
# Default-Start: 2345
# Default-Stop: 016
# Short-Description: start and stop postfix
# Description: Postfix is a Mail Transport Agent, which is the program
#              that moves mail from one machine to another.
### END INIT INFO
 
success() {
        echo " Successful"
        exit 0
}
 
fail() {
        echo " Failed"
        exit 1
 
}
 
check_return () {
        local ret="$1"
 
        if [ "$ret" = "0" ]; then
          success
        else
          fail
        fi
}
 
PIDFile=/var/spool/postfix/pid/master.pid
case "$1" in
 
        start)
        echo -n "Starting Postfix..."
        if [ ! -e /etc/aliases.db ]; then
          # The alias database is necessary for postfix to work correctly.
          echo "Creating aliases database ..."
          newaliases
        fi
        if ! postfix status >/dev/null 2>&1; then
          /usr/sbin/check_hostname.sh
          postfix start
          check_return $?
        else
          success
        fi
        ;;
 
        stop)
        echo -n  "Stopping Postfix..."
        if postfix status >/dev/null 2>&1; then
          postfix stop
          check_return $?
        else
          success
        fi
        ;;
 
        reload)
        echo -n "Reloading Postfix..."
        if postfix status >/dev/null 2>&1; then
          postfix reload
          check_return $?
        else
          postfix start
          check_return $?
        fi
        ;;
 
        restart)
        $0 stop
        sleep 1
        $0 start
        ;;
 
        status)
        if postfix status >/dev/null 2>&1; then
          pid=`sed -e 's/\s//g' $PIDFile`
          echo "The Postfix mail system is running (PID: $pid)"
          exit 0
        else
          echo "The Postfix mail system is not running"
          exit 1
        fi
        ;;
 
        *)
        echo "Usage: $0 {start|stop|status|reload|restart}"
        exit 1
        ;;
esac