Skip to content

Commit

Permalink
Add support for running ksushy in user space (#691)
Browse files Browse the repository at this point in the history
Signed-off-by: Sagi Shnaidman <[email protected]>
  • Loading branch information
sshnaidm authored and karmab committed Jun 25, 2024
1 parent 5dbe3ad commit f360b39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions kvirt/baseconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,21 +1511,31 @@ def import_in_kube(self, network='default', dest=None, secure=False):
return {'result': 'success'}

def deploy_ksushy_service(self, port=9000, ssl=False, ipv6=False, user=None, password=None, bootonce=False):
update = os.path.exists("/usr/lib/systemd/system/ksushy.service")
home = os.environ.get('HOME', '/root')
if ssl:
warning("ssl support requires installing manually pyopenssl and cherrypy")
root = os.getuid() == 0
if root:
service_file = "/usr/lib/systemd/system/ksushy.service"
else:
service_file = f"{os.environ.get('HOME')}/.config/systemd/user/ksushy.service"
if not os.path.exists(os.path.dirname(service_file)):
os.makedirs(os.path.dirname(service_file))
update = os.path.exists(service_file)
home = os.environ.get('HOME', '/root')
executable = which('ksushy')
port = f"Environment=KSUSHY_PORT={port}\n" if port != 9000 else ''
ssl = "Environment=KSUSHY_SSL=true\n" if ssl else ''
ipv6 = "Environment=KSUSHY_IPV6=true\n" if ipv6 else ''
user = f"Environment=KSUSHY_USER={user}\n" if user is not None else ''
password = f"Environment=KSUSHY_PASSWORD={password}\n" if password is not None else ''
bootonce = "Environment=KSUSHY_BOOTONCE=true\n" if bootonce else ''
sushydata = kdefaults.KSUSHYSERVICE.format(home=home, port=port, ipv6=ipv6, ssl=ssl, user=user,
password=password, bootonce=bootonce)
with open("/usr/lib/systemd/system/ksushy.service", "w") as f:
password=password, bootonce=bootonce, executable=executable)
with open(service_file, "w") as f:
f.write(sushydata)
cmd = "systemctl restart ksushy" if update else "systemctl enable --now ksushy"
user_space = "--user" if not root else ""
cmd = f"systemctl {user_space} restart ksushy" if update else f"systemctl {user_space} enable --now ksushy"
call(cmd, shell=True)

def deploy_web_service(self, port=8000, ssl=False, ipv6=False):
Expand Down
2 changes: 1 addition & 1 deletion kvirt/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
After=syslog.target
[Service]
Type=simple
ExecStart=ksushy
ExecStart={executable}
StandardOutput=syslog
StandardError=syslog
Environment=HOME={home}
Expand Down

0 comments on commit f360b39

Please sign in to comment.