From 4ad717c3411da216245b3ba2e78e69de669bf79b Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Fri, 14 Jun 2024 18:48:39 -0500 Subject: [PATCH] initial commit --- .gitignore | 2 ++ create_symlinks.py | 37 +++++++++++++++++++++++++++++++++++++ example.socket | 9 +++++++++ example@.service | 6 ++++++ 4 files changed, 54 insertions(+) create mode 100644 .gitignore create mode 100755 create_symlinks.py create mode 100644 example.socket create mode 100644 example@.service diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6fd0fed --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.python-version +__pycache__ \ No newline at end of file diff --git a/create_symlinks.py b/create_symlinks.py new file mode 100755 index 0000000..9937ce4 --- /dev/null +++ b/create_symlinks.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +from pathlib import Path + +from rich import print + + +def create_symlink(source, target): + try: + target_path = Path(target) + + # Check if the target already exists and remove it if it does + if target_path.exists() or target_path.is_symlink(): + target_path.unlink() + + # Create the symbolic link + target_path.symlink_to(source) + print(f'Created symlink: {source} -> {target}') + except OSError as e: + print(f'Error creating symlink: {e}') + + +def main(): + repo_dir = Path(__file__).resolve() + systemd_dir = Path('/etc/systemd/system') + + # Define the source and target paths + socket_file = 'example.socket' + service_file = 'example@.service' + + # Create symlinks + create_symlink(repo_dir / socket_file, systemd_dir / socket_file) + create_symlink(repo_dir / service_file, systemd_dir / service_file) + + +if __name__ == '__main__': + main() diff --git a/example.socket b/example.socket new file mode 100644 index 0000000..0cb9fe1 --- /dev/null +++ b/example.socket @@ -0,0 +1,9 @@ +[Unit] +Description=Example Unix Socket + +[Socket] +ListenStream=/run/example.sock +Accept=yes + +[Install] +WantedBy=sockets.target \ No newline at end of file diff --git a/example@.service b/example@.service new file mode 100644 index 0000000..4cc75c6 --- /dev/null +++ b/example@.service @@ -0,0 +1,6 @@ +[Unit] +Description=Example Service + +[Service] +ExecStart=/bin/bash -c 'echo "Hello, world!" > /tmp/example_output.txt' +StandardInput=socket