Skip to content

serve: Ensure redis-server saves after signal#138

Merged
mbland merged 5 commits intomasterfrom
save-on-exit
Aug 19, 2017
Merged

serve: Ensure redis-server saves after signal#138
mbland merged 5 commits intomasterfrom
save-on-exit

Conversation

@mbland
Copy link
Copy Markdown
Owner

@mbland mbland commented Aug 19, 2017

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.

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.
@coveralls
Copy link
Copy Markdown

coveralls commented Aug 19, 2017

Coverage Status

Coverage remained the same at 98.089% when pulling 0634f41 on save-on-exit into 38ab7f3 on master.

@coveralls
Copy link
Copy Markdown

coveralls commented Aug 19, 2017

Coverage Status

Coverage remained the same at 98.089% when pulling cb848871daedd40c78666d805d68d201cc727cff on save-on-exit into 38ab7f3 on master.

I want to do a PR specifically focusing on enabling coverage for Bats
tests, and to see if it can be unified with the JavaScript coverage
reports.
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 98.089% when pulling f1260d1 on save-on-exit into 38ab7f3 on master.

1 similar comment
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 98.089% when pulling f1260d1 on save-on-exit into 38ab7f3 on master.

mbland added 3 commits August 18, 2017 20:54
Turns out `pgrep -q` isn't available on Linux.
This appeared to be causing failues on Travis with colorized output.

Also fixes the tab completion test, since `test-config.json` doesn't
exist out of the box.
On Linux, `nc` will exit with an error if the hostname argument is
empty. Setting it to `localhost` by default fixes the problem.

On Travis, it appears that file descriptors for standard output and
error still look like terminal file descriptors to Bash, even after
being redirected to a file (i.e. `[[ -t 0 && -t 1 ]]` is always true)`.
This causes the `log` module from `go-script-bash` to always emit
terminal-formatted log labels. This played havoc with the previous
`assert_output_matches` assertions, which only checked for whitespace
between log label text and the log message text. The fix was to update
each assertion so that all log labels are immediately followed by `.* `.
@coveralls
Copy link
Copy Markdown

coveralls commented Aug 19, 2017

Coverage Status

Coverage remained the same at 98.089% when pulling e68f097 on save-on-exit into 38ab7f3 on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants