aboutsummaryrefslogtreecommitdiffstats
path: root/www/lighttpd/files/lighttpd.sh.in
blob: aa86640603c12d1bc10af85ddfaf5a6cb21ffec6 (plain) (blame)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: lighttpd
# REQUIRE: %%REQUIRE%%
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable lighttpd:
#
# lighttpd_enable (bool):   Set it to "YES" to enable lighttpd
#               Default is "NO".
# lighttpd_conf (path):     Set full path to configuration file.
#               Default is "%%PREFIX%%/etc/lighttpd/lighttpd.conf".
# lighttpd_pidfile (path):  Set full path to pid file.
#               Default is "/var/run/lighttpd.pid".
#
# Add the following lines to /etc/rc.conf for multiple instances:
# (overrides lighttpd_conf and lighttpd_pidfile from above)
#
# lighttpd_instances (string):  Instances of lighttpd
#               Default is "" (no instances).
# lighttpd_${i}_conf (path):    Set full path to instance configuration file.
#               Default is "%%PREFIX%%/etc/lighttpd/${i}.conf".
# lighttpd_${i}_pidfile (path): Set full path to instance pid file
#               Default is "/var/run/lighttpd_${i}.pid".
#

. /etc/rc.subr

name="lighttpd"
rcvar=lighttpd_enable

load_rc_config $name

: ${lighttpd_enable="NO"}
: ${lighttpd_pidfile="/var/run/${name}.pid"}

# Compatibility for old configuration file location
deprecated_conf=
if [ -z "${lighttpd_conf}" ]; then
    if [ -f "%%PREFIX%%/etc/lighttpd.conf" ]; then
        deprecated_conf=1
        lighttpd_conf="%%PREFIX%%/etc/lighttpd.conf"
    else
        lighttpd_conf="%%PREFIX%%/etc/lighttpd/lighttpd.conf"
    fi
fi

command=%%PREFIX%%/sbin/lighttpd
stop_postcmd=stop_postcmd
restart_precmd="checkconfig"
reload_precmd=reload_precmd
reload_postcmd=reload_postcmd
sig_reload="INT"
check_cmd="checkconfig"
extra_commands="reload check"
command_args="-f ${lighttpd_conf}"
pidfile=${lighttpd_pidfile}
required_files=${lighttpd_conf}

check_deprecated()
{
    if [ -n "${deprecated_conf}" ]; then
        echo ""
        echo "*** NOTICE: ***"
        echo "The default location of %%PREFIX%%/etc/lighttpd.conf is deprecated"
        echo "Please consider moving to %%PREFIX%%/etc/lighttpd/lighttpd.conf"
        echo ""
    fi
}

checkconfig()
{
    echo "Performing sanity check on ${name} configuration:"
    eval "${command} ${command_args} -t"
}

stop_postcmd()
{
    rm -f ${pidfile}
}

reload_precmd()
{
    if checkconfig; then
        echo "Performing a graceful restart"
    else
        return 1
    fi
}

reload_postcmd()
{
    rm -f ${pidfile}
    run_rc_command start
}

run_instance()
{
    _i="$1"
    _rcmd="$2"
    name=${_orig_name}_${_i}
    eval ${name}_enable=${lighttpd_enable}
    eval lighttpd_conf=\"\${lighttpd_${_i}_conf:-"%%PREFIX%%/etc/lighttpd/${_i}.conf"}\"
    eval lighttpd_pidfile=\"\${lighttpd_${_i}_pidfile:-"/var/run/lighttpd_${_i}.pid"}\"
    command_args="-f ${lighttpd_conf}"
    pidfile=${lighttpd_pidfile}
    required_files=${lighttpd_conf}
    run_rc_command ${_rcmd}
}

if [ -n "${lighttpd_instances}" ]; then
    _orig_name="${name}"
    _run_cmd="$1"
    if [ $# -gt 0 ]; then
        shift
    fi
    if [ -n "$*" ]; then
        _run_instances="$*"
    fi
    if [ -n "${_run_instances}" ]; then
        for _a in $_run_instances; do
            for _in in ${lighttpd_instances}; do
                if [ "$_a" = "$_in" ]; then
                    _runlist="${_runlist} ${_a}"
                fi
            done
        done
    else
        _runlist="${lighttpd_instances}"
    fi
    for _in in ${_runlist}; do
        run_instance $_in $_run_cmd
    done
else
    start_precmd="check_deprecated"
    run_rc_command "$1"
fi