Quickstart
Overview
Section titled “Overview”This quickstart runs Vigie on your own machine with two services. It guides you through:
- Build the
vigiebinary. - Write a configuration.
- Start the server.
- Query the services.
- Change an endpoint.
- Clean up.
It’s meant for anyone who wants to see Vigie answer before installing it on a server. It assumes you’re at ease in a terminal. How Vigie works explains the ideas behind what you run here.
Before you start
Section titled “Before you start”You need:
- Go, at the version of the
goline of thego.modof Vigie. gitandcurl.- Port 8080 free on your machine.
Build the vigie binary
Section titled “Build the vigie binary”-
Clone the repository.
Terminal window git clone https://github.com/seagalia/vigie.gitcd vigie -
Build the binary.
Terminal window CGO_ENABLED=0 go build .The
vigiebinary lands in the current directory../vigie versionprints its version.
The releases of Vigie also hold built binaries, see Install Vigie.
Write a configuration
Section titled “Write a configuration”-
Write the endpointsOne IP address and port that a service gives, with its load balancing weight. See HTTP API. of a first service in a file, one per line.
web.txt # web servers10.0.0.510.0.0.6:808110.0.0.7:8080#3A line without a port takes the default portThe port an endpoint takes when its source gives none, set by
default_portof the service. See Configuration. of the service, and#3gives the endpoint a weight of 3. Endpoint lines describes the format. -
Write the configuration, with the service
webread from that file and the servicelocalread from DNS. A relativepathstarts from the directory you runvigiein.config.yml serverserverType object · Required no · Default none
Settings of the HTTP server. A change needs a restart, a reload doesn’t apply it.
:listen_addrserver.listen_addrType string · Required no · Default
:8080Address the server listens on.
: 127.0.0.1:8080servicesservicesType list · Required yes · Default none
Services the server answers for, at least one.
:- nameservices[].nameType string · Required yes · Default none
Name clients ask for. A request without a name gets the service named
: webdefault.default_portservices[].default_portType integer · Required no · Default
80Port of the endpoints that don’t give their own.
: 8080fileservices[].fileType object · Required one source · Default none
Reads the endpoints from a local file.
:pathservices[].file.pathType path · Required yes · Default none
File holding one endpoint line per line.
: web.txt- nameservices[].nameType string · Required yes · Default none
Name clients ask for. A request without a name gets the service named
: localdefault.default_portservices[].default_portType integer · Required no · Default
80Port of the endpoints that don’t give their own.
: 9000dnsservices[].dnsType object · Required one source · Default none
Reads the endpoints from DNS.
:nameservices[].dns.nameType string · Required yes · Default none
DNS name to look up.
: localhost -
Check the file.
Terminal window ./vigie check-config -c config.ymlThe command prints
config <path> is valid, with the absolute path of the file. It also refuses the keys it doesn’t know, whereserveignores them.
Start the server
Section titled “Start the server”Start the server in its own terminal:
./vigie serve -c config.ymlIt logs Listening with the address it listens on, and keeps running until you stop it.
Query the services
Section titled “Query the services”-
Ask for the endpoints of
web.Terminal window curl -s 'http://127.0.0.1:8080/services?service_name=web'[{"ip": "10.0.0.5","port": 8080,"load_balancing_weight": 0},{"ip": "10.0.0.6","port": 8081,"load_balancing_weight": 0},{"ip": "10.0.0.7","port": 8080,"load_balancing_weight": 3}] -
Ask for
local. It gives each address oflocalhoston port 9000, such as127.0.0.1and::1.Terminal window curl -s 'http://127.0.0.1:8080/services?service_name=local' -
Open
http://127.0.0.1:8080/in a browser. The page lists both services with their endpoints, as Web page describes.
Change an endpoint
Section titled “Change an endpoint”Vigie reads the file again once the answer it keeps in cache is older than 5 seconds, so a change to the endpoints needs
no reloadReading the configuration file again to replace the services, on SIGHUP or POST /reload. See Reload the services..
-
Add a line to
web.txt.Terminal window echo '10.0.0.8:8080' >> web.txt -
Wait 5 seconds, then ask for
webagain. The answer holds a fourth endpoint.Terminal window curl -s 'http://127.0.0.1:8080/services?service_name=web'
A change to the configuration itself, such as a new service, needs a reload.
-
Add a third service at the end of
config.yml.config.yml serverserverType object · Required no · Default none
Settings of the HTTP server. A change needs a restart, a reload doesn’t apply it.
:listen_addrserver.listen_addrType string · Required no · Default
:8080Address the server listens on.
: 127.0.0.1:8080servicesservicesType list · Required yes · Default none
Services the server answers for, at least one.
:- nameservices[].nameType string · Required yes · Default none
Name clients ask for. A request without a name gets the service named
: webdefault.default_portservices[].default_portType integer · Required no · Default
80Port of the endpoints that don’t give their own.
: 8080fileservices[].fileType object · Required one source · Default none
Reads the endpoints from a local file.
:pathservices[].file.pathType path · Required yes · Default none
File holding one endpoint line per line.
: web.txt- nameservices[].nameType string · Required yes · Default none
Name clients ask for. A request without a name gets the service named
: localdefault.default_portservices[].default_portType integer · Required no · Default
80Port of the endpoints that don’t give their own.
: 9000dnsservices[].dnsType object · Required one source · Default none
Reads the endpoints from DNS.
:nameservices[].dns.nameType string · Required yes · Default none
DNS name to look up.
: localhost- nameservices[].nameType string · Required yes · Default none
Name clients ask for. A request without a name gets the service named
: defaultdefault.default_portservices[].default_portType integer · Required no · Default
80Port of the endpoints that don’t give their own.
: 8080fileservices[].fileType object · Required one source · Default none
Reads the endpoints from a local file.
:pathservices[].file.pathType path · Required yes · Default none
File holding one endpoint line per line.
: web.txtThe service named
defaultanswers the requests that give noservice_name. -
Reload the services.
Terminal window curl -s -X POST http://127.0.0.1:8080/reloadVigie answers
services reloaded. When the new file is invalid, it answers422with the error and keeps the services it had. -
Ask for the endpoints without a service name.
Terminal window curl -s http://127.0.0.1:8080/services
Clean up
Section titled “Clean up”Stop the server with Ctrl+C, then remove config.yml and web.txt.
Next steps
Section titled “Next steps”- Install Vigie on a server, as a systemd service or in a container.
- Reload the services explains
SIGHUPand why to turnPOST /reloadoff on a shared network. - Configuration lists every key of the file.