~libertine-team/libertine/devel

« back to all changes in this revision

Viewing changes to python/libertine/LxcContainer.py

libertine-launch: refactored core components of application session management.

Approved by Christopher Townsend, Stephen M. Webb, Larry Price, Libertine CI Bot, Brandon Schaefer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
        self.container = lxc_container(container_id)
140
140
        self._set_lxc_log()
141
141
        self.lxc_manager_interface = None
 
142
        self.window_manager = None
142
143
 
143
144
        utils.set_session_dbus_env_var()
144
145
 
309
310
        # Dump it all to disk
310
311
        self.container.save_config()
311
312
 
312
 
    def launch_application(self, app_exec_line):
 
313
    def start_application(self, app_exec_line, environ):
313
314
        if self.lxc_manager_interface == None:
314
315
            print("No interface to libertine-lxc-manager.  Failing application launch.")
315
316
            return
316
317
 
 
318
        os.environ.clear()
 
319
        os.environ.update(environ)
 
320
 
317
321
        (result, error) = self.lxc_manager_interface.app_start(self.container_id, self.lxc_log_file)
318
322
 
319
323
        if not result:
321
325
            print("%s" % error)
322
326
            return
323
327
 
324
 
        window_manager = self.container.attach(lxc.attach_run_command,
325
 
                                               utils.setup_window_manager(self.container_id))
 
328
        self.window_manager = self.container.attach(lxc.attach_run_command,
 
329
                                                    utils.setup_window_manager(self.container_id))
326
330
 
327
331
        # Setup pulse to work inside the container
328
332
        os.environ['PULSE_SERVER'] = utils.get_libertine_lxc_pulse_socket_path()
329
333
 
330
334
        app_launch_cmd = "sudo -E -u " + os.environ['USER'] + " env PATH=" + os.environ['PATH']
331
335
        cmd = shlex.split(app_launch_cmd)
332
 
        self.container.attach_wait(lxc.attach_run_command,
333
 
                                   cmd + app_exec_line)
334
 
 
335
 
        utils.terminate_window_manager(psutil.Process(window_manager))
 
336
        app = self.container.attach(lxc.attach_run_command,
 
337
                                    cmd + app_exec_line)
 
338
        return psutil.Process(app)
 
339
 
 
340
    def finish_application(self, app):
 
341
        os.waitpid(app.pid, 0)
 
342
 
 
343
        utils.terminate_window_manager(psutil.Process(self.window_manager))
336
344
 
337
345
        # Tell libertine-lxc-manager that the app has stopped.
338
346
        self.lxc_manager_interface.app_stop(self.container_id)