#! /bin/bash VERSION="0.3.0" VSERVER="/usr/sbin/vserver" usage () { cat <&2 usage: ${0##*/} s_context sys_call [arguments...] (see --help for more information) EOF } full_usage () { cat < This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. EOF } parse_args () { case "$1" in --help|-h) full_usage shift exit 0 ;; --version|-V) full_version shift exit 0 ;; [1-9]*) case "$2" in sys_reboot) case "$3" in restart) # hum, we can't exec() if we want to restart it... do_vserver_number "$1" kill do_vserver_number "$1" start return ;; halt) do_vserver_number "$1" kill return ;; *) echo "${0##*/} error: third argument must be an action." 1>&2 echo 'e.g. "restart" or "halt" (try --help)' 1>&2 shift 3 exit 1 ;; esac ;; sys_quotactl) echo "${0##*/} error: I know how to handle qutoas yet... :)" 1>&2 echo 'e.g. {the code needs writing!} (try --help)' 1>&2 shift 2 exit 1 ;; *) echo "${0##*/} error: second argument must be a handled sys_call." 1>&2 echo 'e.g. "sys_reboot" (try --help)' 1>&2 shift 2 exit 1 ;; esac ;; *) usage echo "${0##*/} error: first argument must be a non-zero s_context number" 1>&2 echo "e.g. 42" 1>&2 shift exit 1 ;; esac } # call this one with an s_context number do_vserver_number () { HOSTNAME=`grep -l "=$1" /var/run/vservers/* | sed -e 's/.*\/\(.*\).ctx/\1/;q'` # we can't exec() if we want to run another command to restart it... "$VSERVER" "$HOSTNAME" "$2" } parse_args $@