rendered paste bodyconfig/matrixtunnel
-------------------
config matrixtunnel my1sttunnel
option enable '0'
option cacert ''
option privkey ''
option listen_host ''
option listen_port ''
option remote_host ''
option remote_port ''
option syslog_enable 0
option syslog_loglevel 0
config matrixtunnel 2ndtunnel
option enable '0'
option cacert ''
option privkey ''
option listen_host ''
option listen_port ''
option remote_host ''
option remote_port ''
option syslog_enable 0
option syslog_loglevel 0
init.d/matrixtunnel
-------------------
#!/bin/sh /etc/rc.common
# Copyright (C) 2007 X-Wrt.org
START=48
EXTRA_COMMANDS="list status"
EXTRA_HELP=" list Lists available configurations
status Print status of the service
The actions start, stop, restart, status accept also another parameter
to process only the particular configuration.
"
matrixtunnel_start() {
local cfg="$1"
[ -z "$cfg" ] && return 1
local startcfg="$2"
[ -n "$startcfg" -a "$startcfg" != "$cfg" ] && return 0
local enable cacert privkey listenip listenport remoteip remoteport syslogenable sysloglevel
local OPTIONS pidfile
[ -n "$(echo "$cfg" | grep "^cfg[[:digit:]]*$")" ] && {
echo "The confugration section is missing the name!"
return 1
}
config_get_bool enable "$cfg" enable 0
[ 1 -eq "$enable" ] && return 0
config_get cacert "$cfg" cacert 0
config_get privkey "$cfg" privkey 0
[ "$cacert" == "" -o "$privkey" == "" ] && {
echo "The ssl certificates are missing in the $cfg configuration!"
return 1
}
OPTIONS="-A $cacert -p $privkey -d "
config_get listenip "$cfg" listen_host 0
[ -n "$listenip" ] && OPTIONS="$OPTIONS$listenip:"
config_get listenport "$cfg" listen_port 0
[ "$listenport" -lt 1 -o "$listenport" -gt 65535 ] 2>/dev/null && {
echo "The listen_port is invalid in the $cfg configuration!"
return 1
}
OPTIONS="$OPTIONS$listenport -r "
config_get remoteip "$cfg" remote_host 0
[ -n "$remoteip" ] && OPTIONS="$OPTIONS$remoteip:"
config_get remoteport "$cfg" remote_port 0
[ "$remoteport" -lt 1 -o "$remoteport" -gt 65535 ] 2>/dev/null && {
echo "The remote_port is invalid in the $cfg configuration!"
return 1
}
OPTIONS="$OPTIONS$remoteport"
config_get_bool syslogenable "$cfg" enable 0
[ 1 -eq "$syslogenable" ] && {
config_get sysloglevel "$cfg" syslog_loglevel 0
sysloglevel="${sysloglevel:-0}"
[ "$sysloglevel" -lt 0 -a "$sysloglevel" -gt 8 ] 2>/dev/null && sysloglevel=0
OPTIONS="$OPTIONS -D $sysloglevel"
}
pidfile="/var/run/matrixtunnel-${cfg}.pid"
$MT_BIN $OPTIONS -P $pidfile
}
matrixtunnel_stop() {
local cfg="$1"
[ -z "$cfg" ] && return 1
local stopcfg="$2"
[ -n "$stopcfg" -a "$stopcfg" != "$cfg" ] && return 1
local pid
pidfile="/var/run/matrixtunnel-${cfg}.pid"
[ -f "$pidfile" ] && {
pid=$(cat "$pidfile")
[ -n "$pid" -a -d "/proc/$pid" ] && {
echo -n "Stopping the matrixtunnel $cfg configuration (pid $pid)..."
kill -TERM "$pid"
[ "$?" -eq 0 ] && echo "OK" || {
echo "Failed!"
echo -n "Killing the matrixtunnel $cfg configuration (pid $pid)..."
kill -KILL "$pid"
[ "$?" -eq 0 ] && echo "OK" || echo "Failed!"
}
}
rm -f "$pidfile" 2>/dev/null
}
}
matrixtunnel_status() {
local cfg="$1"
[ -z "$cfg" ] && return 1
local statuscfg="$2"
[ -n "$statuscfg" -a "$statuscfg" != "$cfg" ] && return 0
local pid
pidfile="/var/run/matrixtunnel-${cfg}.pid"
[ -f "$pidfile" ] && {
pid=$(cat "$pidfile")
[ -n "$pid" -a -d "/proc/$pid" ] && {
echo "The matrixtunnel $cfg configuration (pid $pid) is running..."
} || echo "The matrixtunnel $cfg configuration (pid $pid) is not running!"
} || echo "The matrixtunnel $cfg configuration is not running!"
}
matrixtunnel_list() {
local cfg="$1"
echo " $cfg"
}
start() {
local mtconfig="$1"
MT_BIN=$(which matrixtunnel 2>/dev/null)
[ -z "$MT_BIN" -o ! -x "$MT_BIN" ] && {
echo "The matrixtunnel binary is missing or is not executable!"
return 1
}
config_load matrixtunnel
config_foreach matrixtunnel_start matrixtunnel "$mtconfig"
}
stop() {
local mtconfig="$1"
config_load matrixtunnel
config_foreach matrixtunnel_stop matrixtunnel "$mtconfig"
}
restart() {
local mtconfig="$1"
stop "$mtconfig"
start "$mtconfig"
}
status() {
local mtconfig="$1"
config_load matrixtunnel
config_foreach matrixtunnel_status matrixtunnel "$mtconfig"
}
list() {
echo "Available matrixtunnel configurations:"
config_load matrixtunnel
config_foreach matrixtunnel_list matrixtunnel
}