summaryrefslogtreecommitdiff
path: root/azurelinuxagent/distro/default/daemon.py
diff options
context:
space:
mode:
authorBen Howard <ben.howard@ubuntu.com>2016-02-08 16:33:07 -0700
committerusd-importer <ubuntu-server@lists.ubuntu.com>2016-02-09 00:59:05 +0000
commita00729ff7421b3661e8b1a1e0fa46393379f2e96 (patch)
tree4563b927e3a57446a4a928a72a92d72c9ad4f6e6 /azurelinuxagent/distro/default/daemon.py
parent53f54030cae2de3d5fa474a61fe51f16c7a07c79 (diff)
downloadvyos-walinuxagent-a00729ff7421b3661e8b1a1e0fa46393379f2e96.tar.gz
vyos-walinuxagent-a00729ff7421b3661e8b1a1e0fa46393379f2e96.zip
Import patches-unapplied version 2.1.3-0ubuntu1 to ubuntu/xenial-proposed
Imported using git-ubuntu import. Changelog parent: 53f54030cae2de3d5fa474a61fe51f16c7a07c79 New changelog entries: * New upstream release (LP: #1543359): - Bug fixes for extension handling - Feature enablement for AzureStack.
Diffstat (limited to 'azurelinuxagent/distro/default/daemon.py')
-rw-r--r--azurelinuxagent/distro/default/daemon.py103
1 files changed, 103 insertions, 0 deletions
diff --git a/azurelinuxagent/distro/default/daemon.py b/azurelinuxagent/distro/default/daemon.py
new file mode 100644
index 0000000..cf9eb16
--- /dev/null
+++ b/azurelinuxagent/distro/default/daemon.py
@@ -0,0 +1,103 @@
+# Microsoft Azure Linux Agent
+#
+# Copyright 2014 Microsoft Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Requires Python 2.4+ and Openssl 1.0+
+#
+
+import os
+import time
+import sys
+import traceback
+import azurelinuxagent.conf as conf
+import azurelinuxagent.logger as logger
+from azurelinuxagent.future import ustr
+from azurelinuxagent.event import add_event, WALAEventOperation
+from azurelinuxagent.exception import ProtocolError
+from azurelinuxagent.metadata import AGENT_LONG_NAME, AGENT_VERSION, \
+ DISTRO_NAME, DISTRO_VERSION, \
+ DISTRO_FULL_NAME, PY_VERSION_MAJOR, \
+ PY_VERSION_MINOR, PY_VERSION_MICRO
+import azurelinuxagent.event as event
+import azurelinuxagent.utils.fileutil as fileutil
+
+
+class DaemonHandler(object):
+ def __init__(self, distro):
+ self.distro = distro
+ self.running = True
+
+
+ def run(self):
+ logger.info("{0} 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)
+
+ self.check_pid()
+
+ while self.running:
+ try:
+ self.daemon()
+ except Exception as e:
+ err_msg = traceback.format_exc()
+ add_event("WALA", is_success=False, message=ustr(err_msg),
+ op=WALAEventOperation.UnhandledError)
+ logger.info("Sleep 15 seconds and restart daemon")
+ time.sleep(15)
+
+ def check_pid(self):
+ """Check whether daemon is already running"""
+ pid = None
+ pid_file = conf.get_agent_pid_file_path()
+ if os.path.isfile(pid_file):
+ pid = fileutil.read_file(pid_file)
+
+ if pid is not None and os.path.isdir(os.path.join("/proc", pid)):
+ logger.info("Daemon is already running: {0}", pid)
+ sys.exit(0)
+
+ fileutil.write_file(pid_file, ustr(os.getpid()))
+
+ def daemon(self):
+ logger.info("Run daemon")
+ #Create lib dir
+ if not os.path.isdir(conf.get_lib_dir()):
+ fileutil.mkdir(conf.get_lib_dir(), mode=0o700)
+ os.chdir(conf.get_lib_dir())
+
+ if conf.get_detect_scvmm_env():
+ if self.distro.scvmm_handler.run():
+ return
+
+ self.distro.provision_handler.run()
+
+ if conf.get_resourcedisk_format():
+ self.distro.resource_disk_handler.run()
+
+ try:
+ protocol = self.distro.protocol_util.detect_protocol()
+ except ProtocolError as e:
+ logger.error("Failed to detect protocol, exit", e)
+ return
+
+ self.distro.event_handler.run()
+ self.distro.env_handler.run()
+
+ while self.running:
+ #Handle extensions
+ self.distro.ext_handlers_handler.run()
+ time.sleep(25)
+