60 lines
2.3 KiB
Bash
Executable file
60 lines
2.3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: $0 <subcommand> [options]
|
|
Subcommands:
|
|
init <jailname> Init jail <jailname>
|
|
update <jailname>|all Update jail <jailname> or all
|
|
remove <jailname>|all Remove jail <jailname> or all
|
|
start <jailname>|all Start jail <jailname> or all
|
|
stop <jailname>|all Stop jail <jailname> or all
|
|
reload <jailname>|all Reload jail <jailname> or all
|
|
restart <jailname>|all Restart jail <jailname> or all
|
|
sync <jailname>|all Sync jail <jailname> or all to another node
|
|
firewall <jailname>|all Update firewall rules of <jailname> or all
|
|
status [<jailname>] Print status of <jailname> (default all jail)
|
|
key <jailname> [<keyfile>] Set or get ssh pubic key of <jailname>
|
|
port <jailname> [<port>|auto] Set or get ssh port of <jailname>
|
|
ip <jailname> [<ip>|all] Set or get allowed(s) ip(s) of <jailname>
|
|
inc Make incremental inc of all jails
|
|
rm Remove old incremtal inc of all jails
|
|
check Run check on jails (NRPE output)
|
|
stats Make and display stats on jails (size, lastconn)
|
|
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
check_jail() {
|
|
jail="${1}"
|
|
[ -d "${JAILDIR}/${jail}" ] && return 0
|
|
return 1
|
|
}
|
|
|
|
check_jail_on() {
|
|
jail="${1}"
|
|
return=1
|
|
if [ -f "${JAILDIR}/${jail}/${SSHD_PID}" ]; then
|
|
pid=$(cat "${JAILDIR}/${jail}/${SSHD_PID}")
|
|
ps -p "${pid}" > /dev/null && return=0
|
|
fi
|
|
if [ "${return}" -eq 1 ]; then
|
|
rm -f "${JAILDIR}/${jail}/${SSHD_PID}"
|
|
grep -q "${JAILDIR}/${jail}/proc" /proc/mounts && umount --lazy "${JAILDIR}/${jail}/proc/"
|
|
grep -q "${JAILDIR}/${jail}/dev" /proc/mounts && umount --lazy --recursive "${JAILDIR}/${jail}/dev"
|
|
fi
|
|
return "${return}"
|
|
}
|
|
|
|
get_inc() {
|
|
jail="${1}"
|
|
inc="0"
|
|
if [ -f "${CONFDIR}/${jail}" ]; then
|
|
day=$(grep -c "day" "${CONFDIR}/${jail}")
|
|
month=$(grep -c "month" "${CONFDIR}/${jail}")
|
|
inc="${day}/${month}"
|
|
fi
|
|
echo "${inc}"
|
|
}
|