slapos-start 2.18 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6


IPV6CHECK=ipv6.google.com
IPV4CHECK=google.com
IPV6WAITTIME=5
7
SLAPOS_CONFIGURATION=/etc/opt/slapos/
8
${ONLY_SLAPFORMAT:=false}
9

10

11 12
if [ $ONLY_SLAPFORMAT = false ]; then
    if [ ! -f  $SLAPOS_CONFIGURATION/slapos.cfg ]; then
Cédric de Saint Martin's avatar
Cédric de Saint Martin committed
13 14
        echo "No slapos.cfg found"
        exit 0
15 16
    fi

Cédric de Saint Martin's avatar
Cédric de Saint Martin committed
17
    echo "Starting slap script"
18

19
    # Check ipv4
20
    echo "Checking IPv4 connectivity..."
21
    ping -c 2 $IPV4CHECK >/dev/null 2>&1
22
    while [ $? != 0 ]; do
23 24
        echo "IPv4 is not ready yet."
        sleep 2
25
        ping -c 2 $IPV4CHECK >/dev/null 2>&1
26
    done
27

28
    # Launch openvpn
29
    if [ -f $SLAPOS_CONFIGURATION/openvpn-needed ]; then
30
        echo "Starting openvpn..."
Cédric de Saint Martin's avatar
Cédric de Saint Martin committed
31
        /etc/init.d/openvpn start
32
    fi
33

34
    # Wait for ipv6 connection to be ready
35
    echo "Checking IPv6 connectivity. This may take a few seconds..."
36
    ping6 -c 2 $IPV6CHECK >/dev/null 2>&1
37 38
    while [ $? != 0 ];
    do
39 40
        echo "IPv6 is not ready yet."
        sleep 2
41
        ping6 -c 2 $IPV6CHECK >/dev/null 2>&1
42 43 44 45
    done
else
    sleep 15
fi
46 47 48 49

# Run slapformat
i=1
echo -n "Running slapformat..." 
50
/opt/slapos/bin/slapformat  --now --console --log_file=/opt/slapos/slapformat.log $SLAPOS_CONFIGURATION/slapos.cfg
51
while [ $? != 0 ]; do
52
    sleep $(($i*60))
53
    if [ $i -le 20 ]; then
Cédric de Saint Martin's avatar
Cédric de Saint Martin committed
54
        let i++
55 56
    fi
    echo "Retrying slapformat"
57
    /opt/slapos/bin/slapformat  --now --console --verbose --log_file=/opt/slapos/slapformat.log $SLAPOS_CONFIGURATION/slapos.cfg
58 59
done

60
if [ $ONLY_SLAPFORMAT = false ]; then
61
    # Run bang
62 63
    i=1
    echo -n "Banging..."
64
    /opt/slapos/bin/bang -m "Rebooted" $SLAPOS_CONFIGURATION/slapos.cfg
65
    while [ $? != 0 ]; do
66 67 68 69 70 71
        sleep $(($i*60))
        if [ $i -le 20 ]; then
            let i++
        fi
        echo "Retrying Bang"
        /opt/slapos/bin/bang -m "Rebooted" $SLAPOS_CONFIGURATION/slapos.cfg
72 73
    done
    echo "done."
74

75
    # Delete timestamp of all partitions so that it will force slapgrid to process them.
76
    rm /srv/slapgrid/slappart*/.timestamp 2>/dev/null
77 78 79

    # Run slapgrid now.
    /opt/slapos/bin/slapgrid-cp --verbose --now --logfile=/opt/slapos/slapgrid-cp.log --pidfile=/opt/slapos/slapgrid-cp.pid $SLAPOS_CONFIGURATION/slapos.cfg >> /opt/slapos/slapgrid-cp.log 2>&1
80
fi
81

82
exit 0