packages/smtptrapd: use new service functions
git-svn-id: svn://svn.openwrt.org/openwrt/packages@29217 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
cc2421aabe
commit
3dc7679e7a
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2008-2009 OpenWrt.org
|
# Copyright (C) 2008-2011 OpenWrt.org
|
||||||
#
|
#
|
||||||
# This is free software, licensed under the GNU General Public License v2.
|
# This is free software, licensed under the GNU General Public License v2.
|
||||||
# See /LICENSE for more information.
|
# See /LICENSE for more information.
|
||||||
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=smtptrapd
|
PKG_NAME:=smtptrapd
|
||||||
PKG_VERSION:=1.5
|
PKG_VERSION:=1.5
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=2
|
||||||
|
|
||||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||||
PKG_SOURCE_URL:=@SF/$(PKG_NAME)
|
PKG_SOURCE_URL:=@SF/$(PKG_NAME)
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
# Copyright (C) 2008 OpenWrt.org
|
# Copyright (C) 2008-2011 OpenWrt.org
|
||||||
|
|
||||||
|
SERVICE_USE_PID=1
|
||||||
|
|
||||||
START=90
|
START=90
|
||||||
|
STOP=10
|
||||||
NAME="smtptrapd"
|
|
||||||
DAEMON="/usr/sbin/$NAME"
|
|
||||||
RUN_D="/var/run"
|
|
||||||
|
|
||||||
EXTRA_COMMANDS="list status exconf"
|
EXTRA_COMMANDS="list status exconf"
|
||||||
EXTRA_HELP=" list Lists available configurations
|
EXTRA_HELP=" list Lists available configurations
|
||||||
@ -17,119 +16,101 @@ globally on all configurations unless the particular
|
|||||||
configuration has been provided as the next parameter.
|
configuration has been provided as the next parameter.
|
||||||
"
|
"
|
||||||
|
|
||||||
check_req() {
|
|
||||||
if [ -x "$DAEMON" ]; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo "The daemon binary is missing!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_section() {
|
check_section() {
|
||||||
echo "$1" | grep -vq '^cfg[[:xdigit:]]\{6\}$'
|
echo "$1" | grep -vq '^cfg[[:xdigit:]]\{6\}$'
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service() {
|
start_instance() {
|
||||||
local cfg="$1"
|
local section="$1"
|
||||||
local named="$2"
|
local instance="$2"
|
||||||
check_section "$cfg" || return 1
|
|
||||||
[ "$named" != "" -a "$cfg" != "$named" ] && return 0
|
check_section "$section" || return 1
|
||||||
|
[ -n "$instance" -a "$section" != "$instance" ] && return 0
|
||||||
|
|
||||||
local args listen_ip banner_host username num_threads listen_port accept_queue_len
|
local args listen_ip banner_host username num_threads listen_port accept_queue_len
|
||||||
config_get listen_ip "$cfg" listen_ip
|
|
||||||
|
config_get listen_ip "$section" 'listen_ip'
|
||||||
[ -n "$listen_ip" ] && append args "-l $listen_ip"
|
[ -n "$listen_ip" ] && append args "-l $listen_ip"
|
||||||
config_get listen_port "$cfg" listen_port
|
|
||||||
|
config_get listen_port "$section" 'listen_port'
|
||||||
[ -n "$listen_port" ] && append args "-p $listen_port"
|
[ -n "$listen_port" ] && append args "-p $listen_port"
|
||||||
config_get username "$cfg" username
|
|
||||||
|
config_get username "$section" 'username'
|
||||||
[ -n "$username" ] && append args "-u $username"
|
[ -n "$username" ] && append args "-u $username"
|
||||||
config_get banner_host "$cfg" banner_host
|
|
||||||
[ -n "$banner_host" ] && append args "-b \"$banner_host\""
|
config_get banner_host "$section" 'banner_host'
|
||||||
config_get num_threads "$cfg" num_threads
|
[ -n "$banner_host" ] && append args "-b '$banner_host'"
|
||||||
|
|
||||||
|
config_get num_threads "$section" 'num_threads'
|
||||||
[ -n "$num_threads" ] && append args "-t $num_threads"
|
[ -n "$num_threads" ] && append args "-t $num_threads"
|
||||||
config_get accept_queue_len "$cfg" accept_queue_len
|
|
||||||
|
config_get accept_queue_len "$section" 'accept_queue_len'
|
||||||
[ -n "$accept_queue_len" ] && append args "-m $accept_queue_len"
|
[ -n "$accept_queue_len" ] && append args "-m $accept_queue_len"
|
||||||
append args "-f ${RUN_D}/${NAME}-${cfg}.pid"
|
|
||||||
eval "$DAEMON $args"
|
SERVICE_PID_FILE="/var/run/smtptrapd-${section}.pid
|
||||||
|
service_start /usr/sbin/smtptrapd -f $SERVICE_PID_FILE $args
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_service() {
|
stop_instance() {
|
||||||
local cfg="$1"
|
local section="$1"
|
||||||
local named="$2"
|
local instance="$2"
|
||||||
check_section "$cfg" || return 1
|
|
||||||
[ "$named" != "" -a "$cfg" != "$named" ] && return 0
|
check_section "$section" || return 1
|
||||||
local PID_F="${RUN_D}/${NAME}-${cfg}.pid"
|
[ -n "$instance" -a "$section" != "$instance" ] && return 0
|
||||||
[ -f $PID_F ] && {
|
|
||||||
local ppid=$(cat $PID_F)
|
SERVICE_PID_FILE="/var/run/smtptrapd-${section}.pid"
|
||||||
ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>" && kill $ppid
|
service_stop /usr/sbin/smtptrapd
|
||||||
rm -f $PID_F
|
}
|
||||||
|
|
||||||
|
check_instance() {
|
||||||
|
local section="$1"
|
||||||
|
local instance="$2"
|
||||||
|
|
||||||
|
check_section "$section" || return 1
|
||||||
|
[ -n "$instance" -a "$section" != "$instance" ] && return 0
|
||||||
|
|
||||||
|
SERVICE_PID_FILE="/var/run/smtptrapd-${section}.pid"
|
||||||
|
service_check /usr/sbin/smtptrapd && {
|
||||||
|
echo "${initscript}: configuration instance '$section' is running"
|
||||||
|
} || {
|
||||||
|
echo "${initscript}: configuration instance '$section' is not running"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status_service() {
|
list_instance() {
|
||||||
local cfg="$1"
|
local section="$1"
|
||||||
local named="$2"
|
check_section "$section" || return 1
|
||||||
check_section "$cfg" || return 1
|
echo " $section"
|
||||||
[ "$named" != "" -a "$cfg" != "$named" ] && return 0
|
|
||||||
local PID_F="${RUN_D}/${NAME}-${cfg}.pid"
|
|
||||||
[ -f $PID_F ] && {
|
|
||||||
local ppid=$(cat $PID_F)
|
|
||||||
if ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>"; then
|
|
||||||
echo "$cfg (pid $ppid) is running"
|
|
||||||
else
|
|
||||||
echo "$cfg is not running (stale pid file exists)"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list_service() {
|
|
||||||
local cfg="$1"
|
|
||||||
check_section "$cfg" || return 1
|
|
||||||
echo " $cfg"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
local svc_cfg="$1"
|
config_load 'smtptrapd'
|
||||||
check_req || return 1
|
config_foreach start_instance 'smtptrapd' "$@"
|
||||||
[ ! -d $RUN_D ] && mkdir -p $RUN_D
|
|
||||||
config_load "$NAME"
|
|
||||||
config_foreach start_service "$NAME" "$svc_cfg"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
local svc_cfg="$1"
|
config_load 'smtptrapd'
|
||||||
check_req || return 1
|
config_foreach stop_instance 'smtptrapd' "$@"
|
||||||
config_load "/etc/config/$NAME"
|
|
||||||
if [ -n "$svc_cfg" ]; then
|
|
||||||
config_foreach stop_service "$NAME" "$svc_cfg"
|
|
||||||
else
|
|
||||||
config_foreach stop_service "$NAME"
|
|
||||||
local pf
|
|
||||||
for pf in $(ls ${RUN_D}/${NAME}*.pid 2>/dev/null); do
|
|
||||||
local ppid=$(cat $pf)
|
|
||||||
ps | grep "^[[:space:]]*$ppid[[:space:]]" | grep -q "[s]mtptrapd\>" && kill "$ppid"
|
|
||||||
rm -f $pf
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status() {
|
status() {
|
||||||
local svc_cfg="$1"
|
config_load 'smtptrapd'
|
||||||
check_req || return 1
|
config_foreach check_instance 'smtptrapd' "$@"
|
||||||
config_load "$NAME"
|
|
||||||
config_foreach status_service "$NAME" "$svc_cfg"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list() {
|
list() {
|
||||||
check_req || return 1
|
config_load 'smtptrapd'
|
||||||
echo "Available $NAME configurations:"
|
echo "${initscript}: available configuration instances:"
|
||||||
config_load "$NAME"
|
config_foreach list_instance 'smtptrapd'
|
||||||
config_foreach list_service "$NAME"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exconf() {
|
exconf() {
|
||||||
echo "An example configuration in /etc/config/$NAME:" >&2
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
config '$NAME' 'myfailhost'
|
# /etc/config/smtptrapd - example configuration
|
||||||
|
|
||||||
|
package 'smtptrapd'
|
||||||
|
|
||||||
|
config 'smtptrapd' 'myfailhost'
|
||||||
option 'num_threads' '1'
|
option 'num_threads' '1'
|
||||||
|
|
||||||
# The init script operates only with named sections
|
# The init script operates only with named sections
|
||||||
|
Loading…
x
Reference in New Issue
Block a user