Add Linux development station role with systemd services for code-server and OpenCode
- Implemented handlers for restarting code-server and OpenCode services. - Created main tasks for setting up a Linux development station, including user management, package installation, and configuration. - Added validation for OpenCode server credentials and code-server password. - Introduced tool package management for npm, uv, and go installers. - Developed templates for systemd service units for code-server and OpenCode. - Included scripts for starting code-server and OpenCode with SSH agent support. - Updated inventory and Terraform configuration to include new development host.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
[Unit]
|
||||
Description=code-server - VS Code on remote Linux
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ linux_dev_station_service_user }}
|
||||
Group={{ linux_dev_station_service_user }}
|
||||
WorkingDirectory={{ linux_dev_station_workspace_dir }}
|
||||
ExecStart=/bin/bash {{ linux_dev_station_scripts_dir }}/start-ide.sh
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=append:{{ linux_dev_station_logs_dir }}/code-server.log
|
||||
StandardError=append:{{ linux_dev_station_logs_dir }}/code-server.err.log
|
||||
|
||||
Environment="HOME={{ linux_dev_station_service_home }}"
|
||||
Environment="PATH={{ linux_dev_station_path }}"
|
||||
Environment="PASSWORD={{ linux_dev_station_code_server_password }}"
|
||||
{% if linux_dev_station_ssh_agent_enabled | bool %}
|
||||
Environment="SSH_AUTH_SOCK={{ linux_dev_station_ssh_agent_socket }}"
|
||||
{% endif %}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1 @@
|
||||
{{ linux_dev_station_opencode_config | to_nice_json }}
|
||||
@@ -0,0 +1,28 @@
|
||||
[Unit]
|
||||
Description=OpenCode - AI-powered terminal IDE
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ linux_dev_station_service_user }}
|
||||
Group={{ linux_dev_station_service_user }}
|
||||
WorkingDirectory={{ linux_dev_station_workspace_dir }}
|
||||
ExecStart=/bin/bash {{ linux_dev_station_scripts_dir }}/start-opencode.sh
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=append:{{ linux_dev_station_logs_dir }}/opencode.log
|
||||
StandardError=append:{{ linux_dev_station_logs_dir }}/opencode.err.log
|
||||
|
||||
Environment="HOME={{ linux_dev_station_service_home }}"
|
||||
Environment="PATH={{ linux_dev_station_path }}"
|
||||
Environment="OPENCODE_SERVER_USERNAME={{ linux_dev_station_opencode_server_username }}"
|
||||
Environment="OPENCODE_SERVER_PASSWORD={{ linux_dev_station_opencode_server_password }}"
|
||||
{% for env_key, env_value in linux_dev_station_opencode_extra_environment.items() %}
|
||||
Environment="{{ env_key }}={{ env_value }}"
|
||||
{% endfor %}
|
||||
{% if linux_dev_station_ssh_agent_enabled | bool %}
|
||||
Environment="SSH_AUTH_SOCK={{ linux_dev_station_ssh_agent_socket }}"
|
||||
{% endif %}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# SSH agent starter — idempotent, safe to source from concurrent sessions.
|
||||
# Starts ssh-agent if not already running, then adds keys.
|
||||
|
||||
export SSH_AUTH_SOCK="{{ linux_dev_station_ssh_agent_socket }}"
|
||||
|
||||
# Start ssh-agent if socket doesn't exist
|
||||
if [ ! -S "$SSH_AUTH_SOCK" ]; then
|
||||
eval "$(/usr/bin/ssh-agent -a "{{ linux_dev_station_ssh_agent_socket }}" -s)" > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
# Wait for the agent socket to appear
|
||||
__wait=0
|
||||
while [ ! -S "$SSH_AUTH_SOCK" ] && [ "$__wait" -lt 15 ]; do
|
||||
sleep 1
|
||||
__wait=$(( __wait + 1 ))
|
||||
done
|
||||
|
||||
# Add keys if the agent is running but has none loaded
|
||||
if [ -S "$SSH_AUTH_SOCK" ]; then
|
||||
if ssh-add -l 2>/dev/null | grep -q "The agent has no identities"; then
|
||||
for _key in {{ linux_dev_station_ssh_agent_keys | map('quote') | join(' ') }}; do
|
||||
if [ -f "$_key" ]; then
|
||||
if [ -n "{{ linux_dev_station_ssh_agent_passphrase }}" ]; then
|
||||
printf '%s\n' "{{ linux_dev_station_ssh_agent_passphrase }}" | ssh-add "$_key" 2>/dev/null || true
|
||||
else
|
||||
ssh-add "$_key" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=SSH Agent for devstation
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User={{ linux_dev_station_service_user }}
|
||||
Group={{ linux_dev_station_service_user }}
|
||||
ExecStart=/usr/bin/ssh-agent -a {{ linux_dev_station_ssh_agent_socket }}
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
StandardOutput=append:{{ linux_dev_station_logs_dir }}/ssh-agent.log
|
||||
StandardError=append:{{ linux_dev_station_logs_dir }}/ssh-agent.err.log
|
||||
|
||||
Environment="HOME={{ linux_dev_station_service_home }}"
|
||||
Environment="PATH={{ linux_dev_station_path }}"
|
||||
Environment="SSH_AUTH_SOCK={{ linux_dev_station_ssh_agent_socket }}"
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
{% if linux_dev_station_ssh_agent_enabled | bool %}
|
||||
source "{{ linux_dev_station_scripts_dir }}/ssh-agent-start.sh"
|
||||
{% endif %}
|
||||
|
||||
cd {{ linux_dev_station_workspace_dir }}
|
||||
|
||||
exec code-server \
|
||||
--bind-addr {{ linux_dev_station_code_server_host }}:{{ linux_dev_station_code_server_port }} \
|
||||
--auth {{ linux_dev_station_code_server_auth }} \
|
||||
--disable-telemetry \
|
||||
{{ linux_dev_station_code_server_workspace }}
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
{% if linux_dev_station_ssh_agent_enabled | bool %}
|
||||
source "{{ linux_dev_station_scripts_dir }}/ssh-agent-start.sh"
|
||||
{% endif %}
|
||||
|
||||
cd {{ linux_dev_station_workspace_dir }}
|
||||
|
||||
exec {{ linux_dev_station_opencode_command }}
|
||||
Reference in New Issue
Block a user