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()
|
|
|
|
{
|
2019-01-12 18:14:22 +00:00
|
|
|
uci_load_validate system system "$1" "$2" \
|
2013-11-25 08:34:31 +00:00
|
|
|
'log_file:string' \
|
2013-11-20 16:56:41 +00:00
|
|
|
'log_size:uinteger' \
|
2016-05-06 19:05:41 +00:00
|
|
|
'log_hostname:string' \
|
2013-11-20 16:56:41 +00:00
|
|
|
'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()
|
|
|
|
{
|
2019-01-12 18:14:22 +00:00
|
|
|
uci_load_validate system system "$1" "$2" \
|
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
|
|
|
[ $log_buffer_size -eq 0 -a $log_size -gt 0 ] && log_buffer_size=$log_size
|
2016-06-08 13:12:55 +00:00
|
|
|
[ $log_buffer_size -eq 0 ] && log_buffer_size=64
|
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}"
|
2018-02-14 08:28:52 +00:00
|
|
|
procd_set_param respawn 5 1 -1
|
2014-03-12 19:33:18 +00:00
|
|
|
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"
|
|
|
|
|
2019-01-12 18:14:22 +00:00
|
|
|
[ "$2" = 0 ] || {
|
2013-11-20 16:56:41 +00:00
|
|
|
echo "validation failed"
|
|
|
|
return 1
|
|
|
|
}
|
2013-07-08 16:35:19 +00:00
|
|
|
[ -z "${log_file}" ] && return
|
|
|
|
|
2018-02-22 11:09:53 +00:00
|
|
|
mkdir -p "$(dirname "${log_file}")"
|
|
|
|
|
2013-07-08 16:35:19 +00:00
|
|
|
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"
|
|
|
|
|
2019-01-12 18:14:22 +00:00
|
|
|
[ "$2" = 0 ] || {
|
2013-11-20 16:56:41 +00:00
|
|
|
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
|
2016-05-06 19:05:41 +00:00
|
|
|
[ -z "${log_hostname}" ] && log_hostname=$(cat /proc/sys/kernel/hostname)
|
2013-07-08 16:35:19 +00:00
|
|
|
|
|
|
|
procd_open_instance
|
2016-05-06 19:05:41 +00:00
|
|
|
procd_set_param command "$PROG" -f -h "$log_hostname" -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
|
2019-01-12 18:14:22 +00:00
|
|
|
config_foreach validate_log_daemon system start_service_daemon
|
|
|
|
config_foreach validate_log_section system start_service_file
|
|
|
|
config_foreach validate_log_section system start_service_remote
|
2013-07-08 16:35:19 +00:00
|
|
|
}
|