Skip to content

Commit a58da2c

Browse files
Merge branch 'BastilleBSD:master' into patch-2
2 parents 3c60a4b + f956254 commit a58da2c

File tree

9 files changed

+320
-105
lines changed

9 files changed

+320
-105
lines changed

docs/chapters/subcommands/mount.rst

+31-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,40 @@ To mount storage within the container use `bastille mount`.
66

77
.. code-block:: shell
88
9-
ishmael ~ # bastille mount azkaban /storage/foo /media/foo nullfs ro 0 0
9+
ishmael ~ # bastille mount azkaban /storage/foo media/foo nullfs ro 0 0
1010
[azkaban]:
11+
Added: /media/foo /usr/local/bastille/jails/azkaban/root/media/foo nullfs ro 0 0
12+
ishmael ~ # bastille mount azkaban /storage/bar /media/bar nullfs ro 0 0
13+
[azkaban]:
14+
Added: /media/bar /usr/local/bastille/jails/azkaban/root/media/bar nullfs ro 0 0
15+
16+
Notice the JAIL_PATH format can be /media/foo or simply media/bar. The leading slash / is optional. The HOST_PATH howerver, must be the full path including the leading slash /.
17+
18+
It is also possible to mount individual files into a jail as seen below.
19+
Bastille will not mount if a file is already present at the specified mount point.
20+
If you do not specify a file name, bastille will mount the file underneath the specified directory as seen in the second example below.
21+
22+
.. code-block:: shell
23+
24+
ishmael ~ # bastille mount azkaban /etc/rc.conf /mnt/etc/rc.conf nullfs ro 0 0
25+
[azkaban]:
26+
Added: /etc/rc.conf /usr/local/bastille/jails/azkaban/root/mnt/etc/rc.conf nullfs ro 0 0
27+
ishmael ~ # bastille mount azkaban /etc/rc.conf /media/bar nullfs ro 0 0
28+
[azkaban]:
29+
Added: /etc/rc.conf usr/local/bastille/jails/azkaban/root/media/bar/rc.conf nullfs ro 0 0
30+
31+
It is also possible (but not recommended) to have spaces in the directories that are mounted.
32+
It is necessary to escape each space with a backslash \ and enclose the mount point in quotes "" as seen below.
33+
It is possible to do the same for the jail path, but again, not recommemded.
34+
35+
.. code-block:: shell
36+
37+
ishmael ~ # bastille mount azkaban "/storage/my\ directory\ with\ spaces" /media/foo nullfs ro 0 0
38+
[azkaban]:
39+
Added: /storage/my\040directory\040with\040spaces /usr/local/bastille/jails/azkaban/root/media/foo nullfs ro 0 0
1140
1241
Syntax follows standard `/etc/fstab` format:
1342

1443
.. code-block:: shell
1544
16-
Usage: bastille mount TARGET host_path container_path [filesystem_type options dump pass_number]
45+
Usage: bastille mount TARGET HOST_PATH JAIL_PATH [filesystem_type options dump pass_number]

docs/chapters/subcommands/umount.rst

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@ To unmount storage from a container use `bastille umount`.
88
99
ishmael ~ # bastille umount azkaban /media/foo
1010
[azkaban]:
11+
Unmounted: /usr/local/bastille/jails/jail4/root/media/foo
12+
ishmael ~ # bastille umount azkaban /mnt/etc/rc.conf
13+
[azkaban]:
14+
Unmounted: /usr/local/bastille/jails/jail4/root/mnt/etc/rc.conf
15+
16+
Syntax requires only the jail path to unmount.
17+
18+
.. code-block:: shell
19+
20+
Usage: bastille umount TARGET JAIL_PATH
1121
12-
Syntax requires only the container path to unmount:
22+
If the directory you are unmounting has spaces, make sure to escape them with a backslash \, and enclode the mount point in quotes "".
1323

1424
.. code-block:: shell
1525
16-
Usage: bastille umount TARGET container_path
26+
ishmael ~ # bastille umount azkaban "/media/foo\ with\ spaces"
27+
[azkaban]:
28+
Unmounted: /usr/local/bastille/jails/jail4/root/media/foo with spaces

usr/local/bin/bastille

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ version|-v|--version)
157157
help|-h|--help)
158158
usage
159159
;;
160-
bootstrap|create|destroy|export|import|list|rdr|restart|setup|start|update|upgrade|verify)
160+
bootstrap|create|destroy|export|htop|import|list|mount|rdr|restart|setup|start|top|umount|update|upgrade|verify)
161161
# Nothing "extra" to do for these commands. -- cwells
162162
;;
163-
clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|service|stop|sysrc|tags|template|top|umount|zfs)
163+
clone|config|cmd|console|convert|cp|edit|limits|pkg|rcp|rename|service|stop|sysrc|tags|template|zfs)
164164
# Parse the target and ensure it exists. -- cwells
165165
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
166166
PARAMS='help'
@@ -205,7 +205,7 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic
205205
fi
206206

207207
case "${CMD}" in
208-
cmd|console|htop|pkg|service|stop|sysrc|template|top)
208+
cmd|console|pkg|service|stop|sysrc|template)
209209
check_target_is_running
210210
;;
211211
convert|rename)

usr/local/share/bastille/common.sh

+76-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

31+
# Source config file
32+
. /usr/local/etc/bastille/bastille.conf
33+
3134
COLOR_RED=
3235
COLOR_GREEN=
3336
COLOR_YELLOW=
@@ -51,11 +54,18 @@ if [ -z "${NO_COLOR}" ] && [ -t 1 ]; then
5154
enable_color
5255
fi
5356

54-
# Notify message on error, but do not exit
57+
# Error/Info functions
5558
error_notify() {
5659
echo -e "${COLOR_RED}$*${COLOR_RESET}" 1>&2
5760
}
5861

62+
error_continue() {
63+
error_notify "$@"
64+
# Disabling this shellcheck as we only ever call it inside of a loop
65+
# shellcheck disable=SC2104
66+
continue
67+
}
68+
5969
# Notify message on error and exit
6070
error_exit() {
6171
error_notify "$@"
@@ -70,6 +80,33 @@ warn() {
7080
echo -e "${COLOR_YELLOW}$*${COLOR_RESET}"
7181
}
7282

83+
check_target_exists() {
84+
local _TARGET="${1}"
85+
if [ ! -d "${bastille_jailsdir}"/"${_TARGET}" ]; then
86+
return 1
87+
else
88+
return 0
89+
fi
90+
}
91+
92+
check_target_is_running() {
93+
local _TARGET="${1}"
94+
if [ ! "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then
95+
return 1
96+
else
97+
return 0
98+
fi
99+
}
100+
101+
check_target_is_stopped() {
102+
local _TARGET="${1}"
103+
if [ "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then
104+
return 1
105+
else
106+
return 0
107+
fi
108+
}
109+
73110
generate_static_mac() {
74111
local jail_name="${1}"
75112
local external_interface="${2}"
@@ -136,6 +173,43 @@ EOF
136173
fi
137174
}
138175

176+
set_target() {
177+
local _TARGET="${1}"
178+
if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then
179+
target_all_jails
180+
else
181+
check_target_exists "${_TARGET}" || error_exit "Jail not found \"${_TARGET}\""
182+
JAILS="${_TARGET}"
183+
TARGET="${_TARGET}"
184+
export JAILS
185+
export TARGET
186+
fi
187+
}
188+
189+
set_target_single() {
190+
local _TARGET="${1}"
191+
if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then
192+
error_exit "[all|ALL] not supported with this command."
193+
else
194+
check_target_exists "${_TARGET}" || error_exit "Jail not found \"${_TARGET}\""
195+
JAILS="${_TARGET}"
196+
TARGET="${_TARGET}"
197+
export JAILS
198+
export TARGET
199+
fi
200+
}
201+
202+
target_all_jails() {
203+
local _JAILS="$(bastille list jails)"
204+
JAILS=""
205+
for _jail in ${_JAILS}; do
206+
if [ -d "${bastille_jailsdir}/${_jail}" ]; then
207+
JAILS="${JAILS} ${_jail}"
208+
fi
209+
done
210+
export JAILS
211+
}
212+
139213
checkyesno() {
140214
## copied from /etc/rc.subr -- cedwards (20231125)
141215
## issue #368 (lowercase values should be parsed)
@@ -156,3 +230,4 @@ checkyesno() {
156230
;;
157231
esac
158232
}
233+

usr/local/share/bastille/htop.sh

+45-18
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,56 @@
3232
. /usr/local/etc/bastille/bastille.conf
3333

3434
usage() {
35-
error_exit "Usage: bastille htop TARGET"
35+
error_exit "Usage: bastille htop [option(s)] TARGET"
36+
cat << EOF
37+
Options:
38+
39+
-f | --force -- Start the jail if it is stopped.
40+
41+
EOF
42+
exit 1
3643
}
3744

38-
# Handle special-case commands first.
39-
case "$1" in
40-
help|-h|--help)
41-
usage
42-
;;
43-
esac
45+
# Handle options.
46+
FORCE=0
47+
while [ "$#" -gt 0 ]; do
48+
case "${1}" in
49+
-h|--help|help)
50+
usage
51+
;;
52+
-f|--force)
53+
FORCE=1
54+
shift
55+
;;
56+
-*)
57+
error_exit "Unknown option: \"${1}\""
58+
;;
59+
*)
60+
break
61+
;;
62+
esac
63+
done
4464

45-
if [ $# -ne 0 ]; then
65+
if [ "$#" -ne 1 ]; then
4666
usage
4767
fi
4868

69+
TARGET="${1}"
70+
4971
bastille_root_check
72+
set_target_single "${TARGET}"
5073

51-
for _jail in ${JAILS}; do
52-
bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path)
53-
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
54-
error_notify "htop not found on ${_jail}."
55-
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
56-
info "[${_jail}]:"
57-
jexec -l ${_jail} /usr/local/bin/htop
58-
fi
59-
echo -e "${COLOR_RESET}"
60-
done
74+
info "[${TARGET}]:"
75+
check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then
76+
bastille start "${TARGET}"
77+
else
78+
error_notify "Jail is not running."
79+
error_continue "Use [-f|--force] to force start the jail."
80+
fi
81+
82+
bastille_jail_path="${bastille_jailsdir}/${TARGET}/root"
83+
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
84+
error_notify "htop not found on ${TARGET}."
85+
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
86+
jexec -l ${TARGET} /usr/local/bin/htop
87+
fi

0 commit comments

Comments
 (0)