a4e31b1fd6750d46dd0dcd43d7f82d0dbfa3e2f3
[feed/packages.git] / admin / rsyslog / files / rsyslog.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2014 OpenWrt.org
3
4 START=20
5
6 USE_PROCD=1
7
8 UCI_CONF="rsyslog"
9 CONFIG_FILE="/var/etc/rsyslog.conf"
10 BASE_CONFIG_FILE="/etc/rsyslog.conf"
11
12 modules=""
13 selectors=""
14 forwarders=""
15
16 handle_selector() {
17 local config="$1"
18 local src
19 local dst
20
21 config_get src ${config} source
22 config_get dst ${config} destination
23 if [ ${src} != "" ] && [ "$dst" != "" ]; then
24 selectors="${selectors}\n${src}\t${dst}\n"
25 fi
26 }
27
28 handle_forwarder() {
29 local config="$1"
30 local src
31 local target
32 local protocol
33 local port
34 local rfc
35 local opts
36
37 config_get src ${config} source
38 config_get target ${config} target
39 config_get protocol ${config} protocol "udp"
40 config_get port ${config} port "514"
41 config_get rfc ${config} rfc "3164"
42
43 if [ "$rfc" == "5424" ]; then
44 opts='Template="RSYSLOG_SyslogProtocol23Format" TCP_Framing="octet-counted"'
45 fi
46
47 if [ ${src} != "" ] && [ "${target}" != "" ]; then
48 action="action(type=\"omfwd\" target=\"$target\" port=\"$port\" protocol=\"$protocol\" $opts action.resumeRetryCount=\"100\" queue.type=\"linkedList\" queue.size=\"10000\")"
49 forwarders="${forwarders}\n${src}\t${action}\n"
50 fi
51 }
52
53
54 expand_config() {
55 local input_t=""
56 local input_u=""
57
58 config_load ${UCI_CONF}
59 config_list_foreach syslog modules handle_module
60 config_get_bool tcp_input syslog tcp_input
61 if [ ${tcp_input} -eq 1 ]; then
62 modules="${modules} imtcp"
63 config_get tcp_port syslog tcp_input_port
64 input_t="input(type=\"imtcp\" port=\"${tcp_port}\")"
65 fi
66
67 config_get_bool udp_input syslog udp_input
68 if [ ${udp_input} -eq 1 ]; then
69 modules="${modules} imudp"
70 config_get udp_port syslog udp_input_port
71 input_u="input(type=\"imudp\" port=\"${udp_port}\")"
72
73 fi
74 config_get template syslog default_template
75 config_foreach handle_selector selector
76 config_foreach handle_forwarder forwarder
77
78 mkdir -p $(dirname ${CONFIG_FILE})
79 > ${CONFIG_FILE}
80 echo "include(file=\"${BASE_CONFIG_FILE}\" mode=\"optional\")" >> ${CONFIG_FILE}
81 for m in ${modules}; do
82 echo "module(load=\"${m}\")" >> ${CONFIG_FILE}
83 done
84 echo ${input_t} >> ${CONFIG_FILE}
85 echo ${input_u} >> ${CONFIG_FILE}
86 echo "\$ActionFileDefaultTemplate ${template}" >> ${CONFIG_FILE}
87 echo -e ${selectors} >> ${CONFIG_FILE}
88 echo -e ${forwarders} >> ${CONFIG_FILE}
89 }
90
91 handle_module() {
92 local module="$1"
93 modules="${modules} $module"
94 }
95
96 start_service() {
97 expand_config
98 procd_open_instance
99 procd_set_param command /usr/sbin/rsyslogd -f ${CONFIG_FILE} -n
100 procd_close_instance
101 }
102
103
104 service_triggers()
105 {
106 procd_add_reload_trigger ${UCI_CONF}
107 }