2013-07-08 16:35:19 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2013 OpenWrt.org
|
|
|
|
|
|
|
|
# start after and stop before networking
|
2013-11-16 20:20:30 +00:00
|
|
|
START=12
|
2013-07-08 16:35:19 +00:00
|
|
|
STOP=89
|
|
|
|
|
|
|
|
USE_PROCD=1
|
|
|
|
PROG=/sbin/logread
|
|
|
|
|
2013-11-20 16:56:41 +00:00
|
|
|
validate_log_section()
|
|
|
|
{
|
|
|
|
uci_validate_section system system "${1}" \
|
|
|
|
'Password:string' \
|
|
|
|
'log_size:uinteger' \
|
|
|
|
'log_ip:ipaddr' \
|
|
|
|
'log_port:port:514' \
|
|
|
|
'log_proto:or("tcp", "udp"):udp' \
|
|
|
|
'log_prefix:string'
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2013-07-08 16:35:19 +00:00
|
|
|
start_service_file()
|
|
|
|
{
|
|
|
|
local pid_file="/var/run/logread.${PIDCOUNT}.pid"
|
|
|
|
local log_file log_size
|
|
|
|
|
2013-11-20 16:56:41 +00:00
|
|
|
validate_log_section "${1}" || {
|
|
|
|
echo "validation failed"
|
|
|
|
return 1
|
|
|
|
}
|
2013-07-08 16:35:19 +00:00
|
|
|
[ -z "${log_file}" ] && return
|
|
|
|
|
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command "$PROG" -f -F "$log_file" -p "$pid_file"
|
2013-09-23 21:58:36 +00:00
|
|
|
[ -n "${log_size}" ] && procd_append_param command -S "$log_size"
|
2013-07-08 16:35:19 +00:00
|
|
|
procd_close_instance
|
|
|
|
}
|
|
|
|
|
|
|
|
start_service_remote()
|
|
|
|
{
|
|
|
|
local pid_file="/var/run/logread.${PIDCOUNT}.pid"
|
2013-11-20 16:56:41 +00:00
|
|
|
local log_ip log_port log_proto log_prefix
|
2013-07-08 16:35:19 +00:00
|
|
|
|
2013-11-20 16:56:41 +00:00
|
|
|
validate_log_section "${1}" || {
|
|
|
|
echo "validation failed"
|
|
|
|
return 1
|
|
|
|
}
|
2013-07-11 21:16:25 +00:00
|
|
|
[ -z "${log_ip}" ] && return
|
2013-07-08 16:35:19 +00:00
|
|
|
|
|
|
|
procd_open_instance
|
2013-11-20 16:56:41 +00:00
|
|
|
procd_set_param command "$PROG" -f -r "$log_ip" "${log_port}" -p "$pid_file"
|
2013-09-23 21:58:36 +00:00
|
|
|
[ "${log_proto}" != "udp" ] || procd_append_param command -u
|
2013-10-24 14:27:03 +00:00
|
|
|
[ -z "${log_prefix}" ] || procd_append_param command -P ${log_prefix}
|
2013-07-08 16:35:19 +00:00
|
|
|
procd_close_instance
|
|
|
|
}
|
|
|
|
|
2013-07-11 17:00:59 +00:00
|
|
|
service_triggers()
|
|
|
|
{
|
|
|
|
procd_add_config_trigger "system" "/etc/init.d/log" "start"
|
2013-11-20 16:56:41 +00:00
|
|
|
procd_add_validation validate_log_section
|
2013-07-11 17:00:59 +00:00
|
|
|
}
|
|
|
|
|
2013-07-08 16:35:19 +00:00
|
|
|
start_service()
|
|
|
|
{
|
2013-11-16 20:20:30 +00:00
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command "/sbin/logd"
|
|
|
|
procd_set_param respawn
|
|
|
|
procd_close_instance
|
|
|
|
|
2013-07-08 16:35:19 +00:00
|
|
|
config_load system
|
|
|
|
config_foreach start_service_file system
|
|
|
|
config_foreach start_service_remote system
|
|
|
|
}
|