aboutsummaryrefslogtreecommitdiffstats
path: root/hyperbot
blob: 1466ff29f9c96f33cf8abf69b782d339cb18f5bf (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /bin/bash

if [[ "${1}" == 'start' ]]
then
    declare -a pids

    cd /srv/hyperbot/

    ./envbot &
    pids[0]=$!

    ./hyperbot_fixer &
    pids[1]=$!

    ./issues_change_detector &
    pids[2]=$!

    function closedown
    {
        for pid in ${pids[@]}
        do
            kill $pid
        done

        exit
    }

    trap "closedown" SIGINT SIGTERM

    while true
    do
        sleep 5h
    done
elif [[ "${1}" == 'stop' ]]
then
    while true
    do
        pid=$(pgrep -u hyperbot | head -1)

        if [[ -n "${pid}" ]]
        then
            kill ${pid} &>/dev/null
        else
            exit
        fi
    done
else
    echo "first arg must be \`start' or \`stop'"
fi