~ubuntu-branches/ubuntu/karmic/vzctl/karmic

« back to all changes in this revision

Viewing changes to etc/vpsreboot

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2007-04-10 18:08:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070410180816-0uuzj9fnna7gmzxv
Tags: 3.0.16-4
Etch has been released which means that this version can be uploaded
to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#  Copyright (C) 2000-2006 SWsoft. All rights reserved.
3
 
#
4
 
#  This program is free software; you can redistribute it and/or modify
5
 
#  it under the terms of the GNU General Public License as published by
6
 
#  the Free Software Foundation; either version 2 of the License, or
7
 
#  (at your option) any later version.
8
 
#
9
 
#  This program is distributed in the hope that it will be useful,
10
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
#  GNU General Public License for more details.
13
 
#
14
 
#  You should have received a copy of the GNU General Public License
15
 
#  along with this program; if not, write to the Free Software
16
 
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
#
18
 
#
19
 
# Script to start VPS was rebooted
20
 
#
21
 
 
22
 
VZCONF=/etc/vz/vz.conf
23
 
CONF_DIR=/etc/vz/conf
24
 
VE_INFO=/proc/vz/veinfo
25
 
REBOOT_MARK='reboot'
26
 
LOCKFILE='/var/lock/vereboot.lock'
27
 
 
28
 
[ -f ${VZCONF} ] || exit
29
 
. ${VZCONF}
30
 
 
31
 
function check_reboot()
32
 
{
33
 
        local veid=${1}
34
 
        local ve_root
35
 
        local allowreboot
36
 
 
37
 
        VEID=${veid}
38
 
        [ -f "${CONF_DIR}/${veid}.conf" ] || return
39
 
        eval ` (
40
 
                . ${VZCONF};
41
 
                . ${CONF_DIR}/${veid}.conf;
42
 
                echo ve_root=${VE_ROOT}\;;
43
 
                echo allowreboot=${ALLOWREBOOT}\;;
44
 
        ) `
45
 
        if [ ! -z "${allowreboot}" -a "x${allowreboot}" = "xno" ]; then
46
 
                return
47
 
        fi
48
 
        if [ -f "${ve_root}/${REBOOT_MARK}" ]; then
49
 
                [ -z "${LOGFILE}" ] || echo "`date --iso-8601=seconds`  vereboot : VPS ${veid} : reboot " >> ${LOGFILE}
50
 
                /usr/sbin/vzctl start ${veid} >/dev/null 2>&1
51
 
        fi
52
 
}
53
 
 
54
 
function lockfile()
55
 
{
56
 
        local tmpfile="${LOCKFILE}.$$"
57
 
 
58
 
        echo $$ > ${tmpfile} 2> /dev/null || exit
59
 
 
60
 
        ln ${tmpfile} ${LOCKFILE} >& /dev/null && {
61
 
                rm -f ${tmpfile}
62
 
                return
63
 
        }
64
 
        kill -0 `cat $LOCKFILE` >& /dev/null && {
65
 
                rm -f ${tmpfile}
66
 
                exit
67
 
        }
68
 
        ln ${tmpfile} ${LOCKFILE} >& /dev/null && {
69
 
                rm -f ${tmpfile}
70
 
                return
71
 
        }
72
 
        rm -f ${LOCKFILE} ${tmpfile}
73
 
        exit
74
 
}
75
 
 
76
 
# If VZ is not running -- do nothing
77
 
# Fix for OpenVZ bug #107
78
 
test -f ${VE_INFO} || exit 0
79
 
lockfile
80
 
 
81
 
cd ${CONF_DIR} 2>/dev/null || exit 0 
82
 
VE_TOTAL=`ls -1 *.conf 2>/dev/null | sed s/.conf//`
83
 
VE_RUN=`cat ${VE_INFO} | awk '{
84
 
        if ($1 != 0) {
85
 
                if (i++)
86
 
                         printf("|");
87
 
                 printf("^%s$", $1);
88
 
        }
89
 
}'`
90
 
 
91
 
if [ -z "${VE_RUN}" ]; then
92
 
        VE_STOPPED="${VE_TOTAL}"
93
 
else
94
 
        VE_STOPPED=`echo -e "${VE_TOTAL}" | egrep -v "${VE_RUN}"`
95
 
fi
96
 
 
97
 
for i in ${VE_STOPPED}; do
98
 
        check_reboot ${i}
99
 
done
100
 
 
101
 
rm -f ${LOCKFILE}
102
 
exit 0