This file is indexed.

/usr/bin/lxc-shutdown is in lxc 0.7.5-3ubuntu52.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash

# (C) Copyright Canonical 2011,2012

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

set -e

usage() {
    echo "usage: lxc-shutdown -n name [-w] [-r]"
    echo "  Cleanly shut down a container."
    echo "  -w: wait for shutdown to complete."
    echo "  -r: reboot (ignore -w)."
    echo "  -t timeout: wait at most timeout seconds (implies -w), then kill"
    echo "              the container."
}

alarm() {
    pid=$1
    timeout=$2
    sleep $timeout
    kill $pid
}

dolxcstop()
{
    echo "Calling lxc-stop on $lxc_name"
    lxc-stop -n $lxc_name
    exit 0
}

shortoptions='hn:rwt:'
longoptions='help,name:,wait,reboot,timeout:'

timeout="-1"

getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
if [ $? != 0 ]; then
    usage
    exit 1;
fi

eval set -- "$getopt"

reboot=0
dowait=0

while true; do
    case "$1" in
    -h|--help)
        usage
        exit 1
        ;;
    -n|--name)
        shift
        lxc_name=$1
        shift
        ;;
    -w|--wait)
        dowait=1
        shift
        ;;
    -r|--reboot)
        reboot=1
        shift
        ;;
    -t|--timeout)
        shift
        timeout=$1
        dowait=1
        shift
        ;;
    --)
        shift
        break;;
    *)
        echo $1
        usage
        exit 1
        ;;
    esac
done

if [ -z "$lxc_name" ]; then
    echo "no container name specified"
    usage
    exit 1
fi

if [ "$(id -u)" != "0" ]; then
   echo "This command has to be run as root"
   exit 1
fi

type lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; }
type lxc-wait > /dev/null || { echo "lxc-wait not found."; exit 1; }

pid=`lxc-info -n $lxc_name -p 2>/dev/null | awk '{ print $2 }'`
if [ "$pid" = "-1" ]; then
    echo "$lxc_name is not running"
    exit 1
fi

if [ $reboot -eq 1 ]; then
    kill -INT $pid
    exit 0
else
    kill -PWR $pid
fi

if [ $dowait -eq 0 ]; then
    exit 0
fi

if [ $timeout != "-1" ]; then
    trap dolxcstop EXIT
    alarm $$ $timeout &
    alarmpid=$!
fi

while [ 1 ]; do
    s=`lxc-info -s -n $lxc_name | awk '{ print $2 }'`
    if [ "$s" = "STOPPED" ]; then
        break;
    fi
    sleep 1
done

if [ $timeout != "-1" ]; then
    kill $alarmpid
fi

echo "Container $lxc_name has shut down"

exit 0