diff --git a/README.rst b/README.rst index 02ec5aa..9035561 100644 --- a/README.rst +++ b/README.rst @@ -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 `_ +- ``connect_timeout``: value passed to curl ``--connect-timeout`` argument, defaults to ``15``; see `curl connect-timeout argument `_ +- ``max_time``: value passed to curl ``--max-time`` argument, defaults to ``30``; see `curl connect-timeout argument `_ Automatic registration ---------------------- diff --git a/openwisp-config/files/openwisp.agent b/openwisp-config/files/openwisp.agent index 69c8a96..90f0179 100644 --- a/openwisp-config/files/openwisp.agent +++ b/openwisp-config/files/openwisp.agent @@ -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" @@ -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" @@ -51,7 +55,7 @@ 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 @@ -59,10 +63,6 @@ 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 ',' ' ') diff --git a/openwisp-config/files/openwisp.config b/openwisp-config/files/openwisp.config index f08c053..efde460 100644 --- a/openwisp-config/files/openwisp.config +++ b/openwisp-config/files/openwisp.config @@ -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' diff --git a/openwisp-config/files/openwisp.init b/openwisp-config/files/openwisp.init index 135c0c5..a219d83 100644 --- a/openwisp-config/files/openwisp.init +++ b/openwisp-config/files/openwisp.init @@ -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 @@ -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 @@ -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" \