Skip to content

Conversation

timoxley
Copy link
Contributor

@timoxley timoxley commented Apr 27, 2021

This should make starting and stopping collections of related services easier.

  • Maintains existing service naming, only adds new aliases.
  • Aliases should work automatically with all commands, including stop, restart, log and --except flag.
  • Aliases will also work automatically for new commands, but may require some special handling if adding a new --flag.
  • Easy enough to add new aliases. Please do add more if your work regularly requires starting & stopping a particular set of services.

Examples

Start Trackers

sdd start trackers
# sdd start tracker-1 tracker-2 tracker-3

Start Brokers (Nodes)

sdd start nodes # equivalent to sdd start brokers (also works)
# sdd broker-node-no-storage-1 broker-node-no-storage-2 broker-node-storage-1 

Start Brokers & Trackers

sdd start brokers trackers
# sdd start broker-node-no-storage-1 broker-node-no-storage-2 broker-node-storage-1 tracker-1 tracker-2 tracker-3

Log Only Brokers

sdd log -f brokers
# sdd log -f broker-node-no-storage-1 broker-node-no-storage-2 broker-node-storage-1

Start Non-Storage Nodes

sdd start no-storage-nodes
# sdd start broker-node-no-storage-1 broker-node-no-storage-2

Start Storage Node(s)

sdd start storage-nodes
# sdd start broker-node-storage-1

Start all except brokers and trackers

sdd start --except brokers --except trackers
# sdd start --except broker-node-no-storage-1 --except broker-node-no-storage-2 --except broker-node-storage-1 --except tracker-1 --except tracker-2 --except tracker-3

Caveats

  • Works via very simple string substitution on list of services, no word boundary detection, so does open door for weird double-processing if the thing you substitute also matches another alias, or if the alias appears inside a service name. Need to be careful when adding new services that they don't match an existing alias.
  • Aliases are only documented in source, not listed in help currently, but broken windows, the list of services isn't in help either. I tried briefly but didn't see an easy way to do the reverse lookup needed to autogenerate the the list of aliases. The one option I did find, using an array of arrays, required a newer version of bash 4.x which doesn't ship by default on macos 3.x :/

If you want to check exactly what command will be run, and thus which services will be started/stopped/etc, you can always use --dry-run.

See here for aliases:

# Service Aliases
NODE_NO_STORAGE='broker-node-no-storage-1 broker-node-no-storage-2'
NODE_STORAGE='broker-node-storage-1'
NODES="$NODE_NO_STORAGE $NODE_STORAGE"
TRACKERS='tracker-1 tracker-2 tracker-3'
# swap aliases for full names e.g. trackers = tracker-1 tracker-2 tracker-3
# feel free to add more, just make sure you don't end up using actual service
# names as alias names
expandServiceAliases() {
local names=$1
names="${names//node-no-storage/$NODE_NO_STORAGE}"
names="${names//no-storage-nodes/$NODE_NO_STORAGE}"
names="${names//node-storage/$NODE_STORAGE}"
names="${names//storage-nodes/$NODE_STORAGE}"
names="${names//brokers/$NODES}"
names="${names//nodes/$NODES}" # brokers/nodes sort of interchangeable
names="${names//trackers/$TRACKERS}"
echo "$names"
}

@timoxley timoxley requested review from harbu, jtakalai and kare April 27, 2021 13:24
@timoxley timoxley merged commit 9893886 into master Apr 29, 2021
@timoxley timoxley deleted the service-aliases branch April 29, 2021 13:18
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.

2 participants