Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

top/htop: update auto-mode and documentation #804

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/chapters/subcommands/htop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
htop
====

This one runs `htop` inside the container.
note: won't work if you don't have htop installed in the container.
This command runs `htop` in the targeted jail.
Requires htop to be installed in the jail.


.. image:: ../../images/htop.png
Expand Down
2 changes: 1 addition & 1 deletion docs/chapters/subcommands/top.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
top
===

This one runs `top` in that container.
This command runs `top` in the targeted jail.


.. image:: ../../images/top.png
Expand Down
31 changes: 21 additions & 10 deletions usr/local/share/bastille/htop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,41 @@
. /usr/local/etc/bastille/bastille.conf

usage() {
error_exit "Usage: bastille htop [option(s)] TARGET"
error_notify "Usage: bastille htop [option(s)] TARGET"
cat << EOF
Options:

-f | --force -- Start the jail if it is stopped.
-a | --auto Auto mode. Start/stop jail(s) if required.
-x | --debug Enable debug mode.

EOF
exit 1
}

# Handle options.
FORCE=0
AUTO=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-f|--force)
FORCE=1
-a|--auto)
AUTO=1
shift
;;
-x|--debug)
enable_debug
shift
;;
-*)
error_exit "Unknown option: \"${1}\""
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
Expand All @@ -74,15 +86,14 @@ bastille_root_check
set_target_single "${TARGET}"

info "[${TARGET}]:"
check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then
check_target_is_running "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${TARGET}"
else
error_notify "Jail is not running."
error_continue "Use [-f|--force] to force start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi

bastille_jail_path="${bastille_jailsdir}/${TARGET}/root"
if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
if [ ! -x "${bastille_jailsdir}/${TARGET}/root/usr/local/bin/htop" ]; then
error_notify "htop not found on ${TARGET}."
elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then
jexec -l ${TARGET} /usr/local/bin/htop
Expand Down
26 changes: 19 additions & 7 deletions usr/local/share/bastille/top.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,37 @@ usage() {
cat << EOF
Options:

-f | --force -- Start the jail if it is stopped.
-a | --auto Auto mode. Start/stop jail(s) if required.
-x | --debug Enable debug mode.

EOF
exit 1
}

# Handle options.
FORCE=0
AUTO=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-f|--force)
FORCE=1
-a|--auto)
AUTO=1
shift
;;
-x|--debug)
enable_debug
shift
;;
-*)
error_exit "Unknown option: \"${1}\""
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
Expand All @@ -74,10 +86,10 @@ bastille_root_check
set_target_single "${TARGET}"

info "[${TARGET}]:"
check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then
check_target_is_running "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${TARGET}"
else
error_notify "Jail is not running."
error_continue "Use [-f|--force] to force start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
jexec -l "${TARGET}" /usr/bin/top