diff --git a/.gitignore b/.gitignore index ed3fd24275caab560f051db1e0d13d67c2170e71..50a4132ced4c53f982ffd1c303c6bed91884def4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .*.sw[op] .DS_Store acme-web +acme-web*.deb +acme-web*.rpm \ No newline at end of file diff --git a/README.md b/README.md index b3de4074d25f669c745827d373c33c1da948f968..40d62639d1a07d4b3d64a27c531791ea95c25296 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,19 @@ -# dns-checker +# acme-web ## Table of contents 1. [Preamble](#preamble) 2. [Compiling the program](#compiling-the-program) -3. [Keepalived and LVS](#keepalived-and-LVS) -4. [Available options](#available-options) -5. [Setting up systemd](#setting-up-systemd) +3. [Setting up systemd](#setting-up-systemd) ## Preamble -What problems this application tries to solve? UDP can't be easily checked. This application checks the local DNS and optionally Consul DNS and serves the status through a Web page. +This applications runs a Web server and it: -I use it in conjunction with LVS and my understanding is that LVS does not allow to run multiple instances of the same check. For instance, LVS has a `DNS_CHECK` statement, but in my case I need to run it multiple times, to check either the DNS and Consul DNS. - -This application runs as a daemon on the same machine where the DNS is running and it can be used in conjunction with your UDP load-balancer to check the status of your DNS. - -You can also use it from Nagios, Sensu and issue a simple HTTP check. +* runs an external command to create a JSON file (this functionality should be moved into this app) +* transform json object into html table +* serves json object as API +* serves html pages ## Compiling the program @@ -29,95 +26,9 @@ LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) PROG_VERSION=${LATEST_TAG:1} BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S') git checkout $LATEST_TAG - -go get -ldflags "-s -w -X main.appVersion=${PROG_VERSION} -X main.buildTime=${BUILD_TIME}" . -``` - -## Keepalived and LVS - -For instance, with Keepalived + LVS I am using a configuration as follows: - -```txt -HTTP_GET { - connect_port 10053 - connect_timeout 3 - delay_before_retry 1 - http_protocol 1.1 - nb_get_retry 2 - url { - digest 6d3bcaba1fff8c5a461669b409c1a6d2 - path /ipv4 - } -} -``` - -the digest is calculated using this command (`genhash` belongs to keepalived package): - -```bash -genhash -s 127.0.0.1 -p 10053 -u /ipv4 -``` - -And if you receive a 200 status code, you'll get the same digest as mine, because the digest is computed against the small HTML snippet embedded in the `main.go`. - -You could also use the HTTP status code: `man keepalived.conf` and search for `status_code`. - -## Available options - -You can check the options as follows: - -```shell -$ dns-checker --help -DNS Checker: - - checks DNS and optionally Consul and report the status on a Web page - -Usage: - dns-checker [--listen-address=LISTENADDRESS] [--listen-port=LISTENPORT] [--verbose] - dns-checker -h | --help - dns-checker -b | --build - dns-checker -v | --version - -Options: - -h --help Show this screen - -b --build Print version and build information and exit - -v --version Print version information and exit - --listen-address=LISTENADDRESS Web server address. Check Go net/http documentation [default: any] - --listen-port=LISTENPORT Web server port [default: 8000] - --verbose Log also successful connections -``` - -Once it is installed you can check the status using curl (with `curl -I` you get the status code): - -```bash -curl http://localhost:8000/sectigo_ev/index.html +go build -ldflags "-s -w -X main.appVersion=${PROG_VERSION} -X main.buildTime=${BUILDTIME}" -o acme-web ``` ## Setting up systemd -In this case I am also checking Consul, and I check the existance of one local record called `dumb-record.dumb.zone` in the DNS and one record called `consul.service.domain.org` in Consul. - -It is not sensible to check for a record on a forwarded zone, because there can be a problem elsewhere (in the network, or in he SOA of the other domain) and we don't want to bring our DNS down if something else is broken. - -In this case I run it as `unbound` user because I use unbound: - -```systemd -# -# Start ACME web service on port 8000 -# -[Unit] -Description=ACME Web service written in Go -Wants=basic.target -After=basic.target network.target - -[Service] -User=root -Group=root -ExecStart=/usr/bin/acme-web -Restart=on-failure -RestartSec=10 -StandardOutput=syslog -StandardError=syslog -SyslogIdentifier=acme-web - -[Install] -WantedBy=multi-user.target -``` +Check `acme-web.service` in this repository diff --git a/acme-web.service b/acme-web.service new file mode 100644 index 0000000000000000000000000000000000000000..267a0b0ade52b76adc35f359528b595cf6d2d37d --- /dev/null +++ b/acme-web.service @@ -0,0 +1,20 @@ +# +# Start ACME web service on port 8000 +# +[Unit] +Description=ACME Web service written in Go +Wants=basic.target +After=basic.target network.target + +[Service] +User=root +Group=root +ExecStart=/usr/bin/acme-web +Restart=on-failure +RestartSec=10 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=acme-web + +[Install] +WantedBy=multi-user.target diff --git a/inputs.txt b/inputs.txt new file mode 100644 index 0000000000000000000000000000000000000000..536b48487eb1598d4a718b2c7d1ae6dd3218a071 --- /dev/null +++ b/inputs.txt @@ -0,0 +1,3 @@ +./acme-web=/usr/bin/acme-web +./acme-web.service=/etc/systemd/system/acme-web.service +./README.md=/usr/share/doc/acme-web/README.md