#!/bin/bash
# sys/h4 - Host management helper
set -e
source "/home/zwelch/src/mcf/mcsh-release/install/share/mcsh/mcsh.sh"
######
# Native dependencies
h4_client_packages=( iotop iftop )
######
# Host Monitoring CLI
h4_monitor() { cmd_dispatch "$@"; }
h4_monitor_usage() {
cat <<USAGE
<cmd>
Host Monitoring Commands:
all Monitors everything in a new screen
users Monitors users
disk Monitors disk space
tasks Monitors processes
Resource Monitoring Commands:
cpu ... Monitors CPU usage
io ... Monitors I/O usage
net ... Monitors network usage
USAGE
}
h4_monitor_all() {
lib_load 'sys/tool/screen'
screen_run_func h4_monitor_all_screenrc
}
h4_monitor_all_screenrc() {
local -a cmd=( "${script[@]:0:$((${#script[@]} - 1))}" )
local i
for i in users tasks cpu disk io net; do
screen_gen_run "${cmd[@]}" $i
done
}
h4_monitor_users() { run watch 'w'; }
h4_monitor_disk() { run watch 'df -h'; }
h4_monitor_tasks() { run watch 'pstree -u'; }
h4_monitor_cpu() { run top "$@"; }
h4_monitor_io() { run_sudo iotop "$@"; }
h4_monitor_net() { run_sudo iftop "$@"; }
######
# Host CLI
h4_host() { cmd_dispatch "$@"; }
h4_host_usage() {
cat <<USAGE
<cmd> ...
Host Commands:
upgrade Performs a host-wide upgrade
run ... Run each tool with the given args
Host Command Groups:
client ... Runs client command with each tool
server ... Runs server command with each tool
backup ... Run backup on all tools
restore ... Run restore for all tools
USAGE
}
h4_host_run() { run_each_tool "$@"; }
h4_host_upgrade() {
lib_load 'sys/tool/apt'
apt_upgrade
}
h4_host_client() {
lib_load 'sys/client'
cmd_dispatch "$@"
}
h4_host_client_deps() { host_class_deps client; }
h4_host_client_install() { host_class_install client; }
h4_host_server() {
lib_load 'sys/server'
cmd_dispatch "$@"
}
h4_host_server_deps() { host_class_deps server; }
h4_host_server_install() { host_class_install server; }
######
# Backup CLI
h4_host_backup() {
lib_load 'sys/backup'
cmd_dispatch "$@"
}
h4_host_backup_usage() {
cat <<USAGE
<cmd>
Host Backup Commands:
full ... Run backup on all tools
USAGE
}
h4_host_backup_full() { backup_host full; }
h4_host_restore() {
lib_load 'sys/backup'
cmd_dispatch "$@"
}
h4_host_restore_usage() {
cat <<USAGE
<cmd>
Host Restore Commands:
full ... Run full restore on all tools
USAGE
}
h4_host_restore_full() { restore_host full; }
######
# Main
h4_desc() { echo "Host management helper"; }
h4_usage() {
cat <<USAGE
<cmd> ...
Host Command Groups:
host ... Host management commands
monitor ... Host monitoring commands
USAGE
}
app_run "$@"
Generated on Fri Jul 28 14:34:43 PDT 2017 by mcsh d14 v0.23.0.