summaryrefslogtreecommitdiff
path: root/pbot-ng_fixer
blob: b0407270501ad007b76ded3ddad2a7a6664a693c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /bin/bash

while true
do
    sleep 30m

    # If nothing has been written to the log for 30 minutes then we assume
    # pbot is dead.
    if [[ -z $(find logs/ -iname 'raw.log' -mmin -30) ]]
    then
        echo "[pbot-ng_fixer]: restarting pbot due to inactivity"

        # Kill all pbot processes
        while read -r pid
        do
            # If it's not the pid of this process then kill it.
            [[ "${pid}" != "$$" ]] || continue

            echo "[pbot-ng_fixer]: killing '$(ps -p ${pid} -o comm=)'(${pid})"
            kill "${pid}" &>/dev/null
        done < <( pgrep -u pbot )

        # Start pbot
        cd /home/pbot

        ./envbot &
        ./labs_change_detector &
    fi
done