]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/apache
resolv.conf: Add "trust-ad" option
[ipfire-2.x.git] / src / initscripts / system / apache
1 #!/bin/sh
2 # Begin $rc_base/init.d/apache
3
4 # Based on sysklogd script from LFS-3.1 and earlier.
5 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
6
7 . /etc/sysconfig/rc
8 . $rc_functions
9
10 generate_certificates() {
11 if [ ! -f "/etc/httpd/server.key" ]; then
12 boot_mesg "Generating HTTPS RSA server key (this will take a moment)..."
13 openssl genrsa -out /etc/httpd/server.key 4096 &>/dev/null
14 chmod 600 /etc/httpd/server.key
15 evaluate_retval
16 fi
17
18 if [ ! -f "/etc/httpd/server-ecdsa.key" ]; then
19 boot_mesg "Generating HTTPS ECDSA server key..."
20 openssl ecparam -genkey -name secp384r1 -noout \
21 -out /etc/httpd/server-ecdsa.key &>/dev/null
22 chmod 600 /etc/httpd/server-ecdsa.key
23 evaluate_retval
24 fi
25
26 # Generate RSA CSR
27 if [ ! -f "/etc/httpd/server.csr" ]; then
28 sed "s/HOSTNAME/`hostname -f`/" < /etc/certparams | \
29 openssl req -new -key /etc/httpd/server.key \
30 -out /etc/httpd/server.csr &>/dev/null
31 fi
32
33 # Generate ECDSA CSR
34 if [ ! -f "/etc/httpd/server-ecdsa.csr" ]; then
35 sed "s/HOSTNAME/`hostname -f`/" < /etc/certparams | \
36 openssl req -new -key /etc/httpd/server-ecdsa.key \
37 -out /etc/httpd/server-ecdsa.csr &>/dev/null
38 fi
39
40 if [ ! -f "/etc/httpd/server.crt" ]; then
41 boot_mesg "Signing RSA certificate..."
42 openssl x509 -req -days 999999 -sha256 \
43 -in /etc/httpd/server.csr \
44 -signkey /etc/httpd/server.key \
45 -out /etc/httpd/server.crt &>/dev/null
46 evaluate_retval
47 fi
48
49 if [ ! -f "/etc/httpd/server-ecdsa.crt" ]; then
50 boot_mesg "Signing ECDSA certificate..."
51 openssl x509 -req -days 999999 -sha256 \
52 -in /etc/httpd/server-ecdsa.csr \
53 -signkey /etc/httpd/server-ecdsa.key \
54 -out /etc/httpd/server-ecdsa.crt &>/dev/null
55 evaluate_retval
56 fi
57 }
58
59 case "$1" in
60 start)
61 # Generate all required certificates
62 generate_certificates
63
64 # Update hostname
65 echo "ServerName ${HOSTNAME}" > /etc/httpd/conf/hostname.conf
66
67 boot_mesg "Starting Apache daemon..."
68 /usr/sbin/apachectl -k start
69 evaluate_retval
70 ;;
71
72 stop)
73 boot_mesg "Stopping Apache daemon..."
74 killproc /usr/sbin/httpd
75 evaluate_retval
76 ;;
77
78 restart)
79 boot_mesg "Restarting Apache daemon..."
80 /usr/sbin/apachectl -k restart
81 evaluate_retval
82 ;;
83
84 reload)
85 boot_mesg "Reloading Apache daemon..."
86 /usr/sbin/apachectl -k graceful
87 evaluate_retval
88 ;;
89
90 status)
91 statusproc /usr/sbin/httpd
92 ;;
93
94 *)
95 echo "Usage: $0 {start|stop|restart|status}"
96 exit 1
97 ;;
98 esac
99
100 # End $rc_base/init.d/apache