Skip to content

Commit 6232e3a

Browse files
committed
fix(smarthost): simplify environment file handling and remove PHP argument requirement
1 parent a16d9dc commit 6232e3a

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

imageroot/bin/discover-smarthost

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,24 @@
55
# SPDX-License-Identifier: GPL-3.0-or-later
66
#
77

8-
import sys
98
import agent
109
import os
1110

12-
# retrieve the first argument as the php value
13-
if len(sys.argv) <= 1:
14-
print("Error: Missing argument for PHP value", file=sys.stderr)
15-
sys.exit(1)
16-
php_value = sys.argv[1]
17-
1811
# Connect the local Redis replica. This is necessary to consistently start
1912
# the service if the leader node is not reachable:
2013
rdb = agent.redis_connect(use_replica=True)
2114
smtp_settings = agent.get_smarthost_settings(rdb)
2215

2316
# create the smarthost folder
24-
envfile = f'smarthosts/php{php_value}_smarthost.env'
17+
envfile = 'smarthosts/smarthost.env'
2518

2619
# Ensure the target directory exists:
2720
os.makedirs(os.path.dirname(envfile), exist_ok=True)
2821

22+
# Create a unique temporary file using process PID to avoid concurrent writes:
23+
tmp_path = f"{envfile}.tmp.{os.getpid()}"
2924

30-
# Using .tmp suffix: do not overwrite the target file until the new one is
31-
# saved to disk:
32-
with open(envfile + ".tmp", "w") as efp:
25+
with open(tmp_path, "w") as efp:
3326
# HINT for lamp: adjust variable names as needed
3427
print(f"SMTP_ENABLED={'1' if smtp_settings['enabled'] else ''}", file=efp)
3528
print(f"SMTP_HOST={smtp_settings['host']}", file=efp)
@@ -39,5 +32,5 @@ with open(envfile + ".tmp", "w") as efp:
3932
print(f"SMTP_ENCRYPTION={smtp_settings['encrypt_smtp']}", file=efp)
4033
print(f"SMTP_TLSVERIFY={'1' if smtp_settings['tls_verify'] else ''}", file=efp)
4134

42-
# Commit changes by replacing the existing envfile:
43-
os.replace(envfile + ".tmp", envfile)
35+
# Commit changes by atomically replacing the existing envfile:
36+
os.replace(tmp_path, envfile)

imageroot/systemd/user/phpfpm@.service

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Environment=PODMAN_SYSTEMD_UNIT=%n
99
EnvironmentFile=%S/state/environment
1010
EnvironmentFile=%S/state/image_url_tag.env
1111
WorkingDirectory=%S/state
12-
EnvironmentFile=-%S/state/smarthosts/php%i_smarthost.env
12+
EnvironmentFile=-%S/state/smarthosts/smarthost.env
1313
Restart=always
1414
TimeoutStopSec=70
1515
ExecStartPre=/bin/rm -f %t/php%i-fpm.pid %t/php%i-fpm.ctr-id
1616
ExecStartPre=/usr/bin/mkdir -p %S/state/php%i-fpm-custom.d
17-
ExecStartPre=-runagent discover-smarthost %i
17+
ExecStartPre=-runagent discover-smarthost
1818
ExecStart=/usr/bin/podman run --conmon-pidfile %t/php%i-fpm.pid \
1919
--cidfile %t/php%i-fpm.ctr-id --cgroups=no-conmon \
2020
--pod-id-file %t/webserver.pod-id --replace -d --name php%i-fpm \

0 commit comments

Comments
 (0)