Browse files

Add option to have minion retry dns

If name resolution fails when the minion starts, allow the minion
to retry dns resolution after a configurable number of seconds.
Defaults to 30 seconds.

Add retry_dns option to minion config.
  • Loading branch information...
1 parent 9049ef6 commit d4f7f5cac5c1d8edec62f5ff590c7df890dcb01b @UtahDave UtahDave committed with saltstack Nov 9, 2012
Showing with 22 additions and 3 deletions.
  1. +5 −0 conf/minion.template
  2. +1 −1 salt/__init__.py
  3. +3 −1 salt/config.py
  4. +13 −1 salt/utils/__init__.py
View
5 conf/minion.template
@@ -10,6 +10,11 @@
# resolved, then the minion will fail to start.
#master: salt
+# Set the number of seconds to wait before attempting to resolve
+# the master hostname if name resolution fails. Defaults to 30 seconds.
+# Set to zero if the minion should shutdown and not retry.
+# retry_dns: 30
+
# Set the port used by the master reply and authentication server
#master_port: 4506
View
2 salt/__init__.py
@@ -81,6 +81,7 @@ def start(self):
'''
Execute this method to start up a minion.
'''
+ self.daemonize_if_required()
self.parse_args()
try:
@@ -113,7 +114,6 @@ def start(self):
# waiting for it, if we daemonize later then the minion could halt
# the boot process waiting for a key to be accepted on the master.
# This is the latest safe place to daemonize
- self.daemonize_if_required()
try:
minion = salt.minion.Minion(self.config)
self.set_pidfile()
View
4 salt/config.py
@@ -212,6 +212,7 @@ def minion_config(path):
'default_include': 'minion.d/*.conf',
'update_url': False,
'update_restart_services': [],
+ 'retry_dns': 30,
}
if len(opts['sock_dir']) > len(opts['cachedir']) + 10:
@@ -229,7 +230,8 @@ def minion_config(path):
opts['id'] = _append_domain(opts)
try:
- opts['master_ip'] = salt.utils.dns_check(opts['master'], True)
+ opts['master_ip'] = salt.utils.dns_check(opts['master'], True,
+ opts['retry_dns'])
except SaltClientError:
opts['master_ip'] = '127.0.0.1'
View
14 salt/utils/__init__.py
@@ -310,7 +310,7 @@ def gen_mac(prefix='52:54:'):
return mac[:-1]
-def dns_check(addr, safe=False):
+def dns_check(addr, safe=False, retry_dns=30):
'''
Return the ip resolved by dns, but do not exit on failure, only raise an
exception.
@@ -325,6 +325,18 @@ def dns_check(addr, safe=False):
err = ('This master address: \'{0}\' was previously resolvable '
'but now fails to resolve! The previously resolved ip addr '
'will continue to be used').format(addr)
+ if retry_dns:
+ msg = ('Hostname: \'{0}\' could not be reached.'
+ 'Waiting \'{1}\' seconds and then will try to'
+ 'resolve the name again.').format(addr, retry_dns)
+ import salt.log
+ if salt.log.is_console_configured():
+ # If logging is not configured it also means that either
+ # the master or minion instance calling this hasn't even
+ # started running
+ logging.getLogger(__name__).error(msg)
+ time.sleep(retry_dns)
+ self.dns_check(addr, safe, retry_dns)
if safe:
import salt.log
if salt.log.is_console_configured():

0 comments on commit d4f7f5c

Please sign in to comment.