aboutsummaryrefslogtreecommitdiff
path: root/net/etebase/files/uwsgi.init
blob: 516b424f788d5643717584c6c8052f3c28778925 (plain)
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
#!/bin/sh /etc/rc.common

START=82

USE_PROCD=1

ETEBASE_INI="/var/etc/etebase/server.ini"


etebase_print_uci_allow_all_ips_of() {
    local ifstat="$(ifstatus "$1")"

    for ip in $(echo "${ifstat}" | jsonfilter -e '@["ipv4-address"].*.address')
    do echo "allowed_host_${ip//[^0-9]/_} = ${ip}"
    done

    for ip in $(echo "${ifstat}" | jsonfilter -e '@["ipv6-address"].*.address')
    do echo "allowed_host_${ip//[^0-9A-Fa-f]/_} = [${ip}]"
    done

    for ip in $(echo "${ifstat}" | \
        jsonfilter -e '@["ipv6-prefix-assignment"].*["local-address"].address')
    do echo "allowed_host_${ip//[^0-9A-Fa-f]/_} = [${ip}]"
    done
}


etebase_validate_global() {
    cd /usr/share/etebase/ >/dev/null || return

    uci_load_validate etebase django "global" "$1" \
        'secret_file:file:secret.txt' \
        'static_url:string:static/' \
        'language_code:string:en-us' \
        'time_zone:string:UTC' \
        'debug:bool:false' \
        ;
}


etebase_print_global() {
    printf "\n[global]\n"

    echo "secret_file = ${secret_file}"
    echo "static_root = /www/etebase/static" #sic!
    echo "static_url = ${static_url}"
    echo "language_code = ${language_code}"
    echo "time_zone = ${time_zone}"
    echo "debug = ${debug}"
}


etebase_validate_allowed_hosts() {
    cd /usr/share/etebase/ >/dev/null || return

    uci_load_validate etebase django "allowed_hosts" "$1" \
        'uci_allow_all_ips_of:network' \
        'allowed_host:host' \
        ;
}


etebase_print_allowed_hosts() {
    printf "\n[allowed_hosts]\n"

    local iface
    for iface in ${uci_allow_all_ips_of}
    do etebase_print_uci_allow_all_ips_of "${iface}"
    done

    local host
    for host in ${allowed_host}
    do echo "allowed_host_${host//[^0-9A-Za-z]/_} = ${host}"
    done
}


etebase_validate_database() {
    cd /usr/share/etebase/ >/dev/null || return

    uci_load_validate etebase django "database" "$1" \
        'engine:hostname:django.db.backends.sqlite3' \
        'name:file:db.sqlite3' \
        ;
}


etebase_print_database() {
    printf "\n[database]\n"
    echo "engine = ${engine}"
    echo "name = ${name}"
}


etebase_init() { # This must print ONLY configuration lines:
    echo "; This file is re-created from /etc/config/etebase "
    etebase_validate_global etebase_print_global
    etebase_validate_allowed_hosts etebase_print_allowed_hosts
    etebase_validate_database etebase_print_database
} >"${ETEBASE_INI}"


start_service() {
    mkdir -p /var/etc/etebase/

    etebase_init

    logger -p 'daemon.info' -t 'etebase_init' 'starting ...'
    ln -sf /etc/uwsgi/vassals/etebase.available /var/etc/etebase/uwsgi.ini
}


stop_service() {
    rm -f /var/etc/etebase/uwsgi.ini "${ETEBASE_INI}"
}


reload_service() {
    etebase_init

    logger -p 'daemon.info' -t 'etebase_init' 'reloading ...'
    kill -SIGHUP "$(cat "/var/etc/etebase/master.pid")" 2>/dev/null
    #if the server is in on-demand mode, the ini files are reloaded then, too.
}


service_triggers() {
    procd_open_validate
    etebase_validate_global "$@"
    etebase_validate_allowed_hosts "$@"
    etebase_validate_database "$@"
    procd_close_validate

    config_load etebase
    config_list_foreach "allowed_hosts" "uci_allow_all_ips_of" procd_add_reload_interface_trigger
    procd_add_reload_trigger etebase
}