Skip to content

Instantly share code, notes, and snippets.

@henkin
Last active October 4, 2023 17:26
Show Gist options
  • Save henkin/4b965bb0e71223a5d9436507dd717ec0 to your computer and use it in GitHub Desktop.
Save henkin/4b965bb0e71223a5d9436507dd717ec0 to your computer and use it in GitHub Desktop.
seq
#!/bin/bash
# assumes bunyan-seq is installed globally - "npm install -g bunyan-seq"
# run with: npm run dev | ./bunyan-seq.sh
# SEQ_TOKEN comes from either $1, SEQ_TOKEN environment variable, or contents of ~/.seq_token
# This script assumes you've previously created a SEQ_TOKEN (reseq.sh - https://gist.githubusercontent.com/henkin/4b965bb0e71223a5d9436507dd717ec0/raw/636ac6f219010042ae0cbf233ffe1fe19c9a052a/reseq.sh)
export SEQ_TOKEN=${1:-${SEQ_TOKEN:-$(cat ~/.seq_token)}}
echo "token: $SEQ_TOKEN"
bunyan-seq --serverUrl http://localhost:5341 --apiKey $SEQ_TOKEN --logOtherAs Debug
#!/bin/bash
seqcli tail --json | tee logs/wed-logs.json
seqcli ingest --json -i logs/wed-logs.json
seqcli log -l 'Warning' -m '>>> Starting Operation {Operation}! <<<' -p Operation=Starting
seqcli search --json
#!/bin/bash
# This script is used to (re)start the Seq container, and create an API key and token for Seq CLI.
# Before running this script, you must have Seq CLI installed on your machine.
# https://github.com/datalust/seqcli/releases
# This script also requires the following dependencies to be installed:
# - docker
# (re)start seq container, create api key and token for seq_cli
# SEQ_PWD should be SEQ_PWD (if set), ortherwise $1 if defined, or "seq" if undefined
export SEQ_PWD=${SEQ_PWD:-${1:-"seq"}}
export SEQ_PORT=8008
export SEQ_DATA="$HOME/.seq_data"
docker stop seq || true
(docker rm seq || true) && echo "stopped/deleted seq container"
(rm -rf "$SEQ_DATA" || true) && echo "deleted events"
echo "starting seq on :$SEQ_PORT/5341"
SEQ_PWD_HASH=$(echo "$SEQ_PWD" | docker run --rm -i datalust/seq config hash)
export SEQ_FIRSTRUN_ADMINPASSWORDHASH=$SEQ_PWD_HASH
export SEQ_FIRSTRUN_ADMINUSERNAME="admin"
mkdir -p "$SEQ_DATA"
# debug output
# echo "($SEQ_FIRSTRUN_ADMINUSERNAME) pwd ($SEQ_PWD) hash: $SEQ_PWD_HASH"
docker run \
--name seq \
-d \
--restart unless-stopped \
-e ACCEPT_EULA=Y \
-e SEQ_FIRSTRUN_ADMINUSERNAME="$SEQ_FIRSTRUN_ADMINUSERNAME" \
-e SEQ_FIRSTRUN_ADMINPASSWORDHASH="$SEQ_PWD_HASH" \
-v "$SEQ_DATA":/data \
-p "$SEQ_PORT":80 \
-p 8443:443 \
-p 5341:5341 \
datalust/seq
# wait and create api key and token
sleep 2
seqcli config -k connection.serverUrl -v "http://localhost:$SEQ_PORT"
token=$(echo "$SEQ_PWD" | seqcli apikey create -t CLI --connect-username $SEQ_FIRSTRUN_ADMINUSERNAME --connect-password-stdin)
# write token to ~/.seq_token
echo $token > ~/.seq_token
seqcli config -k connection.apiKey -v "$token"
export SEQ_TOKEN="$token"
echo "Seq running at http://localhost:$SEQ_PORT (user: $SEQ_FIRSTRUN_ADMINUSERNAME, pwd: $SEQ_PWD, token: $SEQ_TOKEN)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment