[packages] radvd: bump to v1.8 - solves size regression (#9733)
[openwrt/svn-archive/archive.git] / net / smtptrapd / files / smtptrapd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3
4 START=90
5
6 NAME="smtptrapd"
7 DAEMON="/usr/sbin/$NAME"
8 RUN_D="/var/run"
9
10 EXTRA_COMMANDS="list status exconf"
11 EXTRA_HELP=" list Lists available configurations
12 status Prints status of the service
13 exconf Shows an example config file
14
15 The actions start, stop, restart, reload, status operate
16 globally on all configurations unless the particular
17 configuration has been provided as the next parameter.
18 "
19
20 check_req() {
21 if [ -x "$DAEMON" ]; then
22 return 0
23 else
24 echo "The daemon binary is missing!"
25 return 1
26 fi
27 }
28
29 check_section() {
30 echo "$1" | grep -vq '^cfg[[:xdigit:]]\{6\}$'
31 }
32
33 start_service() {
34 local cfg="$1"
35 local named="$2"
36 check_section "$cfg" || return 1
37 [ "$named" != "" -a "$cfg" != "$named" ] && return 0
38 local args listen_ip banner_host username num_threads listen_port accept_queue_len
39 config_get listen_ip "$cfg" listen_ip
40 [ -n "$listen_ip" ] && append args "-l $listen_ip"
41 config_get listen_port "$cfg" listen_port
42 [ -n "$listen_port" ] && append args "-p $listen_port"
43 config_get username "$cfg" username
44 [ -n "$username" ] && append args "-u $username"
45 config_get banner_host "$cfg" banner_host
46 [ -n "$banner_host" ] && append args "-b \"$banner_host\""
47 config_get num_threads "$cfg" num_threads
48 [ -n "$num_threads" ] && append args "-t $num_threads"
49 config_get accept_queue_len "$cfg" accept_queue_len
50 [ -n "$accept_queue_len" ] && append args "-m $accept_queue_len"
51 append args "-f ${RUN_D}/${NAME}-${cfg}.pid"
52 eval "$DAEMON $args"
53 }
54
55 stop_service() {
56 local cfg="$1"
57 local named="$2"
58 check_section "$cfg" || return 1
59 [ "$named" != "" -a "$cfg" != "$named" ] && return 0
60 local PID_F="${RUN_D}/${NAME}-${cfg}.pid"
61 [ -f $PID_F ] && {
62 local ppid=$(cat $PID_F)
63 ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>" && kill $ppid
64 rm -f $PID_F
65 }
66 }
67
68 status_service() {
69 local cfg="$1"
70 local named="$2"
71 check_section "$cfg" || return 1
72 [ "$named" != "" -a "$cfg" != "$named" ] && return 0
73 local PID_F="${RUN_D}/${NAME}-${cfg}.pid"
74 [ -f $PID_F ] && {
75 local ppid=$(cat $PID_F)
76 if ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>"; then
77 echo "$cfg (pid $ppid) is running"
78 else
79 echo "$cfg is not running (stale pid file exists)"
80 fi
81 }
82 }
83
84 list_service() {
85 local cfg="$1"
86 check_section "$cfg" || return 1
87 echo " $cfg"
88 }
89
90 start() {
91 local svc_cfg="$1"
92 check_req || return 1
93 [ ! -d $RUN_D ] && mkdir -p $RUN_D
94 config_load "$NAME"
95 config_foreach start_service "$NAME" "$svc_cfg"
96 }
97
98 stop() {
99 local svc_cfg="$1"
100 check_req || return 1
101 config_load "/etc/config/$NAME"
102 if [ -n "$svc_cfg" ]; then
103 config_foreach stop_service "$NAME" "$svc_cfg"
104 else
105 config_foreach stop_service "$NAME"
106 local pf
107 for pf in $(ls ${RUN_D}/${NAME}*.pid 2>/dev/null); do
108 local ppid=$(cat $pf)
109 ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>" && kill "$ppid"
110 rm -f $pf
111 done
112 fi
113 }
114
115 status() {
116 local svc_cfg="$1"
117 check_req || return 1
118 config_load "$NAME"
119 config_foreach status_service "$NAME" "$svc_cfg"
120 }
121
122 list() {
123 check_req || return 1
124 echo "Available $NAME configurations:"
125 config_load "$NAME"
126 config_foreach list_service "$NAME"
127 }
128
129 exconf() {
130 echo "An example configuration in /etc/config/$NAME:" >&2
131 cat <<EOF
132 config '$NAME' 'myfailhost'
133 option 'num_threads' '1'
134
135 # The init script operates only with named sections
136 # All options (default values)
137 # option 'banner_host' '<hostname>'
138 # option 'username' 'nobody'
139 # option 'listen_ip' '<all addresses>'
140 # option 'listen_port' '25'
141 # option 'num_threads' '10'
142 # option 'accept_queue_len' '100'
143 EOF
144 }