Adding reload function and more tweaks for backends
All checks were successful
HAProxy Manager Build and Push / Build-and-Push (push) Successful in 48s
All checks were successful
HAProxy Manager Build and Push / Build-and-Push (push) Successful in 48s
This commit is contained in:
parent
7e53ba00d8
commit
64c707317f
@ -150,6 +150,31 @@ def regenerate_conf():
|
||||
'status': 'failed',
|
||||
'error': str(e)
|
||||
}), 500
|
||||
|
||||
@app.route('api/reload', methods=['POST'])
|
||||
def reload_haproxy():
|
||||
if is_process_running('haproxy'):
|
||||
subprocess.run(['echo', '"reload"', '|', 'socat', 'stdio', '/tmp/haproxy-cli'])
|
||||
else:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
['haproxy', '-W', '-S', '/tmp/haproxy-cli,level,admin', '-f', HAPROXY_CONFIG_PATH],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
if result.returncode == 0:
|
||||
print("HAProxy started successfully")
|
||||
return jsonify({'status': 'success'}), 200
|
||||
else:
|
||||
print(f"HAProxy start command returned: {result.stdout}")
|
||||
print(f"Error output: {result.stderr}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Failed to start HAProxy: {e.stdout}\n{e.stderr}")
|
||||
return jsonify({
|
||||
'status': 'failed',
|
||||
'error': f"Failed to start HAProxy: {e.stdout}\n{e.stderr}"
|
||||
}), 500
|
||||
|
||||
@app.route('/api/domain', methods=['POST'])
|
||||
def add_domain():
|
||||
|
@ -1,7 +1,6 @@
|
||||
|
||||
backend {{ name }}-backend
|
||||
option forwardfor
|
||||
option httpchk
|
||||
http-request add-header X-CLIENT-IP %[src]
|
||||
{% if ssl_enabled %}http-request set-header X-Forwarded-Proto https if { ssl_fc }{% endif %}
|
||||
{% for server in servers %}server {{ server.server_name }} {{ server.server_address }}:{{ server.server_port }} {{ server.server_options }}{% endfor %}
|
||||
|
8
templates/hap_backend_http_check.tpl
Normal file
8
templates/hap_backend_http_check.tpl
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
backend {{ name }}-backend
|
||||
option forwardfor
|
||||
option httpchk
|
||||
http-request add-header X-CLIENT-IP %[src]
|
||||
{% if ssl_enabled %}http-request set-header X-Forwarded-Proto https if { ssl_fc }{% endif %}
|
||||
{% for server in servers %}server {{ server.server_name }} {{ server.server_address }}:{{ server.server_port }} {{ server.server_options }}{% endfor %}
|
||||
|
@ -105,6 +105,7 @@
|
||||
<div class="container">
|
||||
<h1>HAProxy Domain Manager</h1>
|
||||
<button onclick="regenerateConfig()" class="regenerate-btn">Regenerate HAProxy Config</button>
|
||||
<button onclick="reloadHAProxy()" class="regenerate-btn" style="background-color: #2196F3;">Reload HAProxy</button>
|
||||
<form id="domainForm">
|
||||
<div class="form-group">
|
||||
<label for="domain">Domain:</label>
|
||||
@ -237,6 +238,27 @@
|
||||
}
|
||||
});
|
||||
|
||||
async function reloadHAProxy() {
|
||||
try {
|
||||
const response = await fetch('/api/reload', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
showStatus('HAProxy reloaded successfully', 'success');
|
||||
} else {
|
||||
const data = await response.json();
|
||||
showStatus('Failed to reload HAProxy: ' + (data.message || 'Unknown error'), 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
showStatus('Error: ' + error.message, 'error');
|
||||
console.error('Error reloading HAProxy:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async function requestSSL(domain) {
|
||||
try {
|
||||
const response = await fetch('/api/ssl', {
|
||||
|
Loading…
x
Reference in New Issue
Block a user