tagit

command module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

TagIt

Go Report Card License codecov

TagIt is a tool that updates Consul service 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.

Table of Contents

Why TagIt?

TagIt addresses a feature that's currently missing from Consul. You can read more about the need for this functionality in this Consul issue.

Here are some scenarios where TagIt can be useful:

  1. Database Leader Tagging: Ensure all writes go to the leader by tagging it appropriately.
  2. Non-Consul-Aware Service Discovery: Use Consul for service discovery with services that aren't Consul-aware.
  3. Web Server VHost Tagging: Tag all vhosts served by a web server or load balancer.
  4. Generic Service Tagging: Tag any services for Consul-based service discovery.

Installation

To install TagIt, use the following commands:

$ git clone https://github.com/ncode/tagit
$ cd tagit
$ go build

Usage

TagIt provides three main commands: run, cleanup, and systemd.

Run Command

The run command starts TagIt and continuously updates the tags based on the script output:

$ ./tagit run --consul-addr=127.0.0.1:8500 --service-id=my-service1 --script=./examples/tagit/example.sh --interval=5s --tag-prefix=tagit

Cleanup Command

The cleanup command removes all tags with the specified prefix from the service:

$ ./tagit cleanup --consul-addr=127.0.0.1:8500 --service-id=my-service1 --tag-prefix=tagit

Systemd Command

The systemd command generates a systemd service file for TagIt:

./tagit systemd --service-id=my-service1 --script=./examples/tagit/example.sh --tag-prefix=tagit --interval=5s --user=tagit --group=tagit

This command will output a systemd service file that you can use to run TagIt as a system service.

How It Works

TagIt interacts with Consul as follows:

sequenceDiagram
    participant tagit
    participant consul
    loop execute script on interval
        tagit->>consul: Query service with ID
        consul->>tagit: Return current service registration
        tagit->>tagit: Execute script and process output
        tagit->>consul: Update service registration with new tags
    end

Examples

Here's an example of how to test TagIt:

  1. Start a Consul agent in development mode:

    consul agent -dev &
    
  2. Register a service with Consul:

    curl --request PUT --data @examples/consul/my-service1.json http://127.0.0.1:8500/v1/agent/service/register
    
  3. Run TagIt:

    ./tagit run --consul-addr=127.0.0.1:8500 --service-id=my-service1 --script=./examples/tagit/example.sh --interval=5s --tag-prefix=tagit
    
  4. Generate a systemd service file:

    ./tagit systemd --service-id=my-service1 --script=./examples/tagit/example.sh --tag-prefix=tagit --interval=5s --user=tagit --group=tagit > /etc/systemd/system/tagit-my-service1.service
    
  5. Clean up the tags:

    ./tagit cleanup --consul-addr=127.0.0.1:8500 --service-id=my-service1 --tag-prefix=tagit
    

Contributing

Contributions to TagIt are welcome! Please feel free to submit a Pull Request.

License

TagIt is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

Documentation

Overview

Copyright © 2022 Juliano Martinez <juliano@martinez.io>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL