LoginSignup
3
0

More than 3 years have passed since last update.

Serverspecみたいにサーバの構成が正しいか確認する場合はGossがよさそう

Last updated at Posted at 2020-12-28

概要

Serverspecのようにサーバの構成が正しいかどうかを確認したいときに、Go言語でかかれたGossというツールがよい。このツールは動作もはやく、Go言語なのでランタイムもいらない。ServerspecはRubyが必要。

Gossは,goss.yamlファイルにYAML形式でプロセスが起動しているか、ポートをListenしているか、ファイルは存在するか、ファイル内容は正しいか、HTTPリクエストはできるか。といった内容をチェックできる。

インストール

# Install latest version to /usr/local/bin
curl -fsSL https://goss.rocks/install | sh

Quick Start

systemdなどのプロセス管理システム管理しているサービスであれば、goss autoadd で自動的にgoss.yamlに現在の状態を正しいものとして書き込んでくれる。

sudo goss autoadd sshd

この状態で goss validate を実行すると、下記のように結果を出力する。

........

Total Duration: 0.023s
Count: 8, Failed: 0, Skipped: 0

/healthzを提供する

gossは標準でhealth checkも実行できるようになっている。

goss serve --format json

このコマンドを実行すると、gossはサーバとして動作する。そしてこのサーバに対してcurlでリクエストすると、ヘルスチェックの実行結果が出力される。

curl http://localhost:8080/healthz | jq .

DockerのHEALTHCHECKに使う

下記のDockerfileのようにDockerfileのHEALTHCHECKをgossでチェックさせることもできる

FROM alpine:3.4

RUN apk add --no-cache --virtual=goss-dependencies curl ca-certificates && \
    curl -fsSL https://goss.rocks/install | sh && \
    apk del goss-dependencies
ADD goss.yaml /goss/goss.yaml

HEALTHCHECK --interval=1s --timeout=6s CMD goss -g /goss/goss.yaml validate

参考

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0