1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2016 OpenWrt.org
8 COLLECTD_CONF
="/tmp/collectd.conf"
9 LOG
="logger -t collectd[$$] -p"
15 printf "<Plugin exec>\n" >> "$COLLECTD_CONF"
16 config_foreach process_exec_sections exec_input
"Exec"
17 config_foreach process_exec_sections exec_notify
"NotificationExec"
18 printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
21 process_exec_sections
() {
25 local cmdline cmduser cmdgroup
27 config_get cmdline
"$cfg" cmdline
28 [ -z "$cmdline" ] && {
29 $LOG notice
"No cmdline option in config $cfg defined"
33 config_get cmduser
"$cfg" cmduser
34 [ -z "$cmduser" ] && {
35 $LOG notice
"No cmduser option in config $cfg defined"
39 config_get cmdgroup
"$cfg" cmdgroup
40 if [ -z "$cmdgroup" ]; then
41 printf "\\t%s \"%s\" \"%s\"\n" "${section}" "${cmduser}" "${cmdline}" >> "$COLLECTD_CONF"
43 printf "\\t%s \"%s:%s\" \"%s\"\n" "${section}" "${cmduser}" "${cmdgroup}" "${cmdline}" >> "$COLLECTD_CONF"
53 CONFIG_LIST
="${CONFIG_LIST}${indent}${option} \"$value\"\n"
63 .
/usr
/share
/libubox
/jshn.sh
65 json_load_file
"$json"
67 json_select string
1>/dev
/null
2>&1
70 for key
in ${keys}; do
71 json_get_var option
"$key"
72 config_get value
"$cfg" "$option" ""
74 config
="${config}${indent}${option} \"${value}\"\n"
80 json_select bool
1>/dev
/null
2>&1
83 for key
in ${keys}; do
84 json_get_var option
"$key"
85 config_get_bool value
"$cfg" "$option"
86 if [ "$value" = "0" ]; then
87 config
="${config}${indent}${option} false\n"
90 if [ "$value" = "1" ]; then
91 config
="${config}${indent}${option} true\n"
97 json_select list
1>/dev
/null
2>&1
100 for key
in ${keys}; do
101 json_get_var option
"$key"
103 config_list_foreach
"$cfg" "$option" add_list_option
"$option" "$indent"
104 config
="${config}${CONFIG_LIST}"
109 [ -z "$config" ] ||
{
110 printf "%s<Plugin %s>\n" "${CONFIG_STRING}" "$cfg" >> "$COLLECTD_CONF"
111 echo -e "${config}" >> "$COLLECTD_CONF"
112 printf "%s</Plugin>\n" "${CONFIG_STRING}" >> "$COLLECTD_CONF"
115 printf "\n" >> "$COLLECTD_CONF"
121 local enable keys key option value
123 config_get
enable "$cfg" enable 0
124 [ "$enable" = "1" ] ||
return 0
126 [ -f "/usr/lib/collectd/$cfg.so" ] ||
{
127 $LOG notice
"Plugin collectd-mod-$cfg not installed"
131 [ -f "/usr/share/collectd/plugin/$cfg.json" ] ||
{
132 $LOG notice
"Configuration definition file for $cfg not found"
136 printf "LoadPlugin %s\n" "$cfg" >> "$COLLECTD_CONF"
144 process_generic
"$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"
150 local alt_config_file BaseDir Include PIDFile PluginDir TypesDB
151 local Interval ReadThreads Hostname
153 rm -f "$COLLECTD_CONF"
155 [ -f /etc
/config
/collectd
] ||
{
156 $LOG notice
"UCI config not found"
160 config_get alt_config_file globals alt_config_file
162 # If "alt_config_file" specified, use that instead
163 [ -n "$alt_config_file" ] && [ -f "$alt_config_file" ] && {
164 rm -f "$COLLECTD_CONF"
165 ln -s "$alt_config_file" "$COLLECTD_CONF"
170 config_get BaseDir globals BaseDir
"/var/run/collectd"
171 printf "BaseDir \"%s\"\n" "$BaseDir" >> "$COLLECTD_CONF"
173 config_get Include globals Include
"/tmp/collectd.d"
174 printf "Include \"%s\"\n" "$Include" >> "$COLLECTD_CONF"
177 config_get PIDFile globals PIDFile
"/var/run/collectd.pid"
178 printf "PIDFile \"%s\"\n" "$PIDFile" >> "$COLLECTD_CONF"
180 config_get PluginDir globals PluginDir
"/usr/lib/collectd"
181 printf "PluginDir \"%s\"\n" "$PluginDir" >> "$COLLECTD_CONF"
183 config_get TypesDB globals TypesDB
"/usr/share/collectd/types.db"
184 printf "TypesDB \"%s\"\n" "$TypesDB" >> "$COLLECTD_CONF"
186 config_get Interval globals Interval
30
187 printf "Interval \"%s\"\n" "$Interval" >> "$COLLECTD_CONF"
189 config_get ReadThreads globals ReadThreads
2
190 printf "ReadThreads \"%s\"\n" "$ReadThreads" >> "$COLLECTD_CONF"
192 config_get Hostname globals Hostname
"$(uname -n)"
193 printf "Hostname \"%s\"\n" "$Hostname" >> "$COLLECTD_CONF"
195 printf "\n" >> "$COLLECTD_CONF"
198 config_foreach process_plugins plugin
205 procd_set_param
command /usr
/sbin
/collectd
206 procd_append_param
command -C "$COLLECTD_CONF"
207 procd_append_param
command -f # don't daemonize
208 procd_set_param nice
"$NICEPRIO"
209 procd_set_param stderr
1
210 procd_set_param respawn