Skip to content

Commit 12e15ed

Browse files
authored
Merge pull request #86 from NethServer/fixPort_reload
Reload PHP-FPM services after configuration changes and update NextFpmPort script NethServer/dev#7200
2 parents 685197e + dedd219 commit 12e15ed

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

imageroot/actions/create-vhost/30SystemdServices

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ if PhpVersion:
3939
subprocess.run(["download-php-fpm",str(PhpVersion)])
4040
# start the container if stopped
4141
subprocess.run(["systemctl", "--user", "enable", "--now", "phpfpm@"+str(PhpVersion)+".service"])
42+
# we need to reload the php fpm service to let him know about the new configuration
43+
subprocess.run(["systemctl", "--user", "reload", "phpfpm@"+str(PhpVersion)+".service"])
4244
else:
4345
subprocess.run(["systemctl", "--user", "reload", "nginx.service"])
4446

imageroot/actions/update-vhost/30SystemdServices

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ if PhpVersion:
5151
subprocess.run(["download-php-fpm",str(PhpVersion)])
5252
# start the container if stopped
5353
subprocess.run(["systemctl", "--user", "enable", "--now", "phpfpm@"+str(PhpVersion)+".service"])
54+
# php version might have changed, reload all php-fpm services
5455
subprocess.run(["systemctl", "--user", "reload", "phpfpm@*.service"])
5556
else:
5657
subprocess.run(["systemctl", "--user", "reload", "nginx.service"])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Copyright (C) 2024 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
8+
# first release where buildt with a static file NextFpmPort set to 9000
9+
# during upgrade the value of virtualhost ID was overwritten with the default value 9000
10+
# this script will attempt to discover how many configurations we have
11+
# and set the NextFpmPort file accordingly
12+
# Added with the release 1.0.20
13+
# Todo: NextFpmPort should be named LastFpmPort (when the vhost is created, the last ID is written there)
14+
15+
# actions:
16+
# find all existing ID of vhosts
17+
# keep the max value or default to 10 000 if no vhosts are found or exception (probably a module never used, but be prudent)
18+
# read the NextFpmPort file
19+
# if current_id is None or last_id > current_id write the last_id to the file
20+
21+
22+
import os
23+
import sys
24+
25+
# Define the directory and the target file
26+
directory = "databases/vhosts/"
27+
output_file = "databases/NextFpmPort"
28+
29+
# no NextFpmPort, no need to continue
30+
if not os.path.exists(output_file):
31+
sys.exit(0)
32+
33+
# Find all .ini files
34+
ini_files = [f for f in os.listdir(directory) if f.endswith('.ini')]
35+
36+
# Extract IDs from filenames
37+
ids = []
38+
try:
39+
for file in ini_files:
40+
# Remove the .ini suffix and convert the remaining part to an integer
41+
id_str = file.removesuffix(".ini")
42+
ids.append(int(id_str))
43+
44+
# Determine the last ID
45+
if ids:
46+
last_id = max(ids)
47+
else:
48+
last_id = 0 # Default to 0 if no IDs exist, no vhosts
49+
except:
50+
last_id = 10000 # Default to 10 000 if ecxeption, few chances to get 1000 active vhosts
51+
52+
# Read the current value from the NextFpmPort file if it exists
53+
current_id = None
54+
with open(output_file, "r") as f:
55+
try:
56+
current_id = int(f.read().strip())
57+
except ValueError:
58+
current_id = None
59+
60+
# Write the last ID only if it's greater than the current value
61+
if current_id is None or last_id > current_id:
62+
with open(output_file, "w") as f:
63+
f.write(str(last_id))
64+
print(f"{os.environ['MODULE_ID']}: Last virtualhost ID {last_id} written to {output_file}", file=sys.stderr)
65+
else:
66+
print(f"{os.environ['MODULE_ID']}: Last virtualhost ID {last_id} not written, the current ID {current_id} in {output_file} is correct", file=sys.stderr)

0 commit comments

Comments
 (0)