def _write_upstart(self, ssh, cmdline): serviceFilePath = "/etc/init/replicator.conf" upstartService = UPSTART_TEMPLATE % { "cmdline": cmdline, } utils.write_ssh_file( ssh, '/tmp/replicator.conf', upstartService) utils.exec_ssh_cmd( ssh, "sudo mv /tmp/replicator.conf %s" % serviceFilePath, get_pty=True).decode().rstrip( "\n") utils.exec_ssh_cmd(ssh, "start replicator")
def _write_systemd(self, ssh, cmdline): serviceFilePath = "/lib/systemd/system/replicator.service" def _reload_and_start(): utils.exec_ssh_cmd( ssh, "sudo systemctl daemon-reload", get_pty=True) utils.exec_ssh_cmd( ssh, "sudo systemctl start replicator", get_pty=True) systemdService = SYSTEMD_TEMPLATE % { "cmdline": cmdline, "username": REPLICATOR_USERNAME, } utils.write_ssh_file( ssh, '/tmp/replicator.service', systemdService) utils.exec_ssh_cmd( ssh, "sudo mv /tmp/replicator.service %s" % serviceFilePath, get_pty=True).decode().rstrip("\n") _reload_and_start()
def run_user_script(self, user_script): if len(user_script) == 0: return script_path = "/tmp/coriolis_user_script" try: utils.write_ssh_file(self._conn, script_path, user_script) except Exception as err: raise exception.CoriolisException( "Failed to copy user script to target system.") from err try: utils.exec_ssh_cmd(self._conn, "sudo chmod +x %s" % script_path, get_pty=True) utils.exec_ssh_cmd(self._conn, 'sudo "%s" "%s"' % (script_path, self._os_root_dir), get_pty=True) except Exception as err: raise exception.CoriolisException( "Failed to run user script.") from err
def _write_file(self, chroot_path, content): path = os.path.join(self._os_root_dir, chroot_path) utils.write_ssh_file(self._ssh, path, content)