Skip to content

Commit f00ecf9

Browse files
committed
[agent] Give up registration only when 403
Keep retrying in all other cases. This allows the device to keep trying to register if there's a temporary server side issue or in case the self creation has been disabled: openwisp/django-netjsonconfig#162
1 parent 0833399 commit f00ecf9

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

openwisp-config/files/openwisp.agent

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,20 @@ register() {
188188
fi
189189
# exit if response does not seem to come from openwisp controller
190190
check_header $REGISTRATION_PARAMETERS
191-
# exit if controller returns errors
192191
if [ $(head -n 1 $REGISTRATION_PARAMETERS | grep -c "201 Created") -lt 1 ]; then
193192
local message=$(tail -n 1 $REGISTRATION_PARAMETERS)
194193
logger -s "Registration failed! $message" \
195194
-t openwisp \
196195
-p daemon.err
197-
exit 5
196+
# if controller returns 403, stop retrying because it's useless
197+
if [ $(head -n 1 $REGISTRATION_PARAMETERS | grep -c "403 Forbidden") -gt 0 ]; then
198+
exit 5
199+
# in all other cases, keep re-trying because the problem can be fixed
200+
# on the server (eg: self creation disabled and device needs to be created
201+
# or temporary error condition on the server)
202+
else
203+
return 2
204+
fi
198205
fi
199206
# set configuration options and reload
200207
export UUID=$(cat $REGISTRATION_PARAMETERS | grep uuid | awk '/uuid: / { print $2 }')

0 commit comments

Comments
 (0)