Skip to content
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

Add support for new relx directive that provides start/stop script hooks #445

Merged
merged 2 commits into from
Nov 26, 2016

Conversation

lrascao
Copy link
Collaborator

@lrascao lrascao commented Feb 7, 2016

New 'extended_start_script_hooks' directive that allows the developer to define six different hook scripts to be invoked at pre/post start/stop/install upgrade phases.
Besides these custom defined scripts other types of builtin scripts are also available, these offer pre-packaged functionality that can be used directly, they are:

  • pid - writes the beam pid to a configurable file location
    (/var/run/<rel_name>.pid by default).
  • wait_for_vm_start - waits for the vm to start (ie. when it can be pinged)
  • wait_for_process - waits for a configurable name to appear in the erlang process registry
    The hook scripts are invoked with the 'source' command, therefore they have access to all the variables in the start script.
    These hook scripts apply only to start, stop and upgrade/downgrade/install/uninstall commands.
    The paths are relative to the start script, and the syntax is:
                  {extended_start_script_hooks, [
                        {pre_start, [{custom, "hooks/pre_start"}]},
                        {post_start, [{pid, "/tmp/foo.pid"},
                                      {wait_for_process, some_process},
                                      {custom, "hooks/post_start"}]},
                        {pre_stop, [{custom, "hooks/pre_stop"}]},
                        {post_stop, [{custom, "hooks/post_stop"}]}
                    ]},

Possible use cases:

  • Cuttlefish integration, generate sys.config on the fly when starting the release
  • Generate a pid to a custom location
  • Feedback provider, when starting the node a post_start script can check that the entire application-specific boot process has succeeded

@lrascao lrascao force-pushed the feature/extended_script_hooks branch 10 times, most recently from 1d74e09 to b7084a7 Compare February 7, 2016 22:22
@tsloughter
Copy link
Member

Oh hm, this is great! I need to try this out and use it for my new cuttlefish provider. I'll hopefully merge it in today.

@tsloughter
Copy link
Member

@lrascao problem with this patch is the start hooks only run before start and not foreground or console, right? Would need to also run before those.

@lrascao
Copy link
Collaborator Author

lrascao commented Feb 19, 2016

right, i'll update the PR

@lrascao lrascao force-pushed the feature/extended_script_hooks branch from b7084a7 to d306b5f Compare February 19, 2016 16:59
@lrascao
Copy link
Collaborator Author

lrascao commented Feb 28, 2016

@tsloughter have you had a chance to try this out with cuttlefish?

@tsloughter
Copy link
Member

I haven't since your last update.

@lrascao lrascao force-pushed the feature/extended_script_hooks branch from d306b5f to 4112358 Compare June 15, 2016 13:39
exec "$@" -- ${1+$ARGS}
[ "$POST_START_HOOK" ] && . "$POST_START_HOOK"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One problem with this (and affects all of these) is that the post_start event will either never be executed, or will only be executed when the release stops, which is obviously not desired for a post_start event handler. I think the best way to do this is by backgrounding the task, executing the post_start task, then waiting on the PID, instead of blocking on exec. I'm using this approach right now in some work I'm doing in Mix, because I wanted to trap exit signals and cleanly shut down the VM.

Copy link
Collaborator Author

@lrascao lrascao Jun 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, so something like:

   pre_start_hook
   Pid = spawn (exec "$@" -- ${1+$ARGS})
   post_start_hook
   wait on Pid

did i understood correctly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've since updated the PR, it now sends the execs to background and waits on them after the post hook

@lrascao lrascao force-pushed the feature/extended_script_hooks branch from 4112358 to de70895 Compare June 23, 2016 09:58
@lrascao lrascao force-pushed the feature/extended_script_hooks branch from de70895 to 09838d5 Compare August 24, 2016 20:55
@lrascao lrascao force-pushed the feature/extended_script_hooks branch 2 times, most recently from c51bc55 to b18cd12 Compare September 26, 2016 16:58
@lrascao lrascao force-pushed the feature/extended_script_hooks branch 3 times, most recently from e72b79b to b31a951 Compare October 6, 2016 23:34
@lrascao lrascao force-pushed the feature/extended_script_hooks branch from b31a951 to 5775a01 Compare October 27, 2016 22:22
@lrascao lrascao force-pushed the feature/extended_script_hooks branch 3 times, most recently from e078582 to 15f0940 Compare November 5, 2016 23:07
@lrascao lrascao force-pushed the feature/extended_script_hooks branch 8 times, most recently from 6082ee4 to 4572296 Compare November 10, 2016 22:42
Move it next to console since it's mostly the
same thing but with extra parameters.
@lrascao lrascao force-pushed the feature/extended_script_hooks branch 4 times, most recently from 1e14e04 to 4abbaa6 Compare November 12, 2016 13:56
…ipt hooks

New 'extended_start_script_hooks' directive that allows the
developer to define six different hook shell scripts to be invoked
at pre/post start/stop/install upgrade phases.
Besides these custom defined scripts, other types of builtin
scripts are also available, these offer pre-packaged functionality
that can be used directly, they are:
  pid - writes the beam pid to a configurable file location
          (/var/run/<rel_name>.pid by default).
  wait_for_vm_start - waits for the vm to start (ie. when it responds to pings)
  wait_for_process - waits for a configurable name
                                to appear in the erlang process registry
The hook scripts are invoked with the 'source' command, therefore
they have access to all the variables in the start script.
@lrascao lrascao force-pushed the feature/extended_script_hooks branch from 4abbaa6 to 3905d39 Compare November 12, 2016 23:59
@lrascao
Copy link
Collaborator Author

lrascao commented Nov 13, 2016

@tsloughter this is ready for review
@GoelDeepak @saleyn any feedback from you guys would also be great

@tsloughter
Copy link
Member

Looks great! Should we wait for +1's from @GoelDeepak and @saleyn ?

@lrascao
Copy link
Collaborator Author

lrascao commented Nov 13, 2016

yeah, let's wait a few days, they might have some improvement suggestions

@saleyn
Copy link
Contributor

saleyn commented Nov 13, 2016

Yes, looks like a good idea.

@lrascao lrascao mentioned this pull request Nov 14, 2016
@lrascao
Copy link
Collaborator Author

lrascao commented Nov 15, 2016

@tsloughter i guess it's good to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants