procd: default to udp log protocol to keep backwards compat with busybox
[openwrt.git] / package / system / procd / files / log.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2013 OpenWrt.org
3
4 # start after and stop before networking
5 START=21
6 STOP=89
7
8 USE_PROCD=1
9 NAME=logread
10 PROG=/sbin/logread
11 PIDCOUNT=1
12
13 start_service_file()
14 {
15         local pid_file="/var/run/logread.${PIDCOUNT}.pid"
16         local log_file log_size
17
18         config_get log_file $1 log_file
19         config_get log_size $1 log_size
20
21         [ -z "${log_file}" ] && return
22
23         procd_open_instance
24         procd_set_param command "$PROG" -f -F "$log_file" -p "$pid_file"
25         [ -n "${log_size}" ] && procd_append_param command -S "$log_size"
26         procd_close_instance
27
28         PIDCOUNT="$(( ${PIDCOUNT} + 1))"
29 }
30
31 start_service_remote()
32 {
33         local pid_file="/var/run/logread.${PIDCOUNT}.pid"
34         local log_ip log_port log_proto
35
36         config_get log_ip $1 log_ip
37         config_get log_port $1 log_port
38         config_get log_proto $1 log_proto
39
40         [ -z "${log_ip}" ] && return
41
42         procd_open_instance
43         procd_set_param command "$PROG" -f -r "$log_ip" "${log_port:-514}" -p "$pid_file"
44         [ "${log_proto}" != "udp" ] || procd_append_param command -u
45         procd_close_instance
46
47         PIDCOUNT="$(( ${PIDCOUNT} + 1))"
48 }
49
50 service_triggers()
51 {
52         procd_add_config_trigger "system" "/etc/init.d/log" "start"
53 }
54
55 start_service()
56 {
57         config_load system
58         config_foreach start_service_file system
59         config_foreach start_service_remote system
60 }