Bug #899 ยป startstopindividualjails.patch
etc/rc.d/jail 29 Dec 2007 08:33:51 -0000 | ||
---|---|---|
start_cmd="jail_start"
|
||
stop_cmd="jail_stop"
|
||
jail_start()
|
||
jail_config()
|
||
{
|
||
echo -n 'Configuring jails:'
|
||
echo -n ' set_hostname_allowed='
|
||
... | ... | |
${SYSCTL_W} 1>/dev/null jail.sysvipc_allowed=0
|
||
fi
|
||
echo '.'
|
||
}
|
||
jail_start()
|
||
{
|
||
jail_config
|
||
echo 'Starting Jails.'
|
||
for _jail in ${jail_list}
|
||
do
|
||
eval jail_rootdir=\"\$jail_${_jail}_rootdir\"
|
||
eval jail_hostname=\"\$jail_${_jail}_hostname\"
|
||
eval jail_ip=\"\$jail_${_jail}_ip\"
|
||
eval jail_exec=\"\$jail_${_jail}_exec\"
|
||
[ -z ${jail_exec} ] && jail_exec="/bin/sh /etc/rc"
|
||
|
||
jail ${jail_rootdir} ${jail_hostname} ${jail_ip} ${jail_exec}
|
||
jail_start_one "${_jail}"
|
||
done
|
||
}
|
||
... | ... | |
kill -TERM $(ps aux | awk '$8 ~ /.*J/ {print $2};')
|
||
}
|
||
jail_stop_one()
|
||
{
|
||
_jail=$1
|
||
eval jail_hostname=\"\$jail_${_jail}_hostname\"
|
||
echo "Stopping Jail ${_jail}."
|
||
jls | grep "${jail_hostname}" | cut -f1 | xargs -J A jexec A kill -TERM -1
|
||
}
|
||
jail_start_one()
|
||
{
|
||
_jail=$1
|
||
echo "Starting Jail ${_jail}."
|
||
eval jail_rootdir=\"\$jail_${_jail}_rootdir\"
|
||
eval jail_hostname=\"\$jail_${_jail}_hostname\"
|
||
eval jail_ip=\"\$jail_${_jail}_ip\"
|
||
eval jail_exec=\"\$jail_${_jail}_exec\"
|
||
[ -z ${jail_exec} ] && jail_exec="/bin/sh /etc/rc"
|
||
|
||
jail ${jail_rootdir} ${jail_hostname} ${jail_ip} ${jail_exec}
|
||
}
|
||
checkjailname()
|
||
{
|
||
_check=$1
|
||
for _jail in ${jail_list}
|
||
do
|
||
if [ "${_jail}" = "${_check}" ]; then
|
||
return 0
|
||
fi
|
||
done
|
||
return 1
|
||
}
|
||
run_jail_command()
|
||
{
|
||
_jail=$1
|
||
_cmd=$2
|
||
if [ "${_cmd}" = "start" ]; then
|
||
jail_config
|
||
jail_start_one "${_jail}"
|
||
return 0
|
||
fi
|
||
if [ "${_cmd}" = "stop" ]; then
|
||
jail_stop_one "${_jail}"
|
||
return 0
|
||
fi
|
||
if [ "${_cmd}" = "restart" ]; then
|
||
jail_stop_one "${_jail}"
|
||
jail_config
|
||
jail_start_one "${_jail}"
|
||
return 0
|
||
fi
|
||
echo "./jail: unknown directive '${_cmd}'."
|
||
echo "Usage: ./jail (start|stop|restart) (jailname)"
|
||
return 1
|
||
}
|
||
load_rc_config $name
|
||
run_rc_command "$1"
|
||
if [ -z "$2"]; then
|
||
run_rc_command "$1"
|
||
else
|
||
if checkjailname "$2"; then
|
||
run_jail_command "$2" "$1"
|
||
else
|
||
echo "Unknown jail: $2"
|
||
fi
|
||
fi
|