Skip to content

Commit

Permalink
[agent] Added "connect_timeout" and "max_time" options (curl)
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Apr 14, 2016
1 parent a2e8d12 commit 93639af
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ UCI configuration options must go in ``/etc/config/openwisp``.
- ``test_config``: whether a new configuration must be tested before being considered applied, defaults to ``1``
- ``test_script``: custom test script, read more about this feature in `Configuration test`_
- ``capath``: value passed to curl ``--capath`` argument, defaults to ``/etc/ssl/certs``; see also `curl capath argument <https://curl.haxx.se/docs/manpage.html#--capath>`_
- ``connect_timeout``: value passed to curl ``--connect-timeout`` argument, defaults to ``15``; see `curl connect-timeout argument <https://curl.haxx.se/docs/manpage.html#--connect-timeout>`_
- ``max_time``: value passed to curl ``--max-time`` argument, defaults to ``30``; see `curl connect-timeout argument <https://curl.haxx.se/docs/manpage.html#-m>`_

Automatic registration
----------------------
Expand Down
10 changes: 5 additions & 5 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ while [ -n "$1" ]; do
--unmanaged) export UNMANAGED="$2"; shift;;
--test-config) export TEST_CONFIG="$2"; shift;;
--test-script) export TEST_SCRIPT="$2"; shift;;
--connect-timeout) export CONNECT_TIMEOUT="$2"; shift;;
--max-time) export MAX_TIME="$2"; shift;;
--capath) export CAPATH="$2"; shift;;
-*)
echo "Invalid option: $1"
Expand Down Expand Up @@ -39,6 +41,8 @@ fi
INTERVAL=${INTERVAL:-120}
VERIFY_SSL=${VERIFY_SSL:-1}
TEST_CONFIG=${TEST_CONFIG:-1}
CONNECT_TIMEOUT=${CONNECT_TIMEOUT:-15}
MAX_TIME=${MAX_TIME:-30}
CAPATH=${CAPATH:-/etc/ssl/certs}
WORKING_DIR="/tmp/openwisp"
BASEURL="$URL/controller"
Expand All @@ -51,18 +55,14 @@ STATUS_REPORT="$WORKING_DIR/status_report"
APPLYING_CONF="$WORKING_DIR/applying_conf"
REGISTRATION_URL="$URL/controller/register/"
UNMANAGED_DIR="$WORKING_DIR/unmanaged"
FETCH_COMMAND="curl -s"
FETCH_COMMAND="curl -s --connect-timeout $CONNECT_TIMEOUT --max-time $MAX_TIME --capath $CAPATH"
mkdir -p $WORKING_DIR
mkdir -p $UNMANAGED_DIR

if [ "$VERIFY_SSL" != "1" ]; then
FETCH_COMMAND="$FETCH_COMMAND -k"
fi

if [ -n "$CAPATH" ]; then
FETCH_COMMAND="$FETCH_COMMAND --capath $CAPATH"
fi

if [ -n "$UNMANAGED" ]; then
# replace commas with spaces
UNMANAGED=$(echo $UNMANAGED | tr ',' ' ')
Expand Down
3 changes: 3 additions & 0 deletions openwisp-config/files/openwisp.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ config controller 'http'
list unmanaged 'network.wan'
list unmanaged 'network.@switch'
list unmanaged 'network.@switch_vlan'
# curl options
#option connect_timeout '15'
#option max_time '30'
#option capath '/etc/ssl/certs'
9 changes: 7 additions & 2 deletions openwisp-config/files/openwisp.init
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ start_service() {
unmanaged=$(config_get http unmanaged)
test_config=$(config_get http test_config)
test_script=$(config_get http test_script)
connect_timeout=$(config_get http connect_timeout)
max_time=$(config_get http max_time)
capath=$(config_get http capath)
if [ $url ]; then url="--url $url"; fi
if [ $interval ]; then interval="--interval $interval"; fi
Expand All @@ -32,6 +34,8 @@ start_service() {
fi
if [ $test_config ]; then test_config="--test-config $test_config"; fi
if [ $test_script ]; then test_script="--test-script $test_script"; fi
if [ $connect_timeout ]; then connect_timeout="--connect-timeout $connect_timeout"; fi
if [ $max_time ]; then max_time="--max-time $max_time"; fi
if [ $capath ]; then capath="--capath $capath"; fi

if [ -z "$url" ]; then
Expand All @@ -49,8 +53,9 @@ start_service() {
fi

procd_open_instance
procd_set_param command $PROG $url $interval $verify_ssl $uuid $key $capath \
$shared_secret $unmanaged $test_config $test_script
procd_set_param command $PROG $url $interval $verify_ssl $uuid $key \
$shared_secret $unmanaged $test_config $test_script \
$connect_timeout $max_time $capath
procd_set_param respawn
procd_close_instance
logger -s "$PROG_NAME started" \
Expand Down

0 comments on commit 93639af

Please sign in to comment.