mirror of
https://github.com/m8tin/cis.git
synced 2026-08-01 11:47:31 +02:00
Added composition.printAllSyncingHosts() to remove hard coded file dependencies and renamed composition-sync-hosts to zfssync-hosts
This commit is contained in:
@@ -61,6 +61,22 @@ function composition.printAllSyncedByThisHost() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# composition.printAllSyncingHosts
|
||||||
|
#
|
||||||
|
# This function prints the name of all hosts the given composition is syncted to.
|
||||||
|
function composition.printAllSyncingHosts() {
|
||||||
|
local _COMPOSITION _SYNCHOSTS_FILE
|
||||||
|
_COMPOSITION="${1:?"composition.printAllSyncingHosts(): Missing first parameter COMPOSITION"}"
|
||||||
|
_SYNCHOSTS_FILE="${CIS[COMPOSITIONS]:?"composition.printAllSyncingHosts(): Missing CIS_COMPOSITIONS"}${_COMPOSITION}/zfssync-hosts"
|
||||||
|
readonly _COMPOSITION _SYNCHOSTS_FILE
|
||||||
|
|
||||||
|
[ -f "${_SYNCHOSTS_FILE}" ] \
|
||||||
|
&& cat "${_SYNCHOSTS_FILE}" \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# composition.printZFS
|
# composition.printZFS
|
||||||
# - COMPOSITION mandatory: "uptime-kuma-prod"
|
# - COMPOSITION mandatory: "uptime-kuma-prod"
|
||||||
#
|
#
|
||||||
@@ -114,7 +130,7 @@ function composition.shouldRunOnThisHost() {
|
|||||||
# - HOST mandatory: "server.your-domain.net"
|
# - HOST mandatory: "server.your-domain.net"
|
||||||
#
|
#
|
||||||
# This function checks if the given composition is or should be synced to the given host.
|
# This function checks if the given composition is or should be synced to the given host.
|
||||||
# Therefore a file 'composition-sync-hosts' defines a list of host, one per line, where the composition should be synced to.
|
# Therefore a file 'zfssync-hosts' defines a list of host, one per line, where the composition should be synced to.
|
||||||
# The given host either runs the composition or syncs it.
|
# The given host either runs the composition or syncs it.
|
||||||
function composition.shouldBeSyncedByGivenHost() {
|
function composition.shouldBeSyncedByGivenHost() {
|
||||||
local _COMPOSITION _HOST _COMPOSITION_PATH _RUNNINGHOST_FILE _SYNCHOSTS_FILE
|
local _COMPOSITION _HOST _COMPOSITION_PATH _RUNNINGHOST_FILE _SYNCHOSTS_FILE
|
||||||
@@ -122,7 +138,7 @@ function composition.shouldBeSyncedByGivenHost() {
|
|||||||
_HOST="${2:?"composition.shouldBeSyncedByGivenHost(): Missing second parameter HOST"}"
|
_HOST="${2:?"composition.shouldBeSyncedByGivenHost(): Missing second parameter HOST"}"
|
||||||
_COMPOSITION_PATH="${CIS[COMPOSITIONS]:?"composition.shouldBeSyncedByGivenHost(): Missing CIS_COMPOSITIONS"}${_COMPOSITION}/"
|
_COMPOSITION_PATH="${CIS[COMPOSITIONS]:?"composition.shouldBeSyncedByGivenHost(): Missing CIS_COMPOSITIONS"}${_COMPOSITION}/"
|
||||||
_RUNNINGHOST_FILE="${_COMPOSITION_PATH}running-host"
|
_RUNNINGHOST_FILE="${_COMPOSITION_PATH}running-host"
|
||||||
_SYNCHOSTS_FILE="${_COMPOSITION_PATH}composition-sync-hosts"
|
_SYNCHOSTS_FILE="${_COMPOSITION_PATH}zfssync-hosts"
|
||||||
readonly _COMPOSITION _HOST _COMPOSITION_PATH _RUNNINGHOST_FILE _SYNCHOSTS_FILE
|
readonly _COMPOSITION _HOST _COMPOSITION_PATH _RUNNINGHOST_FILE _SYNCHOSTS_FILE
|
||||||
|
|
||||||
# This host either runs the composition or syncs it.
|
# This host either runs the composition or syncs it.
|
||||||
|
|||||||
@@ -10,10 +10,9 @@ base.loadModule composition
|
|||||||
|
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
local _COMPOSITION _COMPOSITIONS_FOLDER _SYNC_HOSTS_FILE
|
local _COMPOSITION _COMPOSITIONS_FOLDER
|
||||||
_COMPOSITION="${1}"
|
_COMPOSITION="${1}"
|
||||||
_COMPOSITIONS_FOLDER="${CIS[DOMAINDEFINITIONS]}compositions/"
|
_COMPOSITIONS_FOLDER="${CIS[DOMAINDEFINITIONS]}compositions/"
|
||||||
_SYNC_HOSTS_FILE="${_COMPOSITIONS_FOLDER}${_COMPOSITION}/composition-sync-hosts"
|
|
||||||
readonly _COMPOSITION _COMPOSITIONS_FOLDER
|
readonly _COMPOSITION _COMPOSITIONS_FOLDER
|
||||||
|
|
||||||
echo "Setup the host that receives the composition of others ..."
|
echo "Setup the host that receives the composition of others ..."
|
||||||
@@ -21,7 +20,7 @@ function setup() {
|
|||||||
echo "No folder for your defined composition settings found: ${_COMPOSITIONS_FOLDER}"
|
echo "No folder for your defined composition settings found: ${_COMPOSITIONS_FOLDER}"
|
||||||
echo "Please create it and add your custom composition settings in there, following this convention:"
|
echo "Please create it and add your custom composition settings in there, following this convention:"
|
||||||
echo " 1.) './NAME_OF_THE_COMPOSITION/running-host' containing one line with the FQDN of the host running the composition."
|
echo " 1.) './NAME_OF_THE_COMPOSITION/running-host' containing one line with the FQDN of the host running the composition."
|
||||||
echo " 2.) './NAME_OF_THE_COMPOSITION/composition-sync-hosts' containing a list of hosts receiving the composition, one host with its FQDN per line."
|
echo " 2.) './NAME_OF_THE_COMPOSITION/zfssync-hosts' containing a list of hosts receiving the composition, one host with its FQDN per line."
|
||||||
echo
|
echo
|
||||||
|
|
||||||
[ -d "${_COMPOSITIONS_FOLDER}" ] \
|
[ -d "${_COMPOSITIONS_FOLDER}" ] \
|
||||||
@@ -34,9 +33,8 @@ function setup() {
|
|||||||
&& echo
|
&& echo
|
||||||
|
|
||||||
[ -n "${_COMPOSITION}" ] \
|
[ -n "${_COMPOSITION}" ] \
|
||||||
&& [ -f "${_SYNC_HOSTS_FILE}" ] \
|
|
||||||
&& echo "Following hosts should sync the ZFS of this composition '${COMPOSITION}':" \
|
&& echo "Following hosts should sync the ZFS of this composition '${COMPOSITION}':" \
|
||||||
&& cat "${_SYNC_HOSTS_FILE}" \
|
&& composition.printAllSyncingHosts "${_COMPOSITION}" \
|
||||||
&& echo
|
&& echo
|
||||||
|
|
||||||
echo "Optionally you can create following file:"
|
echo "Optionally you can create following file:"
|
||||||
|
|||||||
@@ -207,9 +207,9 @@ function receiveOnceSingle() {
|
|||||||
function usage() {
|
function usage() {
|
||||||
echo
|
echo
|
||||||
echo 'Commands:'
|
echo 'Commands:'
|
||||||
echo ' --loopAll : This will start one screen session per composition ("composition-sync-hosts"),'
|
echo ' --loopAll : This will start one screen session per composition ("zfssync-hosts"),'
|
||||||
echo ' and run the sync process in an endless loop.'
|
echo ' and run the sync process in an endless loop.'
|
||||||
echo ' --onceAll : This will run the sync process once for each composition ("composition-sync-hosts").'
|
echo ' --onceAll : This will run the sync process once for each composition ("zfssync-hosts").'
|
||||||
echo ' e.g.: you can use it in crontab as a daily backup.'
|
echo ' e.g.: you can use it in crontab as a daily backup.'
|
||||||
echo ' --loopSingle COMPOSITION : This will run the sync process in an endless loop but just for the specified COMPOSITION.'
|
echo ' --loopSingle COMPOSITION : This will run the sync process in an endless loop but just for the specified COMPOSITION.'
|
||||||
echo ' --onceSingle COMPOSITION : This will run the sync process once just for the specified COMPOSITION.'
|
echo ' --onceSingle COMPOSITION : This will run the sync process once just for the specified COMPOSITION.'
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
source /cis/core/base.module.sh
|
source /cis/core/base.module.sh
|
||||||
|
base.loadModule composition
|
||||||
base.loadModule ssh
|
base.loadModule ssh
|
||||||
|
|
||||||
|
|
||||||
@@ -51,12 +52,12 @@ function checkSync() {
|
|||||||
local _COMPOSITION_PATH
|
local _COMPOSITION_PATH
|
||||||
for _COMPOSITION_PATH in "${CIS[COMPOSITIONS]}"*; do
|
for _COMPOSITION_PATH in "${CIS[COMPOSITIONS]}"*; do
|
||||||
|
|
||||||
|
local _COMPOSITION_NAME="${_COMPOSITION_PATH##*/}" #Removes longest matching pattern '*/' from the begin
|
||||||
|
|
||||||
# If remote host is found than it is responsible for this container-composition, otherwise skip
|
# If remote host is found than it is responsible for this container-composition, otherwise skip
|
||||||
# (grep -E "^[[:blank:]]*something" means. Line has to start with "something", leading blank chars are ok.)
|
composition.shouldBeSyncedByGivenHost "${_COMPOSITION_NAME}" "${_REMOTE_HOSTNAME_FQDN}" \
|
||||||
grep -E "^[[:blank:]]*${_REMOTE_HOSTNAME_SHORT}" "${_COMPOSITION_PATH}/composition-sync-hosts" &> /dev/null \
|
|
||||||
|| continue;
|
|| continue;
|
||||||
|
|
||||||
local _COMPOSITION_NAME="${_COMPOSITION_PATH##*/}" #Removes longest matching pattern '*/' from the begin
|
|
||||||
local _LAST_SNAPSHOT_UNIXTIME="$(echo "${_SNAPSHOTS}" | grep ${_COMPOSITION_NAME} | tail -n 1 | cut -d' ' -f1)"
|
local _LAST_SNAPSHOT_UNIXTIME="$(echo "${_SNAPSHOTS}" | grep ${_COMPOSITION_NAME} | tail -n 1 | cut -d' ' -f1)"
|
||||||
local _SECONDS_BEHIND=$[ ${_NOW_UTC_UNIXTIME} - ${_LAST_SNAPSHOT_UNIXTIME} ]
|
local _SECONDS_BEHIND=$[ ${_NOW_UTC_UNIXTIME} - ${_LAST_SNAPSHOT_UNIXTIME} ]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user