startstopindividualjails.patch

kevin.kane, 12/29/2007 03:42 AM

Download (2.36 KB)

View differences:

etc/rc.d/jail 29 Dec 2007 08:33:51 -0000
15 15
start_cmd="jail_start"
16 16
stop_cmd="jail_stop"
17 17

  
18
jail_start()
18
jail_config()
19 19
{
20 20
	echo -n 'Configuring jails:'
21 21
	echo -n ' set_hostname_allowed='
......
45 45
		${SYSCTL_W} 1>/dev/null jail.sysvipc_allowed=0
46 46
	fi
47 47
	echo '.'
48
}
48 49

  
50
jail_start()
51
{
52
	jail_config	
49 53
	echo 'Starting Jails.'
50 54
	for _jail in ${jail_list} 
51 55
	do
52
		eval jail_rootdir=\"\$jail_${_jail}_rootdir\"
53
		eval jail_hostname=\"\$jail_${_jail}_hostname\"
54
		eval jail_ip=\"\$jail_${_jail}_ip\"
55
		eval jail_exec=\"\$jail_${_jail}_exec\"
56
		[ -z ${jail_exec} ] && jail_exec="/bin/sh /etc/rc"
57
		
58
		jail ${jail_rootdir} ${jail_hostname} ${jail_ip} ${jail_exec}
56
		jail_start_one "${_jail}"
59 57
	done
60 58
}
61 59

  
......
64 62
	kill -TERM $(ps aux | awk '$8 ~ /.*J/ {print  $2};')
65 63
}
66 64

  
65
jail_stop_one()
66
{
67
	_jail=$1
68
	eval jail_hostname=\"\$jail_${_jail}_hostname\"
69
	echo "Stopping Jail ${_jail}."
70
	jls | grep "${jail_hostname}" | cut -f1 | xargs -J A jexec A kill -TERM -1
71
}
72

  
73
jail_start_one()
74
{
75
	_jail=$1
76
	echo "Starting Jail ${_jail}."
77

  
78
	eval jail_rootdir=\"\$jail_${_jail}_rootdir\"
79
	eval jail_hostname=\"\$jail_${_jail}_hostname\"
80
	eval jail_ip=\"\$jail_${_jail}_ip\"
81
	eval jail_exec=\"\$jail_${_jail}_exec\"
82
	[ -z ${jail_exec} ] && jail_exec="/bin/sh /etc/rc"
83
		
84
	jail ${jail_rootdir} ${jail_hostname} ${jail_ip} ${jail_exec}
85
}
86

  
87
checkjailname()
88
{
89
	_check=$1
90
	for _jail in ${jail_list} 
91
	do
92
		if [ "${_jail}" = "${_check}" ]; then
93
			return 0
94
		fi
95
	done
96
	return 1
97
}
98

  
99
run_jail_command()
100
{
101
	_jail=$1
102
	_cmd=$2
103

  
104
	if [ "${_cmd}" = "start" ]; then
105
		jail_config
106
		jail_start_one "${_jail}"
107
		return 0
108
	fi
109

  
110
	if [ "${_cmd}" = "stop" ]; then
111
		jail_stop_one "${_jail}"
112
		return 0
113
	fi
114

  
115
	if [ "${_cmd}" = "restart" ]; then
116
		jail_stop_one "${_jail}"
117
		jail_config
118
		jail_start_one "${_jail}"
119
		return 0
120
	fi
121

  
122
	echo "./jail: unknown directive '${_cmd}'."
123
	echo "Usage: ./jail (start|stop|restart) (jailname)"
124
	return 1
125
}
67 126

  
68 127
load_rc_config $name
69
run_rc_command "$1"
128
if [ -z "$2"]; then
129
	run_rc_command "$1"
130
else
131
	if checkjailname "$2"; then
132
		run_jail_command "$2" "$1"
133
	else
134
		echo "Unknown jail: $2"
135
	fi
136
fi