<commit_before>= ServiceManager

It starts processes that have a TCP connection of some kind, most likely webservices.

== Usage

Inside of your project, config/services.rb, declare your services like this:

  ServiceManager.define_service "main-web" do |s|

    # this is the host and port the service will be available on. If something is responding here, don't try to start it again because it's already running
    s.host       = "localhost"
    s.port       = 8090

    s.start_cmd  = lambda { "script/rails server -p #{port}"}

    # When this regexp is matches, ServiceManager will know that the service is ready
    s.loaded_cue = /WEBrick::HTTPServer#start: pid=\d+ port=\d+/

    # ServiceManager will colorize the output as specified by this terminal color id.
    s.color      = 33

    # The directory
    s.cwd        = Dir.pwd + "/main-web/"
  end

  ServiceManager.define_service "tiny-web-service" do |s|

    # ...
  end

== Starting services

You may start your services via the start_services command.  This is helpful if you are working on your integration test suite and don't want to reload the servers each time.

You may also include the following in your integration test suite:

  require "service_manager"
  ServiceManager.start

The command will only start services that are not already running (making it easy to switch between starting them which start_services, or having them start automatically when running your tests)

Your services will be automatically shutdown (via INT, then without mercy, KILL after 3 seconds if it doesn't quit by then) when your integration test process stops, if started by it.
<commit_msg>Updates readme for clarication and profit<commit_after>= ServiceManager

* It starts processes that have a TCP connection of some kind, in foreground mode.  Most likely webservices or consumers
* Runs multiple processes in the same terminal window, colorizing coding the output to to help discern between which output produced which.

TODO:

* Add way to detect if a consumer is running by checking for a pid file.  Currently checking to see if a port is listening is supported.

== Usage

Inside of your super project (the one that contains the distributed applications in your universe), config/services.rb, declare your services like this:

  ServiceManager.define_service "main-web" do |s|

    # this is the host and port the service will be available on. If something is responding here, don't try to start it again because it's already running
    s.host       = "localhost"
    s.port       = 8090

    s.start_cmd  = lambda { "script/rails server -p #{port}"}

    # When this regexp is matches, ServiceManager will know that the service is ready
    s.loaded_cue = /WEBrick::HTTPServer#start: pid=\d+ port=\d+/

    # ServiceManager will colorize the output as specified by this terminal color id.
    s.color      = 33

    # The directory
    s.cwd        = Dir.pwd + "/main-web/"
  end

  ServiceManager.define_service "tiny-web-service" do |s|

    # ...
  end

Then, add service_manager to your Gemfile:

  gem "service_manager"

== Starting services

=== Firing up your services from the command line

If you're going to be running your integration tests multiple times
while debugging them or developing new ones, you may not want to wait
for your services to start and stop every time you run your
integration tests. You may start your services via the start_services
command:

   bundle exec start_services

=== Automatically starting as a part of your tests

You should also include the following in your integration test suite, in features/support/env.rb, spec/spec_helper.rb, etc. where applicable :

  require "service_manager"
  ServiceManager.start

The command will only start services that are not already running, so it will do nothing if you've started your services via the `start_services` command.

If auto-started this way, your services will be automatically shutdown after your integration tests run.

== Tips

* Start your services that you use for testing on different ports than you normally start them for development mode, or you will hate life.

== Other notes

* Lingering processes suck.  ServiceManager is nice but then aggressive when shutting down processes. First, it sends an INT.  If, after 3 seconds, the process hasn't shut down, it sends a KILL signal.
* For color code references, see the bottom of this doc: http://www.termsys.demon.co.uk/vtansi.htm

{'fraction_non_alphanumeric': 0.05813692480359147, 'fraction_numerical': 0.0031425364758698093, 'mean_word_length': 3.680672268907563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '557810', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1119, 'n_words': 602}