Commit 600faead by Natanael Copa Committed by Stéphane Graber

lxc-shutdown: use posix shell instead of bash

- avoid getopt --longoptions - use 'which' instead of 'type' to detect existance of tools - specify -s SIG<signame> with kill Signed-off-by: 's avatarNatanael Copa <ncopa@alpinelinux.org> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 4415d516
#!/bin/bash
#!/bin/sh
# (C) Copyright Canonical 2011,2012
......@@ -41,30 +41,30 @@ dolxcstop()
exit 0
}
shortoptions='hn:rwt:'
longoptions='help,name:,wait,reboot,timeout:'
timeout="-1"
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
if [ $? != 0 ]; then
usage_err() {
[ -n "$1" ] && echo "$1" >&2
usage
exit 1;
fi
exit 1
}
optarg_check() {
[ -n "$2" ] || usage_err "option '$1' requires an argument"
}
eval set -- "$getopt"
timeout="-1"
reboot=0
dowait=0
while true; do
case "$1" in
while [ $# -gt 0 ]; do
opt="$1"
shift
case "$opt" in
-h|--help)
usage
exit 1
;;
-n|--name)
shift
optarg_check $opt "$1"
lxc_name=$1
shift
;;
......@@ -77,19 +77,23 @@ while true; do
shift
;;
-t|--timeout)
shift
optarg_check $opt "$1"
timeout=$1
dowait=1
shift
;;
--)
shift
break;;
-?)
usage_err "unknown option '$opt'"
;;
-*)
# split opts -abc into -a -b -c
set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
;;
*)
echo $1
usage
usage_err "unknown option '$opt'"
exit 1
;;
esac
done
......@@ -104,8 +108,8 @@ if [ "$(id -u)" != "0" ]; then
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; }
which lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; }
which 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
......@@ -114,10 +118,10 @@ if [ "$pid" = "-1" ]; then
fi
if [ $reboot -eq 1 ]; then
kill -INT $pid
kill -s SIGINT $pid
exit 0
else
kill -PWR $pid
kill -s SIGPWR $pid
fi
if [ $dowait -eq 0 ]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment