diff --git a/db/deploy/deploy.bash b/db/deploy/deploy.bash new file mode 100755 index 00000000..462a6d71 --- /dev/null +++ b/db/deploy/deploy.bash @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Deployment script - intended to run on Moonstream database server + +# Main +SCRIPT_DIR="$(realpath $(dirname $0))" +SERVICE_FILE="${SCRIPT_DIR}/moonstreamdb.service" + +echo +echo +echo "Replacing existing moonstreamdb service definition with ${SERVICE_FILE}" +chmod 644 "${SERVICE_FILE}" +cp "${SERVICE_FILE}" /etc/systemd/system/moonstreamdb.service +systemctl daemon-reload +systemctl restart moonstreamdb.service +systemctl status moonstreamdb.service diff --git a/db/deploy/moonstreamdb.service b/db/deploy/moonstreamdb.service new file mode 100644 index 00000000..627a1cb8 --- /dev/null +++ b/db/deploy/moonstreamdb.service @@ -0,0 +1,13 @@ +[Unit] +Description=moonstreamdb-service +After=network.target + +[Service] +User=ubuntu +Group=www-data +WorkingDirectory=/home/ubuntu/moonstream/db/server +ExecStart=moonstreamdb +SyslogIdentifier=moonstreamdb + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/db/server/go.mod b/db/server/go.mod new file mode 100644 index 00000000..5a8fa99b --- /dev/null +++ b/db/server/go.mod @@ -0,0 +1,3 @@ +module moonstreamdb + +go 1.17 diff --git a/db/server/main.go b/db/server/main.go new file mode 100644 index 00000000..e9eb2811 --- /dev/null +++ b/db/server/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "encoding/json" + "fmt" + "net/http" +) + +type PingResponse struct { + Status string `json:"status"` +} + +func ping(w http.ResponseWriter, req *http.Request) { + w.Header().Set("Content-Type", "application/json") + response := PingResponse{Status: "ok"} + json.NewEncoder(w).Encode(response) +} + +func main() { + address := "0.0.0.0:8931" + fmt.Printf("Starting server at %s\n", address) + + http.HandleFunc("/ping", ping) + + http.ListenAndServe(address, nil) +}