Skip to content

Commit

Permalink
Allocate sftp port on updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Stell0 committed Feb 18, 2025
1 parent 76310a5 commit 29f3b63
Showing 1 changed file with 30 additions and 0 deletions.
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 used as flag to avoid re-allocating the port
agent.set_env('ASTERISK_RECORDING_SFTP_PORT', sftp_port)

0 comments on commit 29f3b63

Please sign in to comment.