modern_lisp-machine/misc/scripts/server_git.sh

62 lines
1.8 KiB
Bash
Raw Normal View History

2024-06-01 05:00:40 +00:00
EXEC_SHELL_PATH=$(command -v bash)
### BEGIN INIT INFO
# Provides: ajattix-git
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ajattix Git Monitor
# Description: Monitors Ajattix Git services and restarts if necessary.
### END INIT INFO
# Function to restart loophole
restart_loophole() {
pkill -f "loophole http 3000"
setsid nohup ~/.local/bin/loophole http 3000 --hostname ajattix > "$LOG_SERVICE" 2>&1 &
echo "$(date +"%Y-%m-%d %H:%M:%S"): Loophole restarted due to website unavailability." >> "$LOG_FILE"
}
# Function to start services
start_services() {
echo "$(date +"%Y-%m-%d %H:%M:%S"): Starting services." >> "$LOG_FILE"
setsid nohup bash -c "forgejo -w '$FORGEJO_FOLDER' -c '$FORGEJO_CONFIG' > '$LOG_FILE' 2>&1 &" >/dev/null 2>&1
setsid nohup bash -c "~/.local/bin/loophole http 3000 --hostname ajattix > '$LOG_SERVICE' 2>&1 &" >/dev/null 2>&1
}
# Main script
# Define variables
FORGEJO_FOLDER="/mnt/Data/forgejo/"
FORGEJO_CONFIG="/mnt/Data/forgejo/custom/conf/app.ini"
LOG_SERVICE="/tmp/tunneling_service.log"
LOG_FILE="/tmp/forgejo_monitor.log"
PING_INTERVAL=600 # 10 minutes in seconds
WEBSITE="ajattix.loophole.site"
# Create log directory if it doesn't exist
mkdir -p "$(dirname "$LOG_FILE")"
mkdir -p "$(dirname "$LOG_SERVICE")"
# Start services
start_services
# Run as daemon
while true; do
# Ping website
if ping -c 1 "$WEBSITE" >/dev/null 2>&1; then
echo "$(date +"%Y-%m-%d %H:%M:%S"): Website is reachable." >> "$LOG_FILE"
else
echo "$(date +"%Y-%m-%d %H:%M:%S"): Website is unreachable. Restarting loophole." >> "$LOG_FILE"
restart_loophole
fi
sleep $PING_INTERVAL
done