reloadCommand returns an entrypoint that convinces the pgBackRest TLS server to reload its options and certificate files when they change. The process will appear as name in `ps` and `top`.
(name string, repos []v1beta1.PGBackRestRepo)
| 560 | // to reload its options and certificate files when they change. The process |
| 561 | // will appear as name in `ps` and `top`. |
| 562 | func reloadCommand(name string, repos []v1beta1.PGBackRestRepo) []string { |
| 563 | var repo1MaxGrow string |
| 564 | var repo2MaxGrow string |
| 565 | var repo3MaxGrow string |
| 566 | var repo4MaxGrow string |
| 567 | repo1Trigger := util.AutoGrowTriggerDefault |
| 568 | repo2Trigger := util.AutoGrowTriggerDefault |
| 569 | repo3Trigger := util.AutoGrowTriggerDefault |
| 570 | repo4Trigger := util.AutoGrowTriggerDefault |
| 571 | |
| 572 | // Loop through any repos and see if we have autogrow configured |
| 573 | // If we do, set the variables corresponding to each of the 4 repos |
| 574 | for _, repo := range repos { |
| 575 | // Only check repos that have a volume with autogrow configured |
| 576 | if repo.Volume == nil || repo.Volume.VolumeClaimSpec.AutoGrow == nil { |
| 577 | continue |
| 578 | } |
| 579 | spec := repo.Volume.VolumeClaimSpec |
| 580 | switch repo.Name { |
| 581 | case "repo1": |
| 582 | repo1Trigger, repo1MaxGrow = util.GetAutoGrowFromSpec(&spec) |
| 583 | case "repo2": |
| 584 | repo2Trigger, repo2MaxGrow = util.GetAutoGrowFromSpec(&spec) |
| 585 | case "repo3": |
| 586 | repo3Trigger, repo3MaxGrow = util.GetAutoGrowFromSpec(&spec) |
| 587 | case "repo4": |
| 588 | repo4Trigger, repo4MaxGrow = util.GetAutoGrowFromSpec(&spec) |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | // Use a Bash loop to periodically check the mtime of the mounted server |
| 593 | // volume and configuration file. When either changes, signal pgBackRest |
| 594 | // and print the observed timestamp. |
| 595 | // |
| 596 | // We send SIGHUP because this allows the TLS server configuration to be |
| 597 | // reloaded starting in pgBackRest 2.37. We filter by parent process to ignore |
| 598 | // the forked connection handlers. The server parent process is zero because |
| 599 | // it is started by Kubernetes. |
| 600 | // - https://github.com/pgbackrest/pgbackrest/commit/7b3ea883c7c010aafbeb14d150d073a113b703e4 |
| 601 | |
| 602 | // Coreutils `sleep` uses a lot of memory, so the following opens a file |
| 603 | // descriptor and uses the timeout of the builtin `read` to wait. That same |
| 604 | // descriptor gets closed and reopened to use the builtin `[ -nt` to check |
| 605 | // mtimes. |
| 606 | // - https://unix.stackexchange.com/a/407383 |
| 607 | |
| 608 | // In the manageAutogrowAnnotation function below, df is used to return the |
| 609 | // relevant volume size in Mebibytes. The 'read' variable gets the value from |
| 610 | // the '1M-blocks' output (second column) and the 'use' variable gets the value |
| 611 | // from the 'Use%' column (fifth column). This value is grabbed after stripping |
| 612 | // out the column headers (before the '\n') and then getting the respective |
| 613 | // value delimited by the white spaces by using the 'read -r' command. |
| 614 | // The underscores (_) discard fields and the variables store them. This allows |
| 615 | // for selective parsing of the provided lines. The percent value is stripped of |
| 616 | // the '%' and then used to determine if a expansion should be triggered by |
| 617 | // setting the calculated volume size using the 'size' variable. |
| 618 | script := fmt.Sprintf(` |
| 619 | # Parameters for curl when managing autogrow annotation. |