generated from NethServer/ns8-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from NethServer/fixPort_reload
Reload PHP-FPM services after configuration changes and update NextFpmPort script NethServer/dev#7200
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
# first release where buildt with a static file NextFpmPort set to 9000 | ||
# during upgrade the value of virtualhost ID was overwritten with the default value 9000 | ||
# this script will attempt to discover how many configurations we have | ||
# and set the NextFpmPort file accordingly | ||
# Added with the release 1.0.20 | ||
# Todo: NextFpmPort should be named LastFpmPort (when the vhost is created, the last ID is written there) | ||
|
||
# actions: | ||
# find all existing ID of vhosts | ||
# keep the max value or default to 10 000 if no vhosts are found or exception (probably a module never used, but be prudent) | ||
# read the NextFpmPort file | ||
# if current_id is None or last_id > current_id write the last_id to the file | ||
|
||
|
||
import os | ||
import sys | ||
|
||
# Define the directory and the target file | ||
directory = "databases/vhosts/" | ||
output_file = "databases/NextFpmPort" | ||
|
||
# no NextFpmPort, no need to continue | ||
if not os.path.exists(output_file): | ||
sys.exit(0) | ||
|
||
# Find all .ini files | ||
ini_files = [f for f in os.listdir(directory) if f.endswith('.ini')] | ||
|
||
# Extract IDs from filenames | ||
ids = [] | ||
try: | ||
for file in ini_files: | ||
# Remove the .ini suffix and convert the remaining part to an integer | ||
id_str = file.removesuffix(".ini") | ||
ids.append(int(id_str)) | ||
|
||
# Determine the last ID | ||
if ids: | ||
last_id = max(ids) | ||
else: | ||
last_id = 0 # Default to 0 if no IDs exist, no vhosts | ||
except: | ||
last_id = 10000 # Default to 10 000 if ecxeption, few chances to get 1000 active vhosts | ||
|
||
# Read the current value from the NextFpmPort file if it exists | ||
current_id = None | ||
with open(output_file, "r") as f: | ||
try: | ||
current_id = int(f.read().strip()) | ||
except ValueError: | ||
current_id = None | ||
|
||
# Write the last ID only if it's greater than the current value | ||
if current_id is None or last_id > current_id: | ||
with open(output_file, "w") as f: | ||
f.write(str(last_id)) | ||
print(f"{os.environ['MODULE_ID']}: Last virtualhost ID {last_id} written to {output_file}", file=sys.stderr) | ||
else: | ||
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) |