Skip to content

Commit

Permalink
fix(sftp): Add port on update (#385)
Browse files Browse the repository at this point in the history
* fix(sftp): fix unit syntax

* Allocate sftp port on updates

NethServer/dev#7140
  • Loading branch information
Stell0 authored Feb 18, 2025
1 parent 1e4740b commit aebf106
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion imageroot/systemd/user/sftp.service
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ExecStart=/usr/bin/podman run --conmon-pidfile %t/sftp.pid \
--cidfile %t/sftp.ctr-id --cgroups=no-conmon \
--replace \
--detach \
--name=%N
--name=%N \
--volume=moh:/var/sftp/moh:z \
--volume=sftp_ssh_config:/etc/ssh:Z \
--env=ASTERISK_RECORDING_SFTP_PORT \
Expand Down
30 changes: 30 additions & 0 deletions imageroot/update-module.d/20allocate_ports
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3

#
# Copyright (C) 2025 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

# Allocate new port for sftp service
import sys
import agent

if not hasattr(agent, 'allocate_ports'):
print(f"Core version too old, not allocating sftp port. Try on next update", file=sys.stderr)
sys.exit(0)

# Read the env file, do not use real environment because it could be not updated
env = agent.read_envfile('environment')

# Check:
# skip allocation if the module has already allocated an extra port during an old update
if 'ASTERISK_RECORDING_SFTP_PORT' in env:
sys.exit(0)

# Allocate a new port
allocated_ports = agent.allocate_ports(1, "tcp", keep_existing=True)
sftp_port = allocated_ports[0]
print(f"New port allocated for SFTP: {sftp_port}", file=sys.stderr)

# Update the environment file: this will be used as flag to avoid re-allocating the port
agent.set_env('ASTERISK_RECORDING_SFTP_PORT', sftp_port)

0 comments on commit aebf106

Please sign in to comment.