~j-harbott/cirros/dev

« back to all changes in this revision

Viewing changes to src/etc/rc.d/init.d/cloud-functions

  • Committer: Scott Moser
  • Date: 2011-09-21 00:58:21 UTC
  • Revision ID: smoser@ubuntu.com-20110921005821-fxtb4o4xaqktm1dm
add 'src' from old ttylinux-uec (revno 55).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# vi: ts=4 noexpandtab
 
3
 
 
4
BURL="http://169.254.169.254/2009-04-04"
 
5
MDURL="${BURL}/meta-data"
 
6
UDURL="${BURL}/user-data"
 
7
STATE_D=/var/lib/cloud
 
8
CLOUD_CONFIG=${STATE_D}/config.sh
 
9
MD_DEBUG_COUNT=30
 
10
MD_MAX_TRIES=30
 
11
IS_NOCLOUD=0
 
12
 
 
13
[ -d "${STATE_D}" ] || mkdir -p "${STATE_D}"
 
14
 
 
15
[ -f "${CLOUD_CONFIG}" ] && . "${CLOUD_CONFIG}"
 
16
# CLOUD_CONFIG may set
 
17
# MD_TRIES
 
18
# MD_DEBUG_COUNT
 
19
 
 
20
TMPF=/tmp/${0##*/}.tmp
 
21
trap "rm -f ${TMPF}" EXIT
 
22
msg() { echo "${XN}: $1"; }
 
23
mdget() {
 
24
        if [ "${2}" = "-" ]; then
 
25
                wget -q -O - "${MDURL}/${1}"
 
26
        else
 
27
                local out=${2:-${TMPF}}
 
28
                wget -q -O - "${MDURL}/${1}" > "${out}" &&
 
29
                        { read _RET < "${TMPF}" ; :; }
 
30
        fi
 
31
}
 
32
marked() {
 
33
        local name=${2:-${XN}} iid=${1}
 
34
        [ -f "${STATE_D}/${name}.${iid}" ]
 
35
}
 
36
mark() {
 
37
        local name=${2:-${XN}} iid=${1}
 
38
        { [ -d "${STATE_D}" ] || mkdir "${STATE_D}"; } ||
 
39
                msg "failed to make ${STATE_D}"
 
40
        date > "${STATE_D}/${name}.${iid}"
 
41
}
 
42
 
 
43
mddebug() {
 
44
        local dbf="${STATE_D}/mddebug"
 
45
        if [ -f "${dbf}" ]; then
 
46
                chmod 755 "${dbf}"
 
47
                msg "running ${dbf} (${MD_DEBUG_COUNT} tries reached)"
 
48
                echo "############ debug start ##############"
 
49
                "${STATE_D}/debug"
 
50
                echo "############ debug end   ##############"
 
51
                return
 
52
        fi
 
53
        msg "running debug (${MD_DEBUG_COUNT} tries reached)"
 
54
        echo "############ debug start ##############"
 
55
        echo "### /etc/rc.d/init.d/sshd start"
 
56
        /etc/rc.d/init.d/sshd start
 
57
        local gw=""
 
58
        gw=$(route -n | awk '$1 == "0.0.0.0" && $2 != "0.0.0.0" { print $2 }')
 
59
        echo "### ifconfig -a"
 
60
        ifconfig -a
 
61
        echo "### route -n"
 
62
        route -n
 
63
        echo "### cat /etc/resolv.conf"
 
64
        cat /etc/resolv.conf
 
65
        if [ -n "${gw}" ]; then
 
66
                echo "### ping -c 5 ${gw}"
 
67
                ping -c 5 ${gw}
 
68
        else
 
69
                echo "### gateway not found"
 
70
        fi
 
71
        local t1 t2 t3 nslist="" ns=""
 
72
        while read t1 t2 t3; do
 
73
                case "$t1" in
 
74
                        nameserver) nslist="${nslist} ${t2}";;
 
75
                esac
 
76
        done < /etc/resolv.conf
 
77
        echo "### pinging nameservers"
 
78
        for ns in ${nslist}; do
 
79
                echo "#### ping -c 5 ${ns}"
 
80
                ping -c 5 ${ns}
 
81
        done
 
82
        echo "### uname -a"
 
83
        uname -a
 
84
        lxc-is-container || { echo "### lsmod"; lsmod; }
 
85
        echo "### dmesg | tail"
 
86
        dmesg | tail
 
87
        echo "### tail -n 25 /var/log/messages"
 
88
        tail -n 25 /var/log/messages
 
89
        echo "############ debug end   ##############"
 
90
}
 
91
 
 
92
is_nocloud() {
 
93
        [ "${IS_NOCLOUD:-0}" != "0" ] && return 0
 
94
        lxc-is-container ||
 
95
                { grep -q "ds=nocloud" /proc/cmdline && return 0; }
 
96
        [ -f /root/nocloud ] && return 0
 
97
        return 1
 
98
}