Giter Club home page Giter Club logo

lsrv's Introduction

lsrv

lsrv is a tool that helps manage multiple services that use the same protocol and one machine. It was born out of burnout for trying to remember port numbers for each thing running on my machine. Instead, each service can be assigned the default port for the protocol that is intended to be used. For example, instead of trying to remember which port grafana runs on, and which on prometheus runs on, we just use port 80 for both, and reference each service by name: grafana.svc and prometheus.svc.

This tool uses iptables to assign each service an IP address, and then DNAT to remap to localhost and the correct port.

Usage

We can add a service as follows:

# ./bin/lsrv add grafana 3000 80

After running this command, http://grafana.svc will forward to 127.0.0.1:3000. The command modifies /etc/hosts, however this may change to use an nsswitch module in the future. The iptables rules are added to the nat table under the LSRV chain. There will also be a rule to jump to that chain from the OUTPUT chain.

You can ask the cli tool for the IP address:

# ./bin/lsrv resolve grafana

If we no longer wanted grafana to be mapped:

# ./bin/lsrv rm grafana

Changes may not persist across a reboot. You should restore the previous state after a reboot. It may also be necessary to do a restore if the configuration changed.

# ./bin/lsrv restore

You can cleanup the hosts file and iptables with the following command:

# ./bin/lsrv cleanup

Configuration

lsrv provides a TOML based configuration file. By default, lsrv looks for this file at /etc/lsrv.toml. If found, the file is parsed and configuration is taken from there. This can be overridden with the --config switch:

# ./bin/lsrv -c conf/lsrv.toml add prometheus 9090 80

Example configuration:

# ip_block is the ip block to allocate to services in
# CIDR notation
ip_block = "172.22.0.0/23"

# state_file is the path where state kept by lsrv will
# be stored
state_file = "./state"

# hosts_file is where host names will be stored.
hosts_file = "/etc/hosts"

Todo

There are some limitations I hope to fix:

  • Only one entry per service name is allowed
  • The CLI only allows creating ip addresses that forward to 127.0.0.1. This is purely a limitation of the CLI interface. The server doesn't care

lsrv's People

Contributors

jaym avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.