Skip to content

Commit

Permalink
config: add webssh service
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Mar 7, 2024
1 parent a63ce3c commit 021339e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
14 changes: 14 additions & 0 deletions imageroot/actions/configure-module/20configure
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ response = agent.tasks.run(
)
agent.assert_exp(response['exit_code'] == 0)

response = agent.tasks.run(
agent_id=agent.resolve_agent_id('traefik@node'),
action='set-route',
data={
'instance': os.environ['MODULE_ID'] + '_webssh',
'url': f'http://127.0.0.1:{ports[9]}',
'http2https': True,
'lets_encrypt': request["lets_encrypt"],
'host': request["host"],
'path': '/webssh'
},
)
agent.assert_exp(response['exit_code'] == 0)


# Replace password if passed as parameter, otherwise read the old one
if 'api_password' in request and request['api_password'] != '':
Expand Down
2 changes: 2 additions & 0 deletions imageroot/actions/create-module/20initialize
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ promtail_port=$(($start+4))
# port 6 and 7 are reserved for loki
# port 8 is reserved for prometheus
# port 9 is reserved for grafana
webssh_port=$(($start+9))

num=$(echo $MODULE_ID | sed 's/nethsecurity\-controller//')

Expand All @@ -33,6 +34,7 @@ UI_PORT=$ui_port
UI_BIND_IP=127.0.0.1
PROXY_PORT=$proxy_port
PROXY_BIND_UI=127.0.0.1
WEBSSH_PORT=$webssh_port
EOF

cat << EOF > secret.env
Expand Down
4 changes: 2 additions & 2 deletions imageroot/actions/destroy-module/20destroy
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ if default_traefik_id is None:
sys.exit(2)

# Remove traefik routes
for instance in [os.environ['MODULE_ID'], os.environ['MODULE_ID'] + '_grafana', os.environ['MODULE_ID'] + '_loki', os.environ['MODULE_ID'] + '_prometheus']:
for instance in ['', '_grafana', '_loki', '_prometheus', '_webssh']:
response = agent.tasks.run(
agent_id=default_traefik_id,
action='delete-route',
data={
'instance': instance
'instance': os.environ['MODULE_ID'] + instance
},
)
agent.assert_exp(response['exit_code'] == 0)
4 changes: 2 additions & 2 deletions imageroot/systemd/user/controller.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Podman controller.service
Requires=vpn.service api.service ui.service proxy.service promtail.service metrics-exporter.path loki.service prometheus.service grafana.service
Before=vpn.service api.service ui.service proxy.service promtail.service metrics-exporter.path loki.service prometheus.service grafana.service
Requires=vpn.service api.service ui.service proxy.service promtail.service metrics-exporter.path loki.service prometheus.service grafana.service webssh.service
Before=vpn.service api.service ui.service proxy.service promtail.service metrics-exporter.path loki.service prometheus.service grafana.service webssh.service
ConditionPathExists=%S/state/environment
ConditionPathExists=%S/state/network.env

Expand Down
28 changes: 28 additions & 0 deletions imageroot/systemd/user/webssh.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

[Unit]
Description=Podman webssh.service
BindsTo=controller.service
After=vpm.service

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
EnvironmentFile=%S/state/environment
EnvironmentFile=%S/state/network.env
Restart=always
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/.pid %t/webssh.ctr-id
ExecStart=/usr/bin/podman run \
--conmon-pidfile %t/webssh.pid \
--cidfile %t/webssh.ctr-id \
--cgroups=no-conmon \
--pod-id-file %t/controller.pod-id \
--replace -d --name webssh \
--network=host \
${WEBSSH_IMAGE} --address='127.0.0.1' --port=${WEBSSH_PORT}
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/webssh.ctr-id -t 10
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/webssh.ctr-id
PIDFile=%t/webssh.pid
Type=forking

[Install]
WantedBy=default.target

0 comments on commit 021339e

Please sign in to comment.