-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
serve: Ensure redis-server saves after signal
This is part one of improved shutdown handling; part two will come in a future commit involving a more graceful shutdown of the main node process itself. I began to notice that running `./go serve` to launch the redis-server, using the app, and then killing the script quickly resulted in data loss. This didn't happen when running redis-server manually, as a signal sent to that process would result in it saving its data before exiting. The problem appeared to be that signals sent to the `./go serve` script would be sent simultaneously to the redis-server process, under which circumstances it wouldn't save its data automatically. The script now launches redis-server in a separate process group so that any signals sent to the script aren't sent to the redis-server process. The custom-links server itself now runs as a background process so that the it can be managed explicitly via a trap on the TERM, INT, and HUP signals. Finally, an EXIT trap sends the `shutdown save` command to the redis-server and waits for the process to exit to complete a graceful shutdown with all data saved. The redis-server also now runs with `--appendonly yes` specified, providing more durability against data loss. This also marks the first time Bats tests have been added for any of the scripts. These are now included as part of `./go test`. The `./go serve` script is pretty well-tested at this point, but a few notes: * `scripts/lib/config-json` needs tests specific to it * The new helper functions added to `tests/scripts/serve.bats`, namely `run_in_background`, `wait_for_background_output`, and `stop_background_run`, should get moved into the `go-script-bash` framework. * `scripts/lib/config-json` and parts of `scripts/serve` might make sense to move into `go-script-bash` as well. * Coverage for `./go test scripts` isn't yet enabled.
- Loading branch information
Showing
8 changed files
with
394 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
.config/env.local | ||
.coverage/ | ||
coverage/ | ||
appendonly.aof | ||
dump.rdb | ||
node_modules/ | ||
npm.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#! /usr/local/env bash | ||
# | ||
# Access to configuration values in JSON files | ||
# | ||
# Requires that `jq` is installed on the system. | ||
|
||
# Sets a variable based on an environment variable or configuration file entry | ||
# | ||
# Arguments: | ||
# config_file_path: Path to the configuration file | ||
# config_entry_name: Name of the configuration file entry, e.g. `REDIS_HOST` | ||
# result_var_name: Name of caller's variable into which to store the value | ||
# default_value: Value to assign if neither env or config var is set | ||
# | ||
# Returns: | ||
# Zero if `result_var_name` has been set with either an env or config var | ||
# value; nonzero if it's been set using the default value | ||
cl.get_config_variable() { | ||
local config_file_path="$1" | ||
local config_entry_name="$2" | ||
local result_var_name="$3" | ||
local default_value="$4" | ||
local env_var_name="CUSTOM_LINKS_${config_entry_name}" | ||
local config_value="${!env_var_name:-null}" | ||
local result='0' | ||
|
||
if [[ "$config_value" == 'null' ]]; then | ||
config_value="$(jq -r ".${config_entry_name}" "$config_file_path")" | ||
fi | ||
if [[ "$config_value" == 'null' ]]; then | ||
config_value="$default_value" | ||
result='1' | ||
fi | ||
printf -v "$result_var_name" '%s' "$config_value" | ||
return "$result" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#! /usr/bin/env bash | ||
# | ||
# Tests `./go` scripts | ||
# | ||
# | ||
|
||
# Passes all arguments through to `@go.bats_main` from `lib/bats-main`. | ||
_test_main() { | ||
local _GO_BATS_COVERAGE_INCLUDE | ||
_GO_BATS_COVERAGE_INCLUDE=('scripts/') | ||
local _GO_COVERALLS_URL='https://coveralls.io/github/mbland/custom-links' | ||
|
||
. "$_GO_USE_MODULES" 'bats-main' | ||
# Tab completions | ||
@go.bats_main "$@" | ||
} | ||
|
||
_test_main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
. "$_GO_CORE_DIR/lib/testing/environment" | ||
. "$_GO_CORE_DIR/lib/bats/assertions" | ||
|
||
set_bats_test_suite_name "${BASH_SOURCE[0]%/*}" | ||
remove_bats_test_dirs |
Oops, something went wrong.