in azurelinuxagent/ga/update.py [0:0]
def run(self, debug=False):
"""
This is the main loop which watches for agent and extension updates.
"""
try:
logger.info("{0} (Goal State Agent version {1})", AGENT_LONG_NAME, AGENT_VERSION)
logger.info("OS: {0} {1}", DISTRO_NAME, DISTRO_VERSION)
logger.info("Python: {0}.{1}.{2}", PY_VERSION_MAJOR, PY_VERSION_MINOR, PY_VERSION_MICRO)
vm_arch = self.osutil.get_vm_arch()
logger.info("CPU Arch: {0}", vm_arch)
os_info_msg = u"Distro: {dist_name}-{dist_ver}; "\
u"OSUtil: {util_name}; "\
u"AgentService: {service_name}; "\
u"Python: {py_major}.{py_minor}.{py_micro}; "\
u"Arch: {vm_arch}; "\
u"systemd: {systemd}; "\
u"systemd_version: {systemd_version}; "\
u"LISDrivers: {lis_ver}; "\
u"logrotate: {has_logrotate};".format(
dist_name=DISTRO_NAME, dist_ver=DISTRO_VERSION,
util_name=type(self.osutil).__name__,
service_name=self.osutil.service_name,
py_major=PY_VERSION_MAJOR, py_minor=PY_VERSION_MINOR,
py_micro=PY_VERSION_MICRO, vm_arch=vm_arch, systemd=systemd.is_systemd(),
systemd_version=systemd.get_version(),
lis_ver=get_lis_version(), has_logrotate=has_logrotate()
)
logger.info(os_info_msg)
#
# Initialize the goal state; some components depend on information provided by the goal state and this
# call ensures the required info is initialized (e.g. telemetry depends on the container ID.)
#
protocol = self.protocol_util.get_protocol(save_to_history=True)
self._initialize_goal_state(protocol)
# Initialize the common parameters for telemetry events
initialize_event_logger_vminfo_common_parameters_and_protocol(protocol)
# Send telemetry for the OS-specific info.
add_event(AGENT_NAME, op=WALAEventOperation.OSInfo, message=os_info_msg)
self._log_openssl_info()
#
# Perform initialization tasks
#
self._initialize_firewall(protocol.get_endpoint())
from azurelinuxagent.ga.exthandlers import get_exthandlers_handler, migrate_handler_state
exthandlers_handler = get_exthandlers_handler(protocol)
migrate_handler_state()
from azurelinuxagent.ga.remoteaccess import get_remote_access_handler
remote_access_handler = get_remote_access_handler(protocol)
agent_update_handler = get_agent_update_handler(protocol)
self._ensure_no_orphans()
self._emit_restart_event()
self._emit_changes_in_default_configuration()
self._ensure_readonly_files()
self._ensure_cgroups_initialized()
self._ensure_extension_telemetry_state_configured_properly(protocol)
self._cleanup_legacy_goal_state_history()
# Get all thread handlers
telemetry_handler = get_send_telemetry_events_handler(self.protocol_util)
all_thread_handlers = [
get_monitor_handler(),
get_env_handler(),
telemetry_handler,
get_collect_telemetry_events_handler(telemetry_handler)
]
if is_log_collection_allowed():
all_thread_handlers.append(get_collect_logs_handler())
# Launch all monitoring threads
self._start_threads(all_thread_handlers)
logger.info("Goal State Period: {0} sec. This indicates how often the agent checks for new goal states and reports status.", self._goal_state_period)
while self.is_running:
self._check_daemon_running(debug)
self._check_threads_running(all_thread_handlers)
self._process_goal_state(exthandlers_handler, remote_access_handler, agent_update_handler)
self._send_heartbeat_telemetry(agent_update_handler)
self._check_agent_memory_usage()
time.sleep(self._goal_state_period)
except AgentUpgradeExitException as exitException:
add_event(op=WALAEventOperation.AgentUpgrade, message=exitException.reason, log_event=False)
logger.info(exitException.reason)
except ExitException as exitException:
logger.info(exitException.reason)
except Exception as error:
msg = u"Agent {0} failed with exception: {1}".format(CURRENT_AGENT, ustr(error))
self._set_sentinel(msg=msg)
logger.warn(msg)
logger.warn(textutil.format_exception(error))
sys.exit(1)
# additional return here because sys.exit is mocked in unit tests
return # pylint: disable=unreachable
self._shutdown()
sys.exit(0)