GitRoot

Craft your forge, Build your project, Grow your community freely
 1#!/usr/bin/env bash
 2
 3# SPDX-FileCopyrightText: 2026 Romain Maneschi <romain@gitroot.dev>
 4#
 5# SPDX-License-Identifier: EUPL-1.2
 6
 7_init() {
 8    local SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 9    source "${SCRIPT_DIR}/waitforlog.sh"
10    source "${SCRIPT_DIR}/report.sh"
11}
12
13_init
14unset -f _init
15
16SERVER_PORT="4545"
17SERVER_DATA_DIR="/tmp/gitrootData"
18
19# restart
20#   If launched stop gitroot. Then start it from source and wait.
21function restart() {
22    APP=$(lsof -i tcp:${SERVER_PORT} | awk 'NR!=1 {print $2}') 
23    if [ -z "$APP" ]; then
24        report "🟢 Gitroot not launched"
25    else 
26        kill ${APP}
27        report "🟢 Gitroot killed"
28    fi
29    local lastKill="⌛ Will restart ($(date +%s))"
30    report "${lastKill}"
31    cd ${SCRIPT_DIR}/../../server
32    GIT_TRACE_PACKET=false go run -race . -data="${SERVER_DATA_DIR}" &>> /tmp/mylog.txt &
33    wait_for_logs "starting SSH server on" /tmp/mylog.txt "${lastKill}"
34}