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