Skip to content

Commit b023867

Browse files
committed
feat(status-page): add support for reloading config / restarting workers / clearing logs on the status page
- Simplified the config_reload function by removing the old workers count parameter, focusing on bind address changes. - Introduced new API endpoints for clearing logs, reloading configuration, and restarting workers, enhancing service control capabilities. - Updated the web UI to include a service control section for managing logs and configuration dynamically. - Improved signal handling in the supervisor for better worker management during configuration reloads.
1 parent 7706325 commit b023867

File tree

15 files changed

+972
-589
lines changed

15 files changed

+972
-589
lines changed

src/configuration.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ void set_config_file_path(const char *path) {
743743
* Respects cmd_*_set flags - resources set by command line are NOT freed.
744744
* Does NOT reset cmd_*_set flags (they track command line args).
745745
*/
746-
void config_free(void) {
746+
void config_free(bool force_free) {
747747
/* Free all services */
748748
service_free_all();
749749

@@ -754,27 +754,27 @@ void config_free(void) {
754754
m3u_reset_external_playlist();
755755

756756
/* Free string config values */
757-
if (!cmd_hostname_set)
757+
if (!cmd_hostname_set || force_free)
758758
safe_free_string(&config.hostname);
759-
if (!cmd_r2h_token_set)
759+
if (!cmd_r2h_token_set || force_free)
760760
safe_free_string(&config.r2h_token);
761-
if (!cmd_ffmpeg_path_set)
761+
if (!cmd_ffmpeg_path_set || force_free)
762762
safe_free_string(&config.ffmpeg_path);
763-
if (!cmd_ffmpeg_args_set)
763+
if (!cmd_ffmpeg_args_set || force_free)
764764
safe_free_string(&config.ffmpeg_args);
765-
if (!cmd_status_page_path_set) {
765+
if (!cmd_status_page_path_set || force_free) {
766766
safe_free_string(&config.status_page_path);
767767
safe_free_string(&config.status_page_route);
768768
}
769-
if (!cmd_player_page_path_set) {
769+
if (!cmd_player_page_path_set || force_free) {
770770
safe_free_string(&config.player_page_path);
771771
safe_free_string(&config.player_page_route);
772772
}
773-
if (!cmd_external_m3u_url_set)
773+
if (!cmd_external_m3u_url_set || force_free)
774774
safe_free_string(&config.external_m3u_url);
775775

776776
/* Free bind addresses */
777-
if (!cmd_bind_set) {
777+
if (!cmd_bind_set || force_free) {
778778
free_bindaddr(bind_addresses);
779779
bind_addresses = NULL;
780780
}
@@ -844,25 +844,22 @@ void config_init(void) {
844844
* Reload configuration from file
845845
* Sequence: config_free() -> config_init() -> parse_config_file()
846846
*
847-
* @param out_old_workers If non-NULL, receives the old workers count
848847
* @param out_bind_changed If non-NULL, set to 1 if bind addresses changed
849848
* @return 0 on success, -1 on error (keeps old config)
850849
*/
851-
int config_reload(int *out_old_workers, int *out_bind_changed) {
852-
int old_workers;
850+
int config_reload(int *out_bind_changed) {
853851
bindaddr_t *old_bind_addresses;
854852

855853
if (!config_file_path) {
856854
logger(LOG_ERROR, "No config file path set, cannot reload");
857855
return -1;
858856
}
859857

860-
/* Save current values for comparison and potential rollback */
861-
old_workers = config.workers;
858+
/* Save current bind addresses for comparison and potential rollback */
862859
old_bind_addresses = copy_bindaddr(bind_addresses);
863860

864861
/* Step 1: Free all configuration resources */
865-
config_free();
862+
config_free(false);
866863

867864
/* Step 2: Initialize configuration with defaults */
868865
config_init();
@@ -871,8 +868,6 @@ int config_reload(int *out_old_workers, int *out_bind_changed) {
871868
if (parse_config_file(config_file_path) != 0) {
872869
logger(LOG_ERROR, "Failed to parse config file during reload: %s",
873870
config_file_path);
874-
/* Restore old workers count */
875-
config.workers = old_workers;
876871
/* Restore old bind addresses */
877872
if (!cmd_bind_set) {
878873
bind_addresses = old_bind_addresses;
@@ -889,11 +884,6 @@ int config_reload(int *out_old_workers, int *out_bind_changed) {
889884
!bind_addresses_equal(bind_addresses, old_bind_addresses);
890885
}
891886

892-
/* Output old workers count for supervisor to compare */
893-
if (out_old_workers) {
894-
*out_old_workers = old_workers;
895-
}
896-
897887
/* Clean up saved bind addresses */
898888
if (old_bind_addresses)
899889
free_bindaddr(old_bind_addresses);

src/configuration.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __CONFIGURATION_H__
33

44
#include <net/if.h>
5+
#include <stdbool.h>
56
#include <stdint.h>
67
#include <stdio.h>
78

@@ -133,19 +134,19 @@ void config_init(void);
133134
* Free all configuration resources
134135
* Frees services, EPG cache, M3U cache, bind addresses, and config strings.
135136
* Respects cmd_*_set flags - resources set by command line are NOT freed.
137+
* If force_free is true, all resources are freed regardless of cmd_*_set flags.
136138
*/
137-
void config_free(void);
139+
void config_free(bool force_free);
138140

139141
/**
140142
* Reload configuration from file
141143
* Sequence: config_free() -> config_init() -> parse_config_file()
142144
* Respects command line overrides (cmd_*_set flags).
143145
*
144-
* @param out_old_workers If non-NULL, receives the old workers count
145146
* @param out_bind_changed If non-NULL, set to 1 if bind addresses changed
146147
* @return 0 on success, -1 on error (keeps old config)
147148
*/
148-
int config_reload(int *out_old_workers, int *out_bind_changed);
149+
int config_reload(int *out_bind_changed);
149150

150151
/**
151152
* Get the config file path used during startup

src/connection.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,21 @@ int connection_route_and_start(connection_t *c) {
645645
handle_set_log_level(c);
646646
return 0;
647647
}
648+
if (api_name_len == strlen("clear-logs") &&
649+
strncmp(api_name, "clear-logs", api_name_len) == 0) {
650+
handle_clear_logs(c);
651+
return 0;
652+
}
653+
if (api_name_len == strlen("reload-config") &&
654+
strncmp(api_name, "reload-config", api_name_len) == 0) {
655+
handle_reload_config(c);
656+
return 0;
657+
}
658+
if (api_name_len == strlen("restart-workers") &&
659+
strncmp(api_name, "restart-workers", api_name_len) == 0) {
660+
handle_restart_workers(c);
661+
return 0;
662+
}
648663

649664
http_send_404(c);
650665
return 0;

0 commit comments

Comments
 (0)