Skip to content

Commit

Permalink
Add option to have minion retry dns
Browse files Browse the repository at this point in the history
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
UtahDave authored and saltstack committed Nov 10, 2012
1 parent 9049ef6 commit d4f7f5c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions conf/minion.template
Expand Up @@ -10,6 +10,11 @@
# resolved, then the minion will fail to start. # resolved, then the minion will fail to start.
#master: salt #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 # Set the port used by the master reply and authentication server
#master_port: 4506 #master_port: 4506


Expand Down
2 changes: 1 addition & 1 deletion salt/__init__.py
Expand Up @@ -81,6 +81,7 @@ def start(self):
''' '''
Execute this method to start up a minion. Execute this method to start up a minion.
''' '''
self.daemonize_if_required()
self.parse_args() self.parse_args()


try: try:
Expand Down Expand Up @@ -113,7 +114,6 @@ def start(self):
# waiting for it, if we daemonize later then the minion could halt # 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. # the boot process waiting for a key to be accepted on the master.
# This is the latest safe place to daemonize # This is the latest safe place to daemonize
self.daemonize_if_required()
try: try:
minion = salt.minion.Minion(self.config) minion = salt.minion.Minion(self.config)
self.set_pidfile() self.set_pidfile()
Expand Down
4 changes: 3 additions & 1 deletion salt/config.py
Expand Up @@ -212,6 +212,7 @@ def minion_config(path):
'default_include': 'minion.d/*.conf', 'default_include': 'minion.d/*.conf',
'update_url': False, 'update_url': False,
'update_restart_services': [], 'update_restart_services': [],
'retry_dns': 30,
} }


if len(opts['sock_dir']) > len(opts['cachedir']) + 10: if len(opts['sock_dir']) > len(opts['cachedir']) + 10:
Expand All @@ -229,7 +230,8 @@ def minion_config(path):
opts['id'] = _append_domain(opts) opts['id'] = _append_domain(opts)


try: 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: except SaltClientError:
opts['master_ip'] = '127.0.0.1' opts['master_ip'] = '127.0.0.1'


Expand Down
14 changes: 13 additions & 1 deletion salt/utils/__init__.py
Expand Up @@ -310,7 +310,7 @@ def gen_mac(prefix='52:54:'):
return mac[:-1] 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 Return the ip resolved by dns, but do not exit on failure, only raise an
exception. exception.
Expand All @@ -325,6 +325,18 @@ def dns_check(addr, safe=False):
err = ('This master address: \'{0}\' was previously resolvable ' err = ('This master address: \'{0}\' was previously resolvable '
'but now fails to resolve! The previously resolved ip addr ' 'but now fails to resolve! The previously resolved ip addr '
'will continue to be used').format(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: if safe:
import salt.log import salt.log
if salt.log.is_console_configured(): if salt.log.is_console_configured():
Expand Down

0 comments on commit d4f7f5c

Please sign in to comment.