SHORTNAME=${0##*/}
usemsg() {
- echo "Usage: $1 name action"
- echo "where name is the name of a config file or the network"
- echo "namespace name and action is one of start | stop | reload."
+ echo "Usage: $1 name start|stop|restart|exec cmd [arg ...]"
+ echo " where name is the name of a config file or a network namespace name,"
+ echo " and cmd is a command to execute in the context of an existing namespace."
}
if [ $# -lt 2 ]; then
/bin/rmdir $RUNDIR
}
+# Run a specified command inside a network namespace:
+run_nns() {
+ if ! exist_nns $1 ; then
+ echo "Network namespace $1 does not exist,"
+ echo "please choose another name"
+ exit 1
+ fi
+ NNS=$1
+ shift
+ # Run the specified command inside the namespace:
+ $IP netns exec $NNS su -p -c "$*" $SUDO_USER &
+}
+
case $2 in
start)
start_nns $NNSNAME
;;
run|exec)
- echo "TO-DO: implement '$SHORTNAME run <command>' action."
+ shift
+ shift
+ run_nns $NNSNAME "$@"
;;
*)
usemsg $SHORTNAME