Skip to content

A service manager that helps start and stop services, for example, when testing the interaction between processes in an automated integration test

License

Notifications You must be signed in to change notification settings

leadtune/service_manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: www.termsys.demon.co.uk/vtansi.htm

About

A service manager that helps start and stop services, for example, when testing the interaction between processes in an automated integration test

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages