summarylogtreecommitdiffstats
path: root/gogios-bin.install
blob: aa07d8af0bd0f9b236f183c679909902a9bb529c (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
pre_install() {
    if ! grep "^gogios:" /etc/group &>/dev/null; then
        groupadd -r gogios
    fi
    
    if ! id gogios &>/dev/null; then
        useradd -r -M gogios -s /bin/false -d /var/spool/gogios -g gogios
    fi
}

post_install() {
    LOG_DIR=/var/log/gogios
    SCRIPT_DIR=/usr/lib/gogios/scripts

    test -d $LOG_DIR || mkdir -p $LOG_DIR
    chown -R -L gogios:gogios $LOG_DIR
    chmod 755 $LOG_DIR

    cp -f $SCRIPT_DIR/gogios.service /usr/lib/systemd/system/gogios.service
    systemctl enable gogios || true
    systemctl daemon-reload || true

    # Add defaults file if it doesn't exist
    if [[ ! -d /etc/default/gogios ]]; then
        touch /etc/default/gogios
    fi
    
    # If the user has no checks yet, give them the example file
    if [ ! -f /etc/gogios/checks.json ]; then
        echo "Making default check file"
        cp /etc/gogios/example.json /etc/gogios/checks.json
    fi

    # Gogios will fail to start if these files aren't owned
    chown gogios:gogios -R /opt/gogios
}

post_upgrade() {
    post_install
}

post_remove() {
    systemctl disable gogios
    rm -f /usr/lib/systemd/system/gogios.service
}