-
Notifications
You must be signed in to change notification settings - Fork 20
confd: set IITO startup/failure conditions (fixes status LEDs) #1587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -49,6 +49,31 @@ | |||||||||||||||||
| */ | ||||||||||||||||||
| #define SENTINEL_PATH "/run/confd.boot" | ||||||||||||||||||
|
|
||||||||||||||||||
| /* | ||||||||||||||||||
| * Set a finit condition, e.g. "run/startup/success", creating parent | ||||||||||||||||||
| * directories as needed. Used to signal IITO (and finit services) about | ||||||||||||||||||
| * the outcome of the bootstrap/startup sequence. | ||||||||||||||||||
| */ | ||||||||||||||||||
| static void set_finit_cond(const char *cond) | ||||||||||||||||||
| { | ||||||||||||||||||
| char path[128]; | ||||||||||||||||||
| char *p; | ||||||||||||||||||
|
|
||||||||||||||||||
| snprintf(path, sizeof(path), "/run/finit/cond/%s", cond); | ||||||||||||||||||
|
|
||||||||||||||||||
| /* mkdir -p parent directories (e.g. /run/finit/cond/run/startup) */ | ||||||||||||||||||
| for (p = path + strlen("/run/finit/cond/"); *p; p++) { | ||||||||||||||||||
| if (*p == '/') { | ||||||||||||||||||
| *p = '\0'; | ||||||||||||||||||
| mkdir(path, 0755); | ||||||||||||||||||
| *p = '/'; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+64
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Finit guarantees that |
||||||||||||||||||
|
|
||||||||||||||||||
| if (symlink("/run/finit/cond/reconf", path) && errno != EEXIST) | ||||||||||||||||||
| WARN("Failed to set finit condition %s: %m", path); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /* Callback type names from sysrepo plugin API */ | ||||||||||||||||||
| #define SRP_INIT_CB "sr_plugin_init_cb" | ||||||||||||||||||
| #define SRP_CLEANUP_CB "sr_plugin_cleanup_cb" | ||||||||||||||||||
|
|
@@ -512,6 +537,7 @@ static void handle_startup_failure(sr_session_ctx_t *sess, const char *failure_p | |||||||||||||||||
| ERROR("sr_copy_config(factory-default) failed: %s", sr_strerror(r)); | ||||||||||||||||||
| /* Nuclear option: wipe everything */ | ||||||||||||||||||
| systemf("rm -f /etc/sysrepo/data/*startup* /etc/sysrepo/data/*running* /dev/shm/sr_*"); | ||||||||||||||||||
| set_finit_cond("run/failure/failure"); | ||||||||||||||||||
| return; | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @troglobit: Should we not emit the |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -521,11 +547,13 @@ static void handle_startup_failure(sr_session_ctx_t *sess, const char *failure_p | |||||||||||||||||
| ERROR("Failed loading failure-config, aborting!"); | ||||||||||||||||||
| banner_append("CRITICAL ERROR: Logins are disabled, no credentials available"); | ||||||||||||||||||
| systemf("initctl -nbq runlevel 9"); | ||||||||||||||||||
| set_finit_cond("run/failure/failure"); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Depending on @troglobit's input, this path may have to be merged with the earlier error path. But I think at think point we want to signal "we tried, but failed, to apply |
||||||||||||||||||
| return; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| banner_append("ERROR: Corrupt startup-config, system has reverted to default login credentials"); | ||||||||||||||||||
| set_finit_cond("run/failure/success"); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For symmetry with the other condition names. |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /* | ||||||||||||||||||
|
|
@@ -843,6 +871,9 @@ int main(int argc, char **argv) | |||||||||||||||||
| /* Signal that bootstrap is complete (dbus, resolvconf depend on this) */ | ||||||||||||||||||
| symlink("/run/finit/cond/reconf", "/run/finit/cond/usr/bootstrap"); | ||||||||||||||||||
|
|
||||||||||||||||||
| /* Signal IITO that startup applied cleanly (status LEDs) */ | ||||||||||||||||||
| set_finit_cond("run/startup/success"); | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
872
to
+876
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's move the existing condition to use the new helper, but I don't think we can be sure that |
||||||||||||||||||
| /* | ||||||||||||||||||
| * Write restart sentinel. From this point on, sysrepo and the system | ||||||||||||||||||
| * are in a consistent state. If confd exits for any reason (crash or | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the impulse to use the old condition names from IITO's config. However, the
run/namespace is reserved by Finit to signal the status ofrunjobs under its control. Theusr/namespace is allocated for general use by the system.