From 2f68e21a96a5a09fd6b99512cdf73b2e00b5458c Mon Sep 17 00:00:00 2001 From: Jake Guffey Date: Sun, 5 Jun 2016 21:57:21 -0400 Subject: [PATCH 1/6] Add support for FreeBSD 10.x jails Separate __jail type into distinct __jail_freebsd9 and __jail_freebsd10 types --- cdist/conf/type/__jail/manifest | 13 + .../explorer/basepresent | 0 .../explorer/present | 0 .../explorer/status | 0 .../conf/type/__jail_freebsd10/gencode-local | 52 +++ .../conf/type/__jail_freebsd10/gencode-remote | 362 ++++++++++++++++++ cdist/conf/type/__jail_freebsd10/man.text | 119 ++++++ .../type/__jail_freebsd10/parameter/boolean | 3 + .../parameter/default/devfs-ruleset | 1 + .../parameter/default/jailbase | 1 + .../parameter/default/jaildir | 1 + .../__jail_freebsd10/parameter/default/state | 1 + .../type/__jail_freebsd10/parameter/optional | 8 + .../type/__jail_freebsd9/explorer/basepresent | 54 +++ .../type/__jail_freebsd9/explorer/present | 43 +++ .../conf/type/__jail_freebsd9/explorer/status | 52 +++ .../{__jail => __jail_freebsd9}/gencode-local | 0 .../gencode-remote | 7 +- cdist/conf/type/__jail_freebsd9/man.text | 120 ++++++ .../type/__jail_freebsd9/parameter/boolean | 3 + .../parameter/default/devfs-ruleset | 1 + .../parameter/default/jailbase | 1 + .../__jail_freebsd9/parameter/default/jaildir | 1 + .../__jail_freebsd9/parameter/default/state | 1 + .../type/__jail_freebsd9/parameter/optional | 8 + cdist/conf/type/__package/parameter/boolean | 1 + cdist/conf/type/__package/parameter/optional | 1 + 27 files changed, 851 insertions(+), 3 deletions(-) rename cdist/conf/type/{__jail => __jail_freebsd10}/explorer/basepresent (100%) rename cdist/conf/type/{__jail => __jail_freebsd10}/explorer/present (100%) rename cdist/conf/type/{__jail => __jail_freebsd10}/explorer/status (100%) create mode 100755 cdist/conf/type/__jail_freebsd10/gencode-local create mode 100755 cdist/conf/type/__jail_freebsd10/gencode-remote create mode 100644 cdist/conf/type/__jail_freebsd10/man.text create mode 100644 cdist/conf/type/__jail_freebsd10/parameter/boolean create mode 100644 cdist/conf/type/__jail_freebsd10/parameter/default/devfs-ruleset create mode 100644 cdist/conf/type/__jail_freebsd10/parameter/default/jailbase create mode 100644 cdist/conf/type/__jail_freebsd10/parameter/default/jaildir create mode 100644 cdist/conf/type/__jail_freebsd10/parameter/default/state create mode 100644 cdist/conf/type/__jail_freebsd10/parameter/optional create mode 100755 cdist/conf/type/__jail_freebsd9/explorer/basepresent create mode 100755 cdist/conf/type/__jail_freebsd9/explorer/present create mode 100755 cdist/conf/type/__jail_freebsd9/explorer/status rename cdist/conf/type/{__jail => __jail_freebsd9}/gencode-local (100%) rename cdist/conf/type/{__jail => __jail_freebsd9}/gencode-remote (98%) create mode 100644 cdist/conf/type/__jail_freebsd9/man.text create mode 100644 cdist/conf/type/__jail_freebsd9/parameter/boolean create mode 100644 cdist/conf/type/__jail_freebsd9/parameter/default/devfs-ruleset create mode 100644 cdist/conf/type/__jail_freebsd9/parameter/default/jailbase create mode 100644 cdist/conf/type/__jail_freebsd9/parameter/default/jaildir create mode 100644 cdist/conf/type/__jail_freebsd9/parameter/default/state create mode 100644 cdist/conf/type/__jail_freebsd9/parameter/optional create mode 100644 cdist/conf/type/__package/parameter/boolean diff --git a/cdist/conf/type/__jail/manifest b/cdist/conf/type/__jail/manifest index 2d29e263..6df52c59 100755 --- a/cdist/conf/type/__jail/manifest +++ b/cdist/conf/type/__jail/manifest @@ -37,6 +37,19 @@ jaildir="$(cat "$__object/parameter/jaildir")" __directory ${jaildir} --parents +set -- "$@" "$__object_id" "--state" "$state" +cd "$__object/parameter" +for property in $(ls .); do + set -- "$@" "--$property" "$(cat "$property")" +done + +ver="$(cat "$__global/explorer/os_version")" +if [ -n "$(echo "$ver" | grep '^10\.' )" ]; then # Version is 10.x + __jail_freebsd10 "$@" +else + __jail_freebsd9 "$@" +fi + # Debug #set +x diff --git a/cdist/conf/type/__jail/explorer/basepresent b/cdist/conf/type/__jail_freebsd10/explorer/basepresent similarity index 100% rename from cdist/conf/type/__jail/explorer/basepresent rename to cdist/conf/type/__jail_freebsd10/explorer/basepresent diff --git a/cdist/conf/type/__jail/explorer/present b/cdist/conf/type/__jail_freebsd10/explorer/present similarity index 100% rename from cdist/conf/type/__jail/explorer/present rename to cdist/conf/type/__jail_freebsd10/explorer/present diff --git a/cdist/conf/type/__jail/explorer/status b/cdist/conf/type/__jail_freebsd10/explorer/status similarity index 100% rename from cdist/conf/type/__jail/explorer/status rename to cdist/conf/type/__jail_freebsd10/explorer/status diff --git a/cdist/conf/type/__jail_freebsd10/gencode-local b/cdist/conf/type/__jail_freebsd10/gencode-local new file mode 100755 index 00000000..a88e8ae4 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/gencode-local @@ -0,0 +1,52 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# The __jail type creates, configures, and deletes FreeBSD jails for use as +# virtual machines. +# + +# Debug +exec >&2 +set -x + +jaildir="$(cat "$__object/parameter/jaildir")" + +jailbase="$(cat "$__object/parameter/jailbase")" + +state="$(cat "$__object/parameter/state")" + +if [ "$state" = "present" ] && [ -z "$jailbase" ]; then + exec >&2 + echo "jailbase is a REQUIRED parameter when state=present!" + exit 1 +fi + +remotebase="${jaildir}/jailbase.tgz" +basepresent="$(cat "$__object/explorer/basepresent")" + +if [ "$state" = "present" ]; then + if [ "$basepresent" = "NONE" ]; then + echo "$__remote_copy" "${jailbase}" "$__target_host:${remotebase}" + fi # basepresent=NONE +fi # state=present + +# Debug +set +x + diff --git a/cdist/conf/type/__jail_freebsd10/gencode-remote b/cdist/conf/type/__jail_freebsd10/gencode-remote new file mode 100755 index 00000000..ae68616d --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/gencode-remote @@ -0,0 +1,362 @@ +#!/bin/sh +# +# 2012,2014,2016 Jake Guffey (jake.guffey at jointheirstm.org) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# The __jail_freebsd10 type creates, configures, and deletes FreeBSD +# jails for use as virtual machines on FreeBSD 10.x. +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +state="$(cat "$__object/parameter/state")" + +started="true" +# If the user wants the jail gone, it implies it shouldn't be started. +[ -f "$__object/parameter/stopped" -o "$state" = "absent" ] && started="false" + +if [ -f "$__object/parameter/ip" ]; then + ip="$(cat "$__object/parameter/ip")" +else +# IP is an optional param when $state=absent, but +# when $state=present, it's required. Enforce this. + if [ "$state" = "present" ]; then + exec >&2 + echo "If --state is 'present,' --ip must be given\!" + exit 1 + fi +fi + +if [ -f "$__object/parameter/hostname" ]; then + hostname="$(cat "$__object/parameter/hostname")" +else + hostname="$name" +fi + +if [ -f "$__object/parameter/devfs-disable" ]; then + devfsenable="false" +else + devfsenable="true" +fi + +devfsruleset="$(cat "$__object/parameter/devfs-ruleset")" + +# devfs_ruleset being defined without devfs_enable being true +# is pointless. Treat this as an error. +if [ -n "$devfsruleset" -a "$devfsenable" = "false" ]; then + exec >&2 + echo "Can't have --devfs-ruleset defined with --devfs-disable" + exit 1 +fi + +if [ -f "$__object/parameter/onboot" ]; then + onboot="true" +fi + +jaildir="$(cat "$__object/parameter/jaildir")" + +present="$(cat "$__object/explorer/present")" +#present="$(cat "$__type/explorer/present")" +status="$(cat "$__object/explorer/status")" + +# Handle ip="addr, addr" format +if [ $(expr "${ip}" : ".*, .*") -gt "0" ]; then + SAVE_IFS="$IFS" + IFS=", " + for cur_ip in ${ip}; do + # Just get the last IP address for SSH to listen on + mgmt_ip=$(echo "${ip}" | cut '-d ' -f1) # In case using "ip netmask" format rather than CIDR + done + IFS="$SAVE_IFS" +else + mgmt_ip=$(echo "${ip}" | cut '-d ' -f1) # In case using "ip netmask" format rather than CIDR +fi + +stopJail() { +# Check $status before issuing command + if [ "$status" = "STARTED" ]; then + echo "/etc/rc.d/jail stop ${name}" + echo "stop" >> "$__messages_out" + fi +} + +startJail() { +# Check $status before issuing command + if [ "$status" = "NOTSTART" ]; then + echo "/etc/rc.d/jail start ${name}" + echo "start" >> "$__messages_out" + fi +} + +deleteJail() { +# Unmount the jail's mountpoints if necessary + cat <=1 rw mount is mounted still + for DIR in "${output}"; do + umount -F "/etc/fstab.${name}" "\$(echo "${DIR}" | awk '{print $3}')" + done + fi + output="\$(mount | grep "\/${name} (")" || true + if [ -n "\${output}" ]; then # ro mount is mounted still + umount -F "/etc/fstab.${name}" "\$(echo "${output}" | awk '{print $3}')" + fi +EOF +# Remove the jail's rw mountpoints + echo "rm -rf \"${jaildir}/rw/${name}\"" +# Remove the jail directory + echo "rm -rf \"${jaildir}/${name}\"" +# Remove the jail's fstab + echo "rm -f \"/etc/fstab.${name}\"" +# Remove jail entry from jail.conf + cat <> "$__messages_out" +} + +createJail() { +# Create the jail directory +cat <> "$__messages_out" + +# Create the ro+rw mountpoint entries in fstab +cat </etc/fstab.${name} <>/etc/rc.conf + elif [ ! "\$(echo \$jail_enable | tr '[a-z]' '[A-Z]' | tr -d '"')" = "YES" ]; then # jail_enable="NO" + sed -i '.bak' 's/^jail_enable=.*$/jail_enable="YES"/g' /etc/rc.conf # fix this -^ + rm -f /etc/rc.conf.bak + fi + + jailfile=/etc/jail.conf + jailheader="${name} {" + + jaildata="path=\"${jaildir}/${name}\";" + + if [ "$devfsenable" = "true" ]; then + jaildata="\$jaildata + mount.devfs;" + else + jaildata="\$jaildata + mount.nodevfs;" + fi + + jaildata="\$jaildata + host.hostname=\"${hostname}\"; + ip4.addr=\"${ip}\"; + exec.start=\"/bin/sh /etc/rc\"; + exec.stop=\"/bin/sh /etc/rc.shutdown\"; + exec.consolelog=\"/var/log/jail_${name}_console.log\"; + mount.fstab=\"/etc/fstab.${name}\"; + allow.mount; + exec.clean; + allow.set_hostname=0; + allow.sysvipc=0; + allow.raw_sockets=0;" + + jailtrailer="}" + + if [ "$devfsenable" = "true" ] && [ "${devfsruleset}" = "jailrules" ]; then # The default ruleset is to be used + if [ ! -f /etc/devfs.rules ]; then + touch /etc/devfs.rules + fi + if [ -z "\$(grep '\[jailrules=' /etc/devfs.rules)" ]; then # The default ruleset doesn't exist + # Get the highest-numbered ruleset + highest="\$(sed -n 's/\[.*=\([0-9]*\)\]/\1/pg' /etc/devfs.rules | sort -u | tail -n 1)" || true + # increment by 1 + [ -z "\$highest" ] && highest=10 + let num="\${highest}+1" 2>&1 >/dev/null # Close the FD==fail... + # add default ruleset + cat >>/etc/devfs.rules <>\"\$jailfile\"" + +# Add $name to jail_list if $onboot=yes +if [ "$onboot" = "yes" ]; then + + # first check to see whether jail_enable="YES" exists in rc.conf or not and add it + # if necessary + + cat <> "$__messages_out" +fi + +# Add the normal entries into the jail's rc.conf +cat <"${jaildir}/rw/${name}/etc/rc.conf" +echo sshd_enable=\"YES\" >>"${jaildir}/rw/${name}/etc/rc.conf" +echo sendmail_enable=\"NONE\" >>"${jaildir}/rw/${name}/etc/rc.conf" +echo syslogd_enable=\"YES\" >>"${jaildir}/rw/${name}/etc/rc.conf" +echo syslogd_flags=\"-ss\" >>"${jaildir}/rw/${name}/etc/rc.conf" + +EOF +# Configure SSHd's listening address +cat < + + +NAME +---- +cdist-type__jail_freebsd_10 - Manage FreeBSD jails + + +DESCRIPTION +----------- +This type is used on FreeBSD 10.x to manage jails. + + +REQUIRED PARAMETERS +------------------- +state:: + Either "present" or "absent", defaults to "present". + +jailbase:: + The location of the .tgz archive containing the base fs for your jails. + + +OPTIONAL PARAMETERS +------------------- +name:: + The name of the jail. Default is to use the object_id as the jail name. + +ip:: + The ifconfig style IP/netmask combination to use for the jail guest. If + the state parameter is "present," this parameter is required. + +hostname:: + The FQDN to use for the jail guest. Defaults to the name parameter. + +interface:: + The name of the physical interface on the jail server to bind the jail to. + Defaults to the first interface found in the output of ifconfig -l. + +devfs-ruleset:: + The name of the devfs ruleset to associate with the jail. Defaults to + "jailrules." This ruleset must be copied to the server via another type. + To use this option, devfs-enable must be "true." + +jaildir:: + The location on the remote server to use for hosting jail filesystems. + Defaults to /usr/jail. + +BOOLEAN PARAMETERS +------------------ +stopped:: + Do not start the jail + +devfs-disable:: + Whether to disallow devfs mounting within the jail + +onboot:: + Whether to add the jail to rc.conf's jail_list variable. + + +CAVEATS +------- +This type does not currently support modification of jail options. If, for +example a jail needs to have its IP address or netmask changed, the jail must +be removed then re-added with the correct IP address/netmask or the appropriate +modifications to jail.conf need to be made through alternate means. + +MESSAGES +-------- +start:: + The jail was started +stop:: + The jail was stopped +create: + The jail was created +delete:: + The jail was deleted +onboot:: + The jail was configured to start on boot + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Create a jail called www +__jail_freebsd_10 www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz + +# Remove the jail called www +__jail_freebsd_10 www --state absent --jailbase /my/jail/base.tgz + +# The jail www should not be started +__jail_freebsd_10 www --state present --stopped \ + --ip "192.168.1.2 netmask 255.255.255.0" \ + --jailbase /my/jail/base.tgz + +# Use the name variable explicitly +__jail_freebsd_10 thisjail --state present --name www \ + --ip "192.168.1.2" \ + --jailbase /my/jail/base.tgz + +# Go nuts +__jail_freebsd_10 lotsofoptions --state present --name testjail \ + --ip "192.168.1.100 netmask 255.255.255.0" \ + --hostname "testjail.example.com" --interface "em0" \ + --onboot --jailbase /my/jail/base.tgz --jaildir /jails +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__jail(7) + + +COPYING +------- +Copyright \(C) 2012-2016 Jake Guffey. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__jail_freebsd10/parameter/boolean b/cdist/conf/type/__jail_freebsd10/parameter/boolean new file mode 100644 index 00000000..39144f6f --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/parameter/boolean @@ -0,0 +1,3 @@ +onboot +stopped +devfs-disable diff --git a/cdist/conf/type/__jail_freebsd10/parameter/default/devfs-ruleset b/cdist/conf/type/__jail_freebsd10/parameter/default/devfs-ruleset new file mode 100644 index 00000000..f602aa0a --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/parameter/default/devfs-ruleset @@ -0,0 +1 @@ +jailrules diff --git a/cdist/conf/type/__jail_freebsd10/parameter/default/jailbase b/cdist/conf/type/__jail_freebsd10/parameter/default/jailbase new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/parameter/default/jailbase @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__jail_freebsd10/parameter/default/jaildir b/cdist/conf/type/__jail_freebsd10/parameter/default/jaildir new file mode 100644 index 00000000..ec7d86c6 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/parameter/default/jaildir @@ -0,0 +1 @@ +/usr/jail diff --git a/cdist/conf/type/__jail_freebsd10/parameter/default/state b/cdist/conf/type/__jail_freebsd10/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__jail_freebsd10/parameter/optional b/cdist/conf/type/__jail_freebsd10/parameter/optional new file mode 100644 index 00000000..b36f0fa5 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd10/parameter/optional @@ -0,0 +1,8 @@ +name +ip +hostname +interface +devfs-ruleset +jaildir +jailbase +state diff --git a/cdist/conf/type/__jail_freebsd9/explorer/basepresent b/cdist/conf/type/__jail_freebsd9/explorer/basepresent new file mode 100755 index 00000000..034128d5 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/explorer/basepresent @@ -0,0 +1,54 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# See if the jailbase.tgz or $jaildir/base dir exists +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/jaildir")" +else + jaildir="/usr/jail" +fi + +name="base:jailbase.tgz" +out="" + +save_IFS="$IFS" +IFS=":" +for cur in $name; do + if [ -e "${jaildir}/$cur" ]; then + out="${out}:${cur}" + fi +done +IFS="$save_IFS" + +if [ -z "$out" ]; then + echo "NONE" +else + echo "${out}" +fi + +# Debug +#set +x + diff --git a/cdist/conf/type/__jail_freebsd9/explorer/present b/cdist/conf/type/__jail_freebsd9/explorer/present new file mode 100755 index 00000000..ddfb805c --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/explorer/present @@ -0,0 +1,43 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# See if the requested jail exists +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name=$__object_id +fi + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/jaildir")" +else + jaildir="/usr/jail" +fi + +[ -d "${jaildir}/$name" ] && echo "EXISTS" || echo "NOTEXIST" + +#set +x + diff --git a/cdist/conf/type/__jail_freebsd9/explorer/status b/cdist/conf/type/__jail_freebsd9/explorer/status new file mode 100755 index 00000000..1ceba212 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/explorer/status @@ -0,0 +1,52 @@ +#!/bin/sh +# +# 2012 Jake Guffey (jake.guffey at eprotex.com) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# See if the requested jail is started +# + +# Debug +#exec >&2 +#set -x + +if [ -f "$__object/parameter/name" ]; then + name="$(cat "$__object/parameter/name")" +else + name="$__object_id" +fi + +if [ -f "$__object/parameter/jaildir" ]; then + jaildir="$(cat "$__object/parameter/jaildir")" +else + jaildir="/usr/jail" +fi +# backslash-escaped $jaildir +sjaildir="$(echo ${jaildir} | sed 's#/#\\/#g')" + +jls_output="$(jls | grep "[ ]${sjaildir}\/${name}\$")" || true + +if [ -n "${jls_output}" ]; then + echo "STARTED" +else + echo "NOTSTART" +fi + +# Debug +#set +x + diff --git a/cdist/conf/type/__jail/gencode-local b/cdist/conf/type/__jail_freebsd9/gencode-local similarity index 100% rename from cdist/conf/type/__jail/gencode-local rename to cdist/conf/type/__jail_freebsd9/gencode-local diff --git a/cdist/conf/type/__jail/gencode-remote b/cdist/conf/type/__jail_freebsd9/gencode-remote similarity index 98% rename from cdist/conf/type/__jail/gencode-remote rename to cdist/conf/type/__jail_freebsd9/gencode-remote index c88f3361..6a4c64de 100755 --- a/cdist/conf/type/__jail/gencode-remote +++ b/cdist/conf/type/__jail_freebsd9/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2012,2014 Jake Guffey (jake.guffey at eprotex.com) +# 2012,2014,2016 Jake Guffey (jake.guffey at jointheirstm.org) # # This file is part of cdist. # @@ -18,8 +18,8 @@ # along with cdist. If not, see . # # -# The __jail type creates, configures, and deletes FreeBSD jails for use as -# virtual machines. +# The __jail_freebsd9 type creates, configures, and deletes FreeBSD jails +# for use as virtual machines on FreeBSD 9.x and before. # # Debug @@ -354,3 +354,4 @@ else # The jail does not currently exist exit 0 fi fi + diff --git a/cdist/conf/type/__jail_freebsd9/man.text b/cdist/conf/type/__jail_freebsd9/man.text new file mode 100644 index 00000000..c51f326d --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/man.text @@ -0,0 +1,120 @@ +cdist-type__jail_freebsd9(7) +============================ +Jake Guffey + + +NAME +---- +cdist-type__jail_freebsd9 - Manage FreeBSD jails + + +DESCRIPTION +----------- +This type is used on FreeBSD 9.x and before to manage jails. + + +REQUIRED PARAMETERS +------------------- +state:: + Either "present" or "absent", defaults to "present". + +jailbase:: + The location of the .tgz archive containing the base fs for your jails. + + +OPTIONAL PARAMETERS +------------------- +name:: + The name of the jail. Default is to use the object_id as the jail name. + +ip:: + The ifconfig style IP/netmask combination to use for the jail guest. If + the state parameter is "present," this parameter is required. + +hostname:: + The FQDN to use for the jail guest. Defaults to the name parameter. + +interface:: + The name of the physical interface on the jail server to bind the jail to. + Defaults to the first interface found in the output of ifconfig -l. + +devfs-ruleset:: + The name of the devfs ruleset to associate with the jail. Defaults to + "jailrules." This ruleset must be copied to the server via another type. + To use this option, devfs-enable must be "true." + +jaildir:: + The location on the remote server to use for hosting jail filesystems. + Defaults to /usr/jail. + +BOOLEAN PARAMETERS +------------------ +stopped:: + Do not start the jail + +devfs-disable:: + Whether to disallow devfs mounting within the jail + +onboot:: + Whether to add the jail to rc.conf's jail_list variable. + + +CAVEATS +------- +This type does not currently support modification of jail options. If, for +example a jail needs to have its IP address or netmask changed, the jail must +be removed then re-added with the correct IP address/netmask or the appropriate +line (jail__ip="...") modified within rc.conf through some alternate +means. + +MESSAGES +-------- +start:: + The jail was started +stop:: + The jail was stopped +create: + The jail was created +delete:: + The jail was deleted +onboot:: + The jail was configured to start on boot + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Create a jail called www +__jail_freebsd9 www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz + +# Remove the jail called www +__jail_freebsd9 www --state absent --jailbase /my/jail/base.tgz + +# The jail www should not be started +__jail_freebsd9 www --state present --stopped \ + --ip "192.168.1.2 netmask 255.255.255.0" \ + --jailbase /my/jail/base.tgz + +# Use the name variable explicitly +__jail_freebsd9 thisjail --state present --name www \ + --ip "192.168.1.2" \ + --jailbase /my/jail/base.tgz + +# Go nuts +__jail_freebsd9 lotsofoptions --state present --name testjail \ + --ip "192.168.1.100 netmask 255.255.255.0" \ + --hostname "testjail.example.com" --interface "em0" \ + --onboot --jailbase /my/jail/base.tgz --jaildir /jails +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) +- cdist-type__jail + + +COPYING +------- +Copyright \(C) 2012-2016 Jake Guffey. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__jail_freebsd9/parameter/boolean b/cdist/conf/type/__jail_freebsd9/parameter/boolean new file mode 100644 index 00000000..39144f6f --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/parameter/boolean @@ -0,0 +1,3 @@ +onboot +stopped +devfs-disable diff --git a/cdist/conf/type/__jail_freebsd9/parameter/default/devfs-ruleset b/cdist/conf/type/__jail_freebsd9/parameter/default/devfs-ruleset new file mode 100644 index 00000000..f602aa0a --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/parameter/default/devfs-ruleset @@ -0,0 +1 @@ +jailrules diff --git a/cdist/conf/type/__jail_freebsd9/parameter/default/jailbase b/cdist/conf/type/__jail_freebsd9/parameter/default/jailbase new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/parameter/default/jailbase @@ -0,0 +1 @@ + diff --git a/cdist/conf/type/__jail_freebsd9/parameter/default/jaildir b/cdist/conf/type/__jail_freebsd9/parameter/default/jaildir new file mode 100644 index 00000000..ec7d86c6 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/parameter/default/jaildir @@ -0,0 +1 @@ +/usr/jail diff --git a/cdist/conf/type/__jail_freebsd9/parameter/default/state b/cdist/conf/type/__jail_freebsd9/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__jail_freebsd9/parameter/optional b/cdist/conf/type/__jail_freebsd9/parameter/optional new file mode 100644 index 00000000..b36f0fa5 --- /dev/null +++ b/cdist/conf/type/__jail_freebsd9/parameter/optional @@ -0,0 +1,8 @@ +name +ip +hostname +interface +devfs-ruleset +jaildir +jailbase +state diff --git a/cdist/conf/type/__package/parameter/boolean b/cdist/conf/type/__package/parameter/boolean new file mode 100644 index 00000000..effcb218 --- /dev/null +++ b/cdist/conf/type/__package/parameter/boolean @@ -0,0 +1 @@ +upgrade diff --git a/cdist/conf/type/__package/parameter/optional b/cdist/conf/type/__package/parameter/optional index d674f32e..bb3f5154 100644 --- a/cdist/conf/type/__package/parameter/optional +++ b/cdist/conf/type/__package/parameter/optional @@ -4,3 +4,4 @@ type pkgsite state ptype +repo From bcd4e5f29b96f4e9e486533fc5b645680a6cc46d Mon Sep 17 00:00:00 2001 From: Jake Guffey Date: Sun, 5 Jun 2016 21:57:56 -0400 Subject: [PATCH 2/6] Removed debugging from __jail_freebsd10/gencode-local --- cdist/conf/type/__jail_freebsd10/gencode-local | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__jail_freebsd10/gencode-local b/cdist/conf/type/__jail_freebsd10/gencode-local index a88e8ae4..d4b89730 100755 --- a/cdist/conf/type/__jail_freebsd10/gencode-local +++ b/cdist/conf/type/__jail_freebsd10/gencode-local @@ -23,8 +23,8 @@ # # Debug -exec >&2 -set -x +#exec >&2 +#set -x jaildir="$(cat "$__object/parameter/jaildir")" @@ -48,5 +48,5 @@ if [ "$state" = "present" ]; then fi # state=present # Debug -set +x +#set +x From bcd5e9827b2d887e31b1e2a12b1b8b40b077ee15 Mon Sep 17 00:00:00 2001 From: Jake Guffey Date: Sun, 5 Jun 2016 22:16:42 -0400 Subject: [PATCH 3/6] Fix man pages Migrate (re-migrate) from text -> rst and update docs to reflect new developments --- cdist/conf/type/__jail/man.rst | 6 +- .../__jail_freebsd10/{man.text => man.rst} | 84 +++++++++---------- .../__jail_freebsd9/{man.text => man.rst} | 80 +++++++++--------- 3 files changed, 81 insertions(+), 89 deletions(-) rename cdist/conf/type/__jail_freebsd10/{man.text => man.rst} (59%) rename cdist/conf/type/__jail_freebsd9/{man.text => man.rst} (60%) diff --git a/cdist/conf/type/__jail/man.rst b/cdist/conf/type/__jail/man.rst index 38ec4f96..826dce21 100644 --- a/cdist/conf/type/__jail/man.rst +++ b/cdist/conf/type/__jail/man.rst @@ -2,12 +2,12 @@ cdist-type__jail(7) =================== Manage FreeBSD jails -Jake Guffey +Jake Guffey DESCRIPTION ----------- -This type is used on FreeBSD to manage jails. +This type is used on FreeBSD to manage jails by calling the appropriate per-version subtype. REQUIRED PARAMETERS @@ -112,5 +112,5 @@ SEE ALSO COPYING ------- -Copyright \(C) 2012 Jake Guffey. Free use of this software is +Copyright \(C) 2012,2016 Jake Guffey. Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__jail_freebsd10/man.text b/cdist/conf/type/__jail_freebsd10/man.rst similarity index 59% rename from cdist/conf/type/__jail_freebsd10/man.text rename to cdist/conf/type/__jail_freebsd10/man.rst index b5df9d5d..7e167549 100644 --- a/cdist/conf/type/__jail_freebsd10/man.text +++ b/cdist/conf/type/__jail_freebsd10/man.rst @@ -1,61 +1,58 @@ -cdist-type__jail_freebsd_10(7) -============================== +cdist-type__jail_freebsd10(7) +============================= +Manage FreeBSD jails + Jake Guffey -NAME ----- -cdist-type__jail_freebsd_10 - Manage FreeBSD jails - - DESCRIPTION ----------- -This type is used on FreeBSD 10.x to manage jails. +This type is used on FreeBSD >= 10.0 to manage jails. REQUIRED PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present". -jailbase:: +jailbase The location of the .tgz archive containing the base fs for your jails. OPTIONAL PARAMETERS ------------------- -name:: +name The name of the jail. Default is to use the object_id as the jail name. -ip:: +ip The ifconfig style IP/netmask combination to use for the jail guest. If the state parameter is "present," this parameter is required. -hostname:: +hostname The FQDN to use for the jail guest. Defaults to the name parameter. -interface:: +interface The name of the physical interface on the jail server to bind the jail to. Defaults to the first interface found in the output of ifconfig -l. -devfs-ruleset:: +devfs-ruleset The name of the devfs ruleset to associate with the jail. Defaults to "jailrules." This ruleset must be copied to the server via another type. To use this option, devfs-enable must be "true." -jaildir:: +jaildir The location on the remote server to use for hosting jail filesystems. Defaults to /usr/jail. BOOLEAN PARAMETERS ------------------ -stopped:: +stopped Do not start the jail -devfs-disable:: +devfs-disable Whether to disallow devfs mounting within the jail -onboot:: +onboot Whether to add the jail to rc.conf's jail_list variable. @@ -68,49 +65,48 @@ modifications to jail.conf need to be made through alternate means. MESSAGES -------- -start:: +start The jail was started -stop:: +stop The jail was stopped create: The jail was created -delete:: +delete The jail was deleted -onboot:: +onboot The jail was configured to start on boot EXAMPLES -------- --------------------------------------------------------------------------------- -# Create a jail called www -__jail_freebsd_10 www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz +.. code-block:: sh -# Remove the jail called www -__jail_freebsd_10 www --state absent --jailbase /my/jail/base.tgz + # Create a jail called www + __jail_freebsd10 www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz -# The jail www should not be started -__jail_freebsd_10 www --state present --stopped \ - --ip "192.168.1.2 netmask 255.255.255.0" \ - --jailbase /my/jail/base.tgz + # Remove the jail called www + __jail_freebsd10 www --state absent --jailbase /my/jail/base.tgz -# Use the name variable explicitly -__jail_freebsd_10 thisjail --state present --name www \ - --ip "192.168.1.2" \ - --jailbase /my/jail/base.tgz + # The jail www should not be started + __jail_freebsd10 www --state present --stopped \ + --ip "192.168.1.2 netmask 255.255.255.0" \ + --jailbase /my/jail/base.tgz -# Go nuts -__jail_freebsd_10 lotsofoptions --state present --name testjail \ - --ip "192.168.1.100 netmask 255.255.255.0" \ - --hostname "testjail.example.com" --interface "em0" \ - --onboot --jailbase /my/jail/base.tgz --jaildir /jails --------------------------------------------------------------------------------- + # Use the name variable explicitly + __jail_freebsd10 thisjail --state present --name www \ + --ip "192.168.1.2" \ + --jailbase /my/jail/base.tgz + + # Go nuts + __jail_freebsd10 lotsofoptions --state present --name testjail \ + --ip "192.168.1.100 netmask 255.255.255.0" \ + --hostname "testjail.example.com" --interface "em0" \ + --onboot --jailbase /my/jail/base.tgz --jaildir /jails SEE ALSO -------- -- cdist-type(7) -- cdist-type__jail(7) +- `cdist-type(7) `_ COPYING diff --git a/cdist/conf/type/__jail_freebsd9/man.text b/cdist/conf/type/__jail_freebsd9/man.rst similarity index 60% rename from cdist/conf/type/__jail_freebsd9/man.text rename to cdist/conf/type/__jail_freebsd9/man.rst index c51f326d..1fe20186 100644 --- a/cdist/conf/type/__jail_freebsd9/man.text +++ b/cdist/conf/type/__jail_freebsd9/man.rst @@ -1,61 +1,58 @@ cdist-type__jail_freebsd9(7) ============================ -Jake Guffey +Manage FreeBSD jails - -NAME ----- -cdist-type__jail_freebsd9 - Manage FreeBSD jails +Jake Guffey DESCRIPTION ----------- -This type is used on FreeBSD 9.x and before to manage jails. +This type is used on FreeBSD <= 9.x to manage jails. REQUIRED PARAMETERS ------------------- -state:: +state Either "present" or "absent", defaults to "present". -jailbase:: +jailbase The location of the .tgz archive containing the base fs for your jails. OPTIONAL PARAMETERS ------------------- -name:: +name The name of the jail. Default is to use the object_id as the jail name. -ip:: +ip The ifconfig style IP/netmask combination to use for the jail guest. If the state parameter is "present," this parameter is required. -hostname:: +hostname The FQDN to use for the jail guest. Defaults to the name parameter. -interface:: +interface The name of the physical interface on the jail server to bind the jail to. Defaults to the first interface found in the output of ifconfig -l. -devfs-ruleset:: +devfs-ruleset The name of the devfs ruleset to associate with the jail. Defaults to "jailrules." This ruleset must be copied to the server via another type. To use this option, devfs-enable must be "true." -jaildir:: +jaildir The location on the remote server to use for hosting jail filesystems. Defaults to /usr/jail. BOOLEAN PARAMETERS ------------------ -stopped:: +stopped Do not start the jail -devfs-disable:: +devfs-disable Whether to disallow devfs mounting within the jail -onboot:: +onboot Whether to add the jail to rc.conf's jail_list variable. @@ -69,49 +66,48 @@ means. MESSAGES -------- -start:: +start The jail was started -stop:: +stop The jail was stopped create: The jail was created -delete:: +delete The jail was deleted -onboot:: +onboot The jail was configured to start on boot EXAMPLES -------- --------------------------------------------------------------------------------- -# Create a jail called www -__jail_freebsd9 www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz +.. code-block:: sh -# Remove the jail called www -__jail_freebsd9 www --state absent --jailbase /my/jail/base.tgz + # Create a jail called www + __jail_freebsd9 www --state present --ip "192.168.1.2" --jailbase /my/jail/base.tgz -# The jail www should not be started -__jail_freebsd9 www --state present --stopped \ - --ip "192.168.1.2 netmask 255.255.255.0" \ - --jailbase /my/jail/base.tgz + # Remove the jail called www + __jail_freebsd9 www --state absent --jailbase /my/jail/base.tgz -# Use the name variable explicitly -__jail_freebsd9 thisjail --state present --name www \ - --ip "192.168.1.2" \ - --jailbase /my/jail/base.tgz + # The jail www should not be started + __jail_freebsd9 www --state present --stopped \ + --ip "192.168.1.2 netmask 255.255.255.0" \ + --jailbase /my/jail/base.tgz -# Go nuts -__jail_freebsd9 lotsofoptions --state present --name testjail \ - --ip "192.168.1.100 netmask 255.255.255.0" \ - --hostname "testjail.example.com" --interface "em0" \ - --onboot --jailbase /my/jail/base.tgz --jaildir /jails --------------------------------------------------------------------------------- + # Use the name variable explicitly + __jail_freebsd9 thisjail --state present --name www \ + --ip "192.168.1.2" \ + --jailbase /my/jail/base.tgz + + # Go nuts + __jail_freebsd9 lotsofoptions --state present --name testjail \ + --ip "192.168.1.100 netmask 255.255.255.0" \ + --hostname "testjail.example.com" --interface "em0" \ + --onboot --jailbase /my/jail/base.tgz --jaildir /jails SEE ALSO -------- -- cdist-type(7) -- cdist-type__jail +- `cdist-type(7) `_ COPYING From d2e5fa7167c981e6a3bdd66eb123732581a41da5 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 6 Jun 2016 18:39:24 +0200 Subject: [PATCH 4/6] Add some thoughts about improving speed --- docs/2016-06-06.org | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 docs/2016-06-06.org diff --git a/docs/2016-06-06.org b/docs/2016-06-06.org new file mode 100644 index 00000000..8e3624a8 --- /dev/null +++ b/docs/2016-06-06.org @@ -0,0 +1,7 @@ +* Enhance cdist speed +** Start separate server with own option +** Reconfigure normal sshd with appropriate options +** Start various own daemons +** Use custom multiplexing protocol +** Support native Python code +*** Use manifest.py instead of manifest if available From 35bf9aeaa5930383eee9ed58ac7eb07ecb12217b Mon Sep 17 00:00:00 2001 From: Jake Guffey Date: Mon, 6 Jun 2016 18:01:14 -0400 Subject: [PATCH 5/6] Updated changelog for jail types --- docs/changelog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/changelog b/docs/changelog index dada1d90..9d95c1ea 100644 --- a/docs/changelog +++ b/docs/changelog @@ -1,6 +1,11 @@ Changelog --------- +4.1.1: 2016-06-06 + * New type: __jail_freebsd9: Handle jail management on FreeBSD <= 9.X (Jake Guffey) + * New type: __jail_freebsd10: Handle jail management on FreeBSD >= 10.0 (Jake Guffey) + * Type __jail: Dynamically select the correct jail subtype based on target host OS (Jake Guffey) + 4.1.0: 2016-05-27 * Documentation: Migrate to reStructuredText format and sphinx (Darko Poljak) * Core: Add -f option to read additional hosts from file/stdin (Darko Poljak) From e6d439f2e984fab61594c12d346e21c2c5373f6d Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sun, 12 Jun 2016 20:51:14 +0200 Subject: [PATCH 6/6] Fix changelog: 'next'. --- docs/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog b/docs/changelog index 9d95c1ea..8ad8e953 100644 --- a/docs/changelog +++ b/docs/changelog @@ -1,7 +1,7 @@ Changelog --------- -4.1.1: 2016-06-06 +next: * New type: __jail_freebsd9: Handle jail management on FreeBSD <= 9.X (Jake Guffey) * New type: __jail_freebsd10: Handle jail management on FreeBSD >= 10.0 (Jake Guffey) * Type __jail: Dynamically select the correct jail subtype based on target host OS (Jake Guffey)