diff --git a/create_symlinks.py b/install_service.py similarity index 59% rename from create_symlinks.py rename to install_service.py index 9937ce4..fd94f7b 100755 --- a/create_symlinks.py +++ b/install_service.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +import subprocess from pathlib import Path from rich import print @@ -20,8 +21,15 @@ def create_symlink(source, target): print(f'Error creating symlink: {e}') +def run_command(command): + try: + subprocess.run(command, check=True, shell=True) + except subprocess.CalledProcessError as e: + print(f'Error running command: {command}\n{e}') + + def main(): - repo_dir = Path(__file__).resolve() + repo_dir = Path(__file__).resolve().parent systemd_dir = Path('/etc/systemd/system') # Define the source and target paths @@ -32,6 +40,16 @@ def main(): create_symlink(repo_dir / socket_file, systemd_dir / socket_file) create_symlink(repo_dir / service_file, systemd_dir / service_file) + # Reload systemd, start and enable the socket + run_command('sudo systemctl daemon-reload') + print('Reloaded systemd services') + + run_command('sudo systemctl start example.socket') + print(f'Started [blue]{socket_file}[/]') + + run_command('sudo systemctl enable example.socket') + print(f'Enabled [blue]{socket_file}[/] to start at boot') + if __name__ == '__main__': main()