Update consul registration tags with outputs of a script. It copies the current service registration and appends the output of the script line by line as tags, while keeping the original tags.
Basically because it's a very useful feature that is missing from consul. Read more about it here. A few scenarios where this can be useful:
- Your databases are under mydb.service.consul, and you would like to ensure that all the writes go to the leader
- You run a script that checks the leader and updates the tag
- You have a service that is not consul aware, but you would like to use consul for service discovery
- You run a script that checks the service and updates the tags
- You have a load or a webserver, and you would like to have tags for all vhosts that are served by this server
- You run a script that checks the vhosts and updates the tags
- Pretty much any services that are not consul aware, but you would like to use consul for service discovery
- You run a script that checks the service and updates the tags
$ git clone github.com/ncode/tagit
$ go build
$ consul agent -dev &
$ curl --request PUT --data @examples/consul/my-service1.json http://127.0.0.1:8500/v1/agent/service/register
$ ./tagit run --consul-addr=127.0.0.1:8500 --service-id=my-service1 --script=./examples/tagit/example.sh --interval=5s --tag-prefix=tagit
INFO[0000] running command command=./examples/tagit/example.sh service=my-service1
INFO[0000] updating service tags service=my-service1 tags="[v1 tagit-nice tagit-it tagit-works]"
INFO[0005] running command command=./examples/tagit/example.sh service=my-service1
INFO[0010] running command command=./examples/tagit/example.sh service=my-service1
INFO[0015] running command command=./examples/tagit/example.sh service=my-service1
$ ./tagit cleanup --consul-addr=127.0.0.1:8500 --service-id=my-service1 --tag-prefix=tagit
INFO[0000] current service tags service=my-service1 tags="[v1 tagit-nice tagit-it tagit-works]"
INFO[0000] updating service tags service=my-service1 tags="[v1]"
sequenceDiagram
participant tagit
participant consul
loop execute script on interval
tagit->>consul: Do you have a service with id my-service1?
consul->>tagit: Yes, here it is and that's the current registration
tagit->>consul: Update current registration adding or removing prefixed tags wiht the output of the script
end
- Adds a systemd unit file generator