1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
7 DAEMON
="/usr/sbin/$NAME"
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
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.
21 if [ -x "$DAEMON" ]; then
24 echo "The daemon binary is missing!"
30 echo "$1" |
grep -vq '^cfg[[:xdigit:]]\{6\}$'
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"
58 check_section
"$cfg" ||
return 1
59 [ "$named" != "" -a "$cfg" != "$named" ] && return 0
60 local PID_F
="${RUN_D}/${NAME}-${cfg}.pid"
62 local ppid
=$
(cat $PID_F)
63 ps |
grep "^[[:space:]]*$ppid[[:space:]]" |
grep -q "[s]mtptrapd\>" && kill $ppid
71 check_section
"$cfg" ||
return 1
72 [ "$named" != "" -a "$cfg" != "$named" ] && return 0
73 local PID_F
="${RUN_D}/${NAME}-${cfg}.pid"
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"
79 echo "$cfg is not running (stale pid file exists)"
86 check_section
"$cfg" ||
return 1
93 [ ! -d $RUN_D ] && mkdir
-p $RUN_D
95 config_foreach start_service
"$NAME" "$svc_cfg"
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"
105 config_foreach stop_service
"$NAME"
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"
117 check_req ||
return 1
119 config_foreach status_service
"$NAME" "$svc_cfg"
123 check_req ||
return 1
124 echo "Available $NAME configurations:"
126 config_foreach list_service
"$NAME"
130 echo "An example configuration in /etc/config/$NAME:" >&2
132 config '$NAME' 'myfailhost'
133 option 'num_threads' '1'
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'