Package: adscli
OverviewMicroservices are great, but running them on your dev box is annoying.
Each one has its own commands to start and stop, check status - and how
are you supposed to know where the logs are?ads fixes this by requiring each participating service to expose a
simple uniform interface for the most common commands: start, stop,
status, and log locations.To use ads, drop a file calledads.ymlin each service’s directory:start_cmd:
    gradle run > obscure/logs/dir/out &
    # ads can be used with any build system - cmds are just bash

stop_cmd:
    pgrep -f ninja-service | xargs kill -9
    # Still the most reliable way to kill a process

status_cmd:
    pgrep -f ninja-service
    # Exit status indicates whether any process matched

log_paths:
    - obscure/logs/dir/*
    - even/more/secret/logs/dir/**/ninja.log
    # Note the glob support

description:
    Web service that turns your ordinary app into badass rockstart tech.
    # Optional but a good ideaThere are a few more fields, but this will get you started.Create one more file calledadsroot.yml, in the root of your
codebase:# Actually, you don't need to put anything in it yet.
# The existence of the file is sufficient.Now you can run ads from anywhere in the codebase and get at any of the
services.$ cd /anywhere/in/codebase
$ ads list
   ninja: Web service that turns your ordinary app into badass rockstart tech.Once you’ve “adsified” a bunch of services, ads makes it really
convenient to operate on several at once.$ ads status
--- db: not running
--- ninja: not running
--- pirate: not running

$ ads up ninja pirate
--- Starting [ninja, pirate]
--- Starting ninja
--- Starting pirateGetting startedDependenciesads has been tested with python 2.7.8 on Mac OS Yosemite-El Capitanpythonpip: install witheasy_install pipshell stuff available on any Unixy OS (find,bash,tail,cat)Installingpip install adscliA brief tourIf you want to follow along, install ads (see “Installing”) and clone
this repo to get the sample project
(git clonehttps://github.com/adamcath/ads).$ cd ads/doc/samples/introWhat do we got here?$ ads list
All services in current project (intro):
     ninja: Slices and chops, mostly
        db: (No description)
    pirate: Walks the plank and shivers timbers
...
# We'll come back to the rest of this stuffLet’s start a service:$ ads up -v ninja
--- Starting [ninja]
--- Checking if ninja is already running
cd /intro/./ninja
pgrep -f ninja.sh
--- Starting ninja
cd /intro/./ninja
mkdir logs
bash ninja.sh >logs/ninja.out 2>logs/ninja.err &
--- Started ninja-v makes ads show you what it’s doing. You can usually omit it.Up is idempotent, so you don’t have to remember what state it was in:$ ads up -v ninja
--- Starting [ninja]
--- Checking if ninja is already running
cd /intro/./ninja
pgrep -f ninja.sh
4743
--- ninja is already runningToo much chopping; let’s stop ninja:$ ads down -v ninja
--- Checking if ninja is running
cd /intro/./ninja
pgrep -f ninja.sh
4863
--- Stopping ninja
cd /intro/./ninja
pgrep -f ninja.sh | xargs kill -9
--- Stopped ninjaI forget, is ninja up?$ ads status -v ninja
cd /intro/./ninja
pgrep -f ninja.sh
--- ninja: not runningAny command can take a list of services:$ ads up -v ninja pirate
--- Starting [ninja, pirate]
...If you don’t say which service, ads does ‘em all (you can override this
by settingdefaultin adsroot.yml or ~/.ads_profile.yml):$ ads status
--- db: not running
--- ninja: ok
--- pirate: okLet’s tail the logs:$ ads logs
cd /Users/arc/Projects/ads/doc/samples/intro
tail -F ninja/logs/ninja.err \
    ninja/logs/ninja.out \
    pirate/logs/treasure-chest/pirate.err \
    pirate/logs/treasure-chest/pirate.log

==> ninja/logs/ninja.err <==

==> ninja/logs/ninja.out <==
Chop!
Chop!

==> pirate/logs/treasure-chest/pirate.err <==

==> pirate/logs/treasure-chest/pirate.log <==
Arrrrr!
Arrrrr!tail -F works pretty well with multiple log files, but if you want to
focus on one, just specify the service.The logs command has some cool variants:$ ads help logs
usage: logs [-h] [--tail | --list | --cat] [--general | --errors]
            [service [service ...]]
...
  --tail      (Default) Follow the logs with tail -f
  --list      List the paths of all log files which exist (useful for
              pipelining)
  --cat       Dump the contents of all log files to stdoutFAQMy service needs some one-time setup before it runs. How do I tell ads this?This is a common scenario; for example, you may need to set up the DB
schema before you can start anything. ads doesn’t have a solution for
this yet. Your service should probably try to detect the missing
precondition, refuse to start, and direct the user to the relevant wiki
page.Does ads let me define dependencies?No. This is one area where ads is opinionated: in production, any
service could go down, and the other services would have to be able to
deal with that. The dependant service might go unhealthy, but it
shouldn’t crash. Therefore, starting in an arbitrary order is a special
case of the general problem, which you cannot avoid, of some services
being up and others being down.In other words, if a service can’t even start without another running,
they’re actually one service.What youcando is specify groups of services and easily start them
all (see “Groups” below).Can I specify a “build” step separate from “run”?No. If running requires building, it should just do it. If that’s slow,
then improve your project’s build avoidance to reduce rebuilds.Can I use ads to run my services in production?You could, but it’s probably not very useful. The main benefit of ads is
the ergonomics of running several services from source. In my
experience, this is not a big problem in production.Why isn’t this just…part of the build system?Building is a very general problem, and build systems are quite
flexible. This flexibility comes at a cost: even in a well-factored
build system, you always have to figure out which targets you’re
supposed to run. ads is a “run” system, not a build system, so it can
be restricted to a fixed set of commands - the ones you need to run
services.Big projects often involve multiple languages and build systems. I
wanted a uniform way to run them all.It’s fairly annoying to implement things likeads logsin most
build systems.an init.d script (or similar)?ads is inspired by OS service managers, but:I don’t want to “install” each service on my dev box. That would
raise awkward questions about what happens when I change the code. I
want to run things straight from source.init.d scripts are pretty fugly. Maybe other service managers are
better; if so, I’d be curious to learn about them.I suspect that if this were a good solution, people would be doing
it.some project-specific helper scripts?In my experience, code bases frequently evolve a set of helper scripts
that make it tolerable to deal with multiple projects. They work well
when there’s one command to rule them all, but then somebody wants a way
tojust restart my stuff. Now you add some commands to just do that.
It becomes very hard to prevent spaghetti unless you end up designing
something like ads, which lets you freely compose commands with
services. But then…you could have just used ads!docker/vagrant/virtualization tech x?Virtualization solves a very different (and much deeper) set of problems
than ads. If you have multiple services running in VMs, you still need
something to wrangle them. If everything you use is managed by
docker-compose, you might not need ads. But if some stuff is in docker,
other is native, other in VMs, etc, ads is still useful.DevelopmentInstalling from sourcegit clonehttps://github.com/adamcath/ads.gitpip install-e.Running the automated testsGet the source./unit_tests.sh && ./functional_tests.shAdvanced featuresGroupsYou can define groups of services inadsroot.yml:groups:
    north-america:
    - usa
    - canadaand then operate on the whole group at once:$ ads up north-americaGroups can contain other groups (but not cycles! Nice try!).