startup scripts : assume initscripts is not installed, only use systemctl
[myplc.git] / plc.d / mail
1 #!/bin/bash
2 #
3 # priority: 200
4 #
5 # Start local mail server.
6 #
7 # Mark Huang <mlhuang@cs.princeton.edu>
8 # Copyright (C) 2006 The Trustees of Princeton University
9 #
10
11 # Source function library and configuration
12 source /etc/plc.d/functions
13 source /etc/planetlab/plc_config
14
15 # Be verbose
16 set -x
17
18 echo '$1' = $1
19
20 case "$1" in
21     start)
22         if [ "$PLC_MAIL_ENABLED" != "1" ] ; then
23             exit 0
24         fi
25
26         MESSAGE=$"Starting mail server"
27         dialog "$MESSAGE"
28
29         # Add apache to list of users that can send mail as others
30         # without a warning, so that the API can send out mail.
31         count=$(grep ^apache /etc/mail/trusted-users|wc -l)
32         if [ $count -eq 0 ] ; then
33                 echo "apache" >>/etc/mail/trusted-users
34         fi
35
36         (exec 3>&- 4>&- ; systemctl start sendmail)
37         check
38
39         result "$MESSAGE"
40         ;;
41
42     stop)
43         MESSAGE=$"Stopping mail server"
44         dialog "$MESSAGE"
45
46         systemctl stop sendmail
47         check
48
49         result "$MESSAGE"
50         ;;
51 esac
52
53 exit $ERRORS