MichaelXavier / Angel

Process Monitoring/Management, Like Daemontools

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

multiple processes?

mwotton opened this issue · comments

I'd like to use angel to keep many processes of the same type running. Is there an idiomatic way to do that? Writing out 80 process blocks is unappealing.

Weird I just needed this today as well. I may have time to take a crack at it this week...

Do you guys have any ideas on how we could sensibly fit this into the confines of the configurator package? It isn't immediately obvious to me how we'd specify multiple processes in one directive. One idea I could see would look like

http-server {
  exec = "my-http-server"
  count = 10
}

This could internally generate programs named http-server-1, http-server-2, etc. There are some subtle semantics there. If the config is changed and the count decremented to 5, it would have to shut down servers 6-10.

Configurator supports using other values in the configuration file to do interpolation like:

port = 9000
exec = "my-http-server -p $(port)"

So long as we don't need to interpolate the program number into the config itself, this seems pretty easy -- just a simple transform step after loading the config. However if we had to do something like:

exec = "my-http-server -p $(port + program_number)"

Then you'd likely have a lot more work on your hands, as configurator string interploation looks in the current config's context first, then in the OS environment. Doing math to generate port numbers would probably be a problem.

http://hackage.haskell.org/packages/archive/configurator/latest/doc/html/Data-Configurator.html#g:4

One cheap hack would be to allow preprocessing of the config file, so that what Configurator actually sees is stanzas for http-server-1, http-server-2 etc, but what the user sees is some kind of looping construct. Still, I don't have a strong opinion on the underlying implementation, just the functionality I need.

I think I'd be more in favor of just parsing the file as is and expanding a count variable into multiple, uniquely named processes. Rather than having to write a parser, that would pretty much be a matter of adding a HashMap Name Value -> HashMap Name Value step in the middle and then the aforementioned config reload logic.

Provided that you don't need to do port enumeration like I said then it should be a pretty easy fix. If you do need to expand which instance number you're on in the executable, this solution won't work so well. Maybe it would be enough if Angel injected a special environment variable into the executable's environment, so if you did need to enumerate port numbers or log files or something you could just write a shell script that wraps the real binary.

I may have some time to take a look at doing this soon.

Could you have a look at the process-count branch and give it a shot? I made it so you could specify a "count" attribute in the config. I tested it out and it actually works out really nicely, without a need for changing Angel's logic at all. Incrementing/decrementing the process count will add and remove processes as you'd expect. The algorithm for preprocessing the config is a little nasty so if anyone cares enough to clean it up, be my guest.

If this works for you, I'll go ahead and talk to Jamie about getting it merged into master and up on hackage.

sorry this took a while - i get a build error.

Angel/Config.hs:12:20:
Module Data.Ratio' does not exporttruncate'

Sorry about that. I don't know how those two late edits made it in. Could you try again?

https://travis-ci.org/mwotton/Angel/builds/6978515

builds fine, seems to do the right thing. Thanks!

I note this also solves the "commenting out" problem - if you want to temporarily disable a stanza, setting its count to 0 would do just as well.

Cool. I'll add an explicit test case for 0 count and then see about merging this. Thanks for the coordination on this.

hey, minor nit here - it'd be useful if the processes knew which number they were - any chance of setting an env variable?