]> git.ipfire.org Git - ipfire-2.x.git/blame - src/initscripts/system/apache
apache: Write hostname into configuration at boot time
[ipfire-2.x.git] / src / initscripts / system / apache
CommitLineData
23104841
MT
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
23104841
MT
7. /etc/sysconfig/rc
8. $rc_functions
9
9064ba72
AF
10generate_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
d4092860 14 chmod 600 /etc/httpd/server.key
9064ba72
AF
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
d4092860 22 chmod 600 /etc/httpd/server-ecdsa.key
9064ba72
AF
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
23104841
MT
59case "$1" in
60 start)
9064ba72
AF
61 # Generate all required certificates
62 generate_certificates
63
6723afef
MT
64 # Update hostname
65 echo "ServerName ${HOSTNAME}" > /etc/httpd/conf/hostname.conf
66
75474c3c 67 boot_mesg "Starting Apache daemon..."
23104841
MT
68 /usr/sbin/apachectl -k start
69 evaluate_retval
70 ;;
71
72 stop)
73 boot_mesg "Stopping Apache daemon..."
11e900e0 74 killproc /usr/sbin/httpd
23104841
MT
75 evaluate_retval
76 ;;
77
78 restart)
79 boot_mesg "Restarting Apache daemon..."
80 /usr/sbin/apachectl -k restart
81 evaluate_retval
82 ;;
256575b3
CS
83
84 reload)
85 boot_mesg "Reloading Apache daemon..."
86 /usr/sbin/apachectl -k graceful
87 evaluate_retval
88 ;;
23104841
MT
89
90 status)
91 statusproc /usr/sbin/httpd
92 ;;
93
94 *)
95 echo "Usage: $0 {start|stop|restart|status}"
96 exit 1
97 ;;
98esac
99
100# End $rc_base/init.d/apache