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
|
2013-12-09 17:29:44 +00:00
|
|
|
PIDCOUNT=0
|
2013-07-08 16:35:19 +00:00
|
|
|
|
|
|
|
USE_PROCD=1
|
|
|
|
PROG=/sbin/logread
|
|
|
|
|
2013-11-20 16:56:41 +00:00
|
|
|
validate_log_section()
|
|
|
|
{
|
|
|
|
uci_validate_section system system "${1}" \
|
2013-11-25 08:34:31 +00:00
|
|
|
'log_file:string' \
|
2013-11-20 16:56:41 +00:00
|
|
|
'log_size:uinteger' \
|
|
|
|
'log_ip:ipaddr' \
|
2014-07-01 10:26:10 +00:00
|
|
|
'log_remote:bool:1' \
|
2013-11-20 16:56:41 +00:00
|
|
|
'log_port:port:514' \
|
2013-11-28 11:33:49 +00:00
|
|
|
'log_proto:or("tcp", "udp"):udp' \
|
2015-04-09 10:32:18 +00:00
|
|
|
'log_trailer_null:bool:0' \
|
2013-11-20 16:56:41 +00:00
|
|
|
'log_prefix:string'
|
|
|
|
}
|
|
|
|
|
2014-03-12 19:33:18 +00:00
|
|
|
validate_log_daemon()
|
|
|
|
{
|
|
|
|
uci_validate_section system system "${1}" \
|
2014-03-18 19:22:38 +00:00
|
|
|
'log_size:uinteger:0' \
|
|
|
|
'log_buffer_size:uinteger:0'
|
2014-03-12 19:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start_service_daemon()
|
|
|
|
{
|
2014-03-18 19:22:38 +00:00
|
|
|
local log_buffer_size log_size
|
2014-03-12 19:33:18 +00:00
|
|
|
validate_log_daemon "${1}"
|
2014-03-18 19:22:38 +00:00
|
|
|
[ $log_buffer_size -eq 0 -a $log_size -gt 0 ] && log_buffer_size=$log_size
|
|
|
|
[ $log_buffer_size -eq 0 ] && log_buffer_size=16
|
2014-03-12 19:33:18 +00:00
|
|
|
procd_open_instance
|
|
|
|
procd_set_param command "/sbin/logd"
|
|
|
|
procd_append_param command -S "${log_buffer_size}"
|
|
|
|
procd_set_param respawn
|
|
|
|
procd_close_instance
|
|
|
|
}
|
|
|
|
|
2013-07-08 16:35:19 +00:00
|
|
|
start_service_file()
|
|
|
|
{
|
2013-12-09 17:29:44 +00:00
|
|
|
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
|
2013-07-08 16:35:19 +00:00
|
|
|
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()
|
|
|
|
{
|
2013-12-09 17:29:44 +00:00
|
|
|
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
|
2013-07-08 16:35:19 +00:00
|
|
|
local pid_file="/var/run/logread.${PIDCOUNT}.pid"
|
2015-04-09 10:32:18 +00:00
|
|
|
local log_ip log_port log_proto log_prefix log_remote log_trailer_null
|
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
|
|
|
|
}
|
2014-07-02 12:56:20 +00:00
|
|
|
[ "${log_remote}" -ne 0 ] || return
|
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"
|
2015-04-09 10:32:18 +00:00
|
|
|
case "${log_proto}" in
|
|
|
|
"udp") procd_append_param command -u;;
|
|
|
|
"tcp") [ "${log_trailer_null}" -eq 1 ] && procd_append_param command -0;;
|
|
|
|
esac
|
2014-03-12 19:33:18 +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()
|
|
|
|
{
|
2014-02-18 13:33:43 +00:00
|
|
|
procd_add_reload_trigger "system"
|
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()
|
|
|
|
{
|
|
|
|
config_load system
|
2014-03-12 19:33:18 +00:00
|
|
|
config_foreach start_service_daemon system
|
2013-07-08 16:35:19 +00:00
|
|
|
config_foreach start_service_file system
|
|
|
|
config_foreach start_service_remote system
|
|
|
|
}
|