Skip to content

Commit

Permalink
fix: use integrated agent function for tcp_port_in_use
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Sep 3, 2024
1 parent 4483075 commit eee3d69
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions imageroot/actions/restore-module/60systemd
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,18 @@
#
import os
import sys
import subprocess
import glob
import re
import agent
import socket


def is_port_in_use(port):
# Check if the port is in use for IPv4
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
try:
sock.bind(('', port))
except socket.error:
return True # Port is in use for IPv4

# Check if the port is in use for IPv6
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
try:
sock.bind(('', port))
except socket.error:
return True # Port is in use for IPv6

return False # Port is not in use for both IPv4 and IPv6

# we test if the sftp port is not in use with the previous module
port = int(os.environ['SFTP_TCP_PORT'])
if not is_port_in_use(port):
if not agent.tcp_port_in_use(port):
# expand configuration
agent.run_helper("systemctl", "--user", "enable","--now", "nginx.service").check_returncode()
agent.run_helper("systemctl", "--user", "enable", "nginx.service").check_returncode()
agent.run_helper("systemctl", "--user", "restart", "nginx.service").check_returncode()
agent.run_helper("systemctl", "--user", "enable","--now", "sftpgo.service").check_returncode()
agent.run_helper("systemctl", "--user", "enable", "sftpgo.service").check_returncode()
agent.run_helper("systemctl", "--user", "restart", "sftpgo.service").check_returncode()
# detect if a service has configurations, hence start it
PhpServiceArray = glob.glob('php*-fpm-custom.d')
Expand Down

0 comments on commit eee3d69

Please sign in to comment.