Merge pull request #869 from tschettervictor/master

Implement new functins for limits and tags
This commit is contained in:
tschettervictor
2025-02-23 12:19:10 -07:00
committed by GitHub
5 changed files with 118 additions and 38 deletions

View File

@@ -0,0 +1,17 @@
======
limits
======
Set resourse limits for targeted jail(s).
.. code-block:: shell
ishmael ~ # bastille limits help
Usage: bastille limits [option(s)] TARGET OPTION VALUE"
Example: bastille limits JAILNAME memoryuse 1G"
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
-x | --debug Enable debug mode.

View File

@@ -2,12 +2,22 @@
tags
====
The `tags` sub-command adds, removes or lists arbitrary tags on your containers.
The `tags` sub-command adds, removes or lists arbitrary tags on your jail(s).
.. code-block:: shell
ishmael ~ # bastille tags -h ## display tags help
ishmael ~ # bastille tags help ## display tags help
ishmael ~ # bastille tags TARGET add tag1,tag2 ## add the tags "tag1" and "tag2" to TARGET
ishmael ~ # bastille tags TARGET delete tag2 ## delete tag "tag2" from TARGET
ishmael ~ # bastille tags TARGET list ## list tags assigned to TARGET
ishmael ~ # bastille tags ALL list ## list tags from ALL containers
.. code-block:: shell
ishmael ~ # bastille tags help
Usage: bastille tags TARGET [add|delete|list] [tag1,tag2]
Options:
-x | --debug Enable debug mode.

View File

@@ -168,7 +168,7 @@ help|-h|--help)
bootstrap|clone|cmd|config|console|convert|create|cp|destroy|edit|etcupdate|export|htop|import|jcp|list|mount|pkg|rcp|rdr|rename|restart|service|setup|start|stop|sysrc|top|umount|update|upgrade|verify|zfs)
# Nothing "extra" to do for these commands. -- cwells
;;
limits|tags|template)
template)
# Parse the target and ensure it exists. -- cwells
if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells
PARAMS='help'

View File

@@ -35,36 +35,75 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_notify "Usage: bastille limits TARGET option value"
error_notify "Usage: bastille limits [option(s)] TARGET OPTION VALUE"
echo -e "Example: bastille limits JAILNAME memoryuse 1G"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
-x | --debug Enable debug mode.
EOF
exit 1
}
RACCT_ENABLE=$(sysctl -n kern.racct.enable)
if [ "${RACCT_ENABLE}" != '1' ]; then
echo "Racct not enabled. Append 'kern.racct.enable=1' to /boot/loader.conf and reboot"
# exit 1
# Handle options.
AUTO=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-a|--auto)
AUTO=1
shift
;;
-x|--debug)
enable_debug
shift
;;
-*)
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
case ${_opt} in
a) AUTO=1 ;;
x) enable_debug ;;
*) error_exit "Unknown Option: \"${1}\"" ;;
esac
done
shift
;;
*)
break
;;
esac
done
if [ $# -ne 3 ]; then
usage
fi
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
if [ $# -ne 2 ]; then
usage
TARGET="${1}"
OPTION="${2}"
VALUE="${3}"
RACCT_ENABLE="$(sysctl -n kern.racct.enable)"
if [ "${RACCT_ENABLE}" != '1' ]; then
error_exit "Racct not enabled. Append 'kern.racct.enable=1' to /boot/loader.conf and reboot"
fi
bastille_root_check
OPTION="${1}"
VALUE="${2}"
set_target "${TARGET}"
for _jail in ${JAILS}; do
info "[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${_jail}"
else
error_notify "Jail is not running."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
_rctl_rule="jail:${_jail}:${OPTION}:deny=${VALUE}/jail"
_rctl_rule_log="jail:${_jail}:${OPTION}:log=${VALUE}/jail"
@@ -80,5 +119,5 @@ for _jail in ${JAILS}; do
echo -e "${OPTION} ${VALUE}"
rctl -a "${_rctl_rule}" "${_rctl_rule_log}"
echo -e "${COLOR_RESET}"
done

View File

@@ -35,31 +35,45 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_notify "Usage: bastille tags TARGET add tag1[,tag2,...]"
error_notify " bastille tags TARGET delete tag1[,tag2,...]"
error_notify " bastille tags TARGET list [tag]"
echo -e "Example: bastille tags JAILNAME add database,mysql"
echo -e " bastille tags JAILNAME delete mysql"
echo -e " bastille tags ALL list"
echo -e " bastille tags ALL list mysql"
error_notify "Usage: bastille tags TARGET [add|delete|list] [tag1,tag2]"
cat << EOF
Options:
-x | --debug Enable debug mode.
EOF
exit 1
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
# Handle options.
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-x|--debug)
enable_debug
shift
;;
-*)
error_exit "Unknown Option: \"${1}\""
;;
*)
break
;;
esac
done
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
usage
fi
bastille_root_check
TARGET="${1}"
ACTION="${2}"
TAGS="${3}"
ACTION="${1}"
TAGS="${2}"
bastille_root_check
set_target "${TARGET}"
for _jail in ${JAILS}; do
bastille_jail_tags="${bastille_jailsdir}/${_jail}/tags"