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 # (C) Copyright Canonical 2011,2012
...@@ -41,30 +41,30 @@ dolxcstop() ...@@ -41,30 +41,30 @@ dolxcstop()
exit 0 exit 0
} }
shortoptions='hn:rwt:' usage_err() {
longoptions='help,name:,wait,reboot,timeout:' [ -n "$1" ] && echo "$1" >&2
timeout="-1"
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
if [ $? != 0 ]; then
usage usage
exit 1; exit 1
fi }
optarg_check() {
[ -n "$2" ] || usage_err "option '$1' requires an argument"
}
eval set -- "$getopt" timeout="-1"
reboot=0 reboot=0
dowait=0 dowait=0
while true; do while [ $# -gt 0 ]; do
case "$1" in opt="$1"
shift
case "$opt" in
-h|--help) -h|--help)
usage usage
exit 1
;; ;;
-n|--name) -n|--name)
shift optarg_check $opt "$1"
lxc_name=$1 lxc_name=$1
shift shift
;; ;;
...@@ -77,19 +77,23 @@ while true; do ...@@ -77,19 +77,23 @@ while true; do
shift shift
;; ;;
-t|--timeout) -t|--timeout)
shift optarg_check $opt "$1"
timeout=$1 timeout=$1
dowait=1 dowait=1
shift shift
;; ;;
--) --)
shift
break;; break;;
-?)
usage_err "unknown option '$opt'"
;;
-*)
# split opts -abc into -a -b -c
set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@"
;;
*) *)
echo $1 usage_err "unknown option '$opt'"
usage
exit 1 exit 1
;;
esac esac
done done
...@@ -104,8 +108,8 @@ if [ "$(id -u)" != "0" ]; then ...@@ -104,8 +108,8 @@ if [ "$(id -u)" != "0" ]; then
exit 1 exit 1
fi fi
type lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; } which 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-wait > /dev/null || { echo "lxc-wait not found."; exit 1; }
pid=`lxc-info -n $lxc_name -p 2>/dev/null | awk '{ print $2 }'` pid=`lxc-info -n $lxc_name -p 2>/dev/null | awk '{ print $2 }'`
if [ "$pid" = "-1" ]; then if [ "$pid" = "-1" ]; then
...@@ -114,10 +118,10 @@ if [ "$pid" = "-1" ]; then ...@@ -114,10 +118,10 @@ if [ "$pid" = "-1" ]; then
fi fi
if [ $reboot -eq 1 ]; then if [ $reboot -eq 1 ]; then
kill -INT $pid kill -s SIGINT $pid
exit 0 exit 0
else else
kill -PWR $pid kill -s SIGPWR $pid
fi fi
if [ $dowait -eq 0 ]; then 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