diff options
Diffstat (limited to 'src/ovs/daemon.py')
-rw-r--r-- | src/ovs/daemon.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/ovs/daemon.py b/src/ovs/daemon.py index 09735600..f9b037b2 100644 --- a/src/ovs/daemon.py +++ b/src/ovs/daemon.py @@ -24,13 +24,6 @@ import pexpect from conf import settings from tools import tasks -_OVS_VSWITCHD_BIN = os.path.join( - settings.getValue('OVS_DIR'), 'vswitchd', 'ovs-vswitchd') -_OVSDB_TOOL_BIN = os.path.join( - settings.getValue('OVS_DIR'), 'ovsdb', 'ovsdb-tool') -_OVSDB_SERVER_BIN = os.path.join( - settings.getValue('OVS_DIR'), 'ovsdb', 'ovsdb-server') - _OVS_VAR_DIR = settings.getValue('OVS_VAR_DIR') _OVS_ETC_DIR = settings.getValue('OVS_ETC_DIR') @@ -45,6 +38,7 @@ class VSwitchd(tasks.Process): _ovsdb_pid = None _logfile = _LOG_FILE_VSWITCHD _ovsdb_pidfile_path = os.path.join(settings.getValue('LOG_DIR'), "ovsdb_pidfile.pid") + _vswitchd_pidfile_path = os.path.join(settings.getValue('LOG_DIR'), "vswitchd_pidfile.pid") _proc_name = 'ovs-vswitchd' def __init__(self, timeout=30, vswitchd_args=None, expected_cmd=None): @@ -60,7 +54,12 @@ class VSwitchd(tasks.Process): self._timeout = timeout self._expect = expected_cmd vswitchd_args = vswitchd_args or [] - self._cmd = ['sudo', '-E', _OVS_VSWITCHD_BIN] + vswitchd_args + ovs_vswitchd_bin = os.path.join( + settings.getValue('OVS_DIR'), 'vswitchd', 'ovs-vswitchd') + sep = ['--'] if '--dpdk' in vswitchd_args else [] + self._cmd = ['sudo', '-E', ovs_vswitchd_bin] + vswitchd_args + sep + \ + ['--pidfile=' + self._vswitchd_pidfile_path, '--overwrite-pidfile', + '--log-file=' + self._logfile] # startup/shutdown @@ -82,15 +81,19 @@ class VSwitchd(tasks.Process): self._kill_ovsdb() raise exc - def kill(self, signal='-15', sleep=2): + def kill(self, signal='-15', sleep=10): """Kill ``ovs-vswitchd`` instance if it is alive. :returns: None """ self._logger.info('Killing ovs-vswitchd...') + with open(self._vswitchd_pidfile_path, "r") as pidfile: + vswitchd_pid = pidfile.read().strip() + tasks.terminate_task(vswitchd_pid, logger=self._logger) - self._kill_ovsdb() + self._kill_ovsdb() # ovsdb must be killed after vswitchd + # just for case, that sudo envelope has not terminated super(VSwitchd, self).kill(signal, sleep) # helper functions @@ -118,15 +121,20 @@ class VSwitchd(tasks.Process): :returns: None """ - tasks.run_task(['sudo', _OVSDB_TOOL_BIN, 'create', + ovsdb_tool_bin = os.path.join( + settings.getValue('OVS_DIR'), 'ovsdb', 'ovsdb-tool') + tasks.run_task(['sudo', ovsdb_tool_bin, 'create', os.path.join(_OVS_ETC_DIR, 'conf.db'), os.path.join(settings.getValue('OVS_DIR'), 'vswitchd', 'vswitch.ovsschema')], self._logger, 'Creating ovsdb configuration database...') + ovsdb_server_bin = os.path.join( + settings.getValue('OVS_DIR'), 'ovsdb', 'ovsdb-server') + tasks.run_background_task( - ['sudo', _OVSDB_SERVER_BIN, + ['sudo', ovsdb_server_bin, '--remote=punix:%s' % os.path.join(_OVS_VAR_DIR, 'db.sock'), '--remote=db:Open_vSwitch,Open_vSwitch,manager_options', '--pidfile=' + self._ovsdb_pidfile_path, '--overwrite-pidfile'], @@ -144,8 +152,7 @@ class VSwitchd(tasks.Process): self._logger.info("Killing ovsdb with pid: " + ovsdb_pid) if ovsdb_pid: - tasks.run_task(['sudo', 'kill', '-15', str(ovsdb_pid)], - self._logger, 'Killing ovsdb-server...') + tasks.terminate_task(ovsdb_pid, logger=self._logger) @staticmethod def get_db_sock_path(): |