Compare commits
2 Commits
1cae18670a
...
28108567b3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28108567b3 | ||
|
|
483e3f1d39 |
38
README.md
Normal file
38
README.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# AppDaemon VSCode Tunnel
|
||||
|
||||
## Install Service
|
||||
|
||||
Use the `install_service.py` script to install.
|
||||
|
||||
- Creates symlinks to `/etc/systemd/system`
|
||||
- `example.socket`
|
||||
- `example.service`
|
||||
- Reloads the service definitions
|
||||
- Starts the `example.socket`
|
||||
- Enables the `example.socket` to start at boot
|
||||
|
||||
> [!NOTE]
|
||||
> The `example.socket` does cause `example.service` to start when something connects to the socket at `/run/example.sock`.
|
||||
|
||||
> [!CAUTION]
|
||||
> `example.service` does not stop when disconnecting from `/run/example.sock`
|
||||
|
||||
## Other Commands
|
||||
|
||||
Reload systemd units
|
||||
|
||||
```shell
|
||||
sudo systemctl daemon-reload
|
||||
```
|
||||
|
||||
List loaded units
|
||||
|
||||
```shell
|
||||
systemctl list-units --type=service
|
||||
```
|
||||
|
||||
Check statuses
|
||||
|
||||
```shell
|
||||
systemctl status example.socket
|
||||
```
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
#!/usr/bin/env python
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
@@ -21,34 +21,32 @@ def create_symlink(source, target):
|
||||
print(f'Error creating symlink: [bold red]{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().parent
|
||||
systemd_dir = Path('/etc/systemd/system')
|
||||
|
||||
# Define the source and target paths
|
||||
socket_file = 'example.socket'
|
||||
service_file = 'example.service'
|
||||
name = 'example'
|
||||
socket_file = f'{name}.socket'
|
||||
service_file = f'{name}.service'
|
||||
|
||||
# Create symlinks
|
||||
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')
|
||||
try:
|
||||
cmd_kwargs = dict(check=True, text=True, capture_output=True)
|
||||
subprocess.run(['sudo', 'systemctl', 'daemon-reload'], **cmd_kwargs)
|
||||
print('Reloaded systemd services')
|
||||
|
||||
run_command('sudo systemctl start example.socket')
|
||||
print(f'Started [blue]{socket_file}[/]')
|
||||
subprocess.run(['sudo', 'systemctl', 'start', socket_file], **cmd_kwargs)
|
||||
print(f'Started [blue]{socket_file}[/]')
|
||||
|
||||
run_command('sudo systemctl enable example.socket')
|
||||
print(f'Enabled [blue]{socket_file}[/] to start at boot')
|
||||
subprocess.run(['sudo', 'systemctl', 'enable', socket_file], **cmd_kwargs)
|
||||
print(f'Enabled [blue]{socket_file}[/] to start at boot')
|
||||
except subprocess.CalledProcessError as e:
|
||||
print('Error:', e.stderr)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user