diff --git a/.DS_Store b/.DS_Store index 6b8af04..14c3e62 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/sodew-bash-main/README.md b/sodew-bash-main/README.md index 7a1e533..835fa50 100644 --- a/sodew-bash-main/README.md +++ b/sodew-bash-main/README.md @@ -1,4 +1,4 @@ -# KUBE 7.1.553 +# KUBE 7.0.539 Bash script for deploying/backups and restore SODEW infrastructures. diff --git a/sodew-bash-main/assets/k3s/templates/openlitespeed.yaml b/sodew-bash-main/assets/k3s/templates/openlitespeed.yaml index efe423c..115f3f0 100644 --- a/sodew-bash-main/assets/k3s/templates/openlitespeed.yaml +++ b/sodew-bash-main/assets/k3s/templates/openlitespeed.yaml @@ -22,50 +22,6 @@ spec: resources: { requests: { storage: 500Gi } } storageClassName: "" ---- -apiVersion: v1 -kind: PersistentVolume -metadata: { name: "{{ .Values.openlitespeed }}-private-pv" } -spec: - capacity: { storage: 5Gi } - volumeMode: Filesystem - accessModes: [ ReadWriteMany ] - persistentVolumeReclaimPolicy: Retain - hostPath: { path: "{{ .Values.olsPrivatePath }}", type: DirectoryOrCreate } - ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: { name: "{{ .Values.openlitespeed }}-private-pvc", namespace: "{{ .Values.namespace }}" } -spec: - volumeName: "{{ .Values.openlitespeed }}-private-pv" - volumeMode: Filesystem - accessModes: [ ReadWriteMany ] - resources: { requests: { storage: 5Gi } } - storageClassName: "" - ---- -apiVersion: v1 -kind: PersistentVolume -metadata: { name: "{{ .Values.openlitespeed }}-public-pv" } -spec: - capacity: { storage: 10Gi } - volumeMode: Filesystem - accessModes: [ ReadWriteMany ] - persistentVolumeReclaimPolicy: Retain - hostPath: { path: "{{ .Values.olsPublicPath }}", type: DirectoryOrCreate } - ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: { name: "{{ .Values.openlitespeed }}-public-pvc", namespace: "{{ .Values.namespace }}" } -spec: - volumeName: "{{ .Values.openlitespeed }}-public-pv" - volumeMode: Filesystem - accessModes: [ ReadWriteMany ] - resources: { requests: { storage: 10Gi } } - storageClassName: "" - --- apiVersion: v1 kind: PersistentVolume @@ -75,7 +31,7 @@ spec: volumeMode: Filesystem accessModes: [ ReadWriteMany ] persistentVolumeReclaimPolicy: Retain - hostPath: { path: "{{ .Values.olsConfigPath }}", type: DirectoryOrCreate } + hostPath: { path: "{{ .Values.openlitespeedConfigPath }}", type: DirectoryOrCreate } --- apiVersion: v1 @@ -97,7 +53,7 @@ spec: volumeMode: Filesystem accessModes: [ ReadWriteMany ] persistentVolumeReclaimPolicy: Retain - hostPath: { path: "{{ .Values.olsAdminPath }}", type: DirectoryOrCreate } + hostPath: { path: "{{ .Values.openlitespeedAdminPath }}", type: DirectoryOrCreate } --- apiVersion: v1 @@ -119,7 +75,7 @@ spec: volumeMode: Filesystem accessModes: [ ReadWriteMany ] persistentVolumeReclaimPolicy: Retain - hostPath: { path: "{{ .Values.olsPhpIniPath }}", type: DirectoryOrCreate } + hostPath: { path: "{{ .Values.openlitespeedPhpIniPath }}", type: DirectoryOrCreate } --- apiVersion: v1 @@ -142,7 +98,7 @@ spec: accessModes: [ ReadWriteMany ] persistentVolumeReclaimPolicy: Retain storageClassName: "" - hostPath: { path: "{{ .Values.olsLogsPath }}", type: DirectoryOrCreate } + hostPath: { path: "{{ .Values.openlitespeedLogsPath }}", type: DirectoryOrCreate } --- apiVersion: v1 @@ -155,6 +111,50 @@ spec: resources: { requests: { storage: 10Gi } } storageClassName: "" +--- +apiVersion: v1 +kind: PersistentVolume +metadata: { name: "{{ .Values.openlitespeed }}-vhost-data-pv" } +spec: + capacity: { storage: 5Gi } + volumeMode: Filesystem + accessModes: [ ReadWriteMany ] + persistentVolumeReclaimPolicy: Retain + hostPath: { path: "{{ .Values.openlitespeedVhostDataPath }}", type: DirectoryOrCreate } + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: { name: "{{ .Values.openlitespeed }}-vhost-data-pvc", namespace: "{{ .Values.namespace }}" } +spec: + volumeName: "{{ .Values.openlitespeed }}-vhost-data-pv" + volumeMode: Filesystem + accessModes: [ ReadWriteMany ] + resources: { requests: { storage: 5Gi } } + storageClassName: "" + +--- +apiVersion: v1 +kind: PersistentVolume +metadata: { name: "{{ .Values.openlitespeed }}-vhost-shared-pv" } +spec: + capacity: { storage: 1Gi } + volumeMode: Filesystem + accessModes: [ ReadWriteMany ] + persistentVolumeReclaimPolicy: Retain + hostPath: { path: "{{ .Values.openlitespeedVhostSharedPath }}", type: DirectoryOrCreate } + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: { name: "{{ .Values.openlitespeed }}-vhost-shared-pvc", namespace: "{{ .Values.namespace }}" } +spec: + volumeName: "{{ .Values.openlitespeed }}-vhost-shared-pv" + volumeMode: Filesystem + accessModes: [ ReadWriteMany ] + resources: { requests: { storage: 1Gi } } + storageClassName: "" + --- apiVersion: apps/v1 kind: Deployment @@ -194,22 +194,18 @@ spec: readinessProbe: { tcpSocket: { port: 80 }, initialDelaySeconds: 5, periodSeconds: 5, failureThreshold: 3 } livenessProbe: { tcpSocket: { port: 80 }, initialDelaySeconds: 10, periodSeconds: 10, failureThreshold: 5 } volumeMounts: - - { name: "{{ .Values.openlitespeed }}-vhosts-volume", mountPath: {{ .Values.olsPodVhostsPath }} } - - { name: "{{ .Values.openlitespeed }}-private-volume", mountPath: {{ .Values.olsPodPrivatePath }}, readOnly: true } - - { name: "{{ .Values.openlitespeed }}-public-volume", mountPath: {{ .Values.olsPodPublicPath }}, readOnly: true } - - { name: "{{ .Values.openlitespeed }}-config-volume", mountPath: /usr/local/lsws/conf } - - { name: "{{ .Values.openlitespeed }}-admin-volume", mountPath: /usr/local/lsws/admin/conf } - - { name: "{{ .Values.openlitespeed }}-phpini-volume", mountPath: /etc/ols-php-ini } - - { name: "{{ .Values.openlitespeed }}-logs-volume", mountPath: /usr/local/lsws/logs } - - { name: "{{ .Values.openlitespeed }}-cache-volume", mountPath: /usr/local/lsws/cachedata } - - { name: "{{ .Values.openlitespeed }}-tmp-volume", mountPath: /tmp/lshttpd } + - { name: "{{ .Values.openlitespeed }}-vhosts-volume", mountPath: /var/www/vhosts } + - { name: "{{ .Values.openlitespeed }}-config-volume", mountPath: /usr/local/lsws/conf } + - { name: "{{ .Values.openlitespeed }}-admin-volume", mountPath: /usr/local/lsws/admin/conf } + - { name: "{{ .Values.openlitespeed }}-phpini-volume", mountPath: /etc/ols-php-ini } + - { name: "{{ .Values.openlitespeed }}-logs-volume", mountPath: /usr/local/lsws/logs } + - { name: "{{ .Values.openlitespeed }}-cache-volume", mountPath: /usr/local/lsws/cachedata } + - { name: "{{ .Values.openlitespeed }}-tmp-volume", mountPath: /tmp/lshttpd } + - { name: "{{ .Values.openlitespeed }}-vhost-data-volume", mountPath: /var/www/data, readOnly: true } + - { name: "{{ .Values.openlitespeed }}-vhost-shared-volume", mountPath: /var/www/shared, readOnly: true } volumes: - name: "{{ .Values.openlitespeed }}-vhosts-volume" persistentVolumeClaim: { claimName: "{{ .Values.openlitespeed }}-vhosts-pvc" } - - name: "{{ .Values.openlitespeed }}-private-volume" - persistentVolumeClaim: { claimName: "{{ .Values.openlitespeed }}-private-pvc" } - - name: "{{ .Values.openlitespeed }}-public-volume" - persistentVolumeClaim: { claimName: "{{ .Values.openlitespeed }}-public-pvc" } - name: "{{ .Values.openlitespeed }}-config-volume" persistentVolumeClaim: { claimName: "{{ .Values.openlitespeed }}-config-pvc" } - name: "{{ .Values.openlitespeed }}-admin-volume" @@ -222,6 +218,10 @@ spec: emptyDir: { sizeLimit: 100Gi } - name: "{{ .Values.openlitespeed }}-tmp-volume" emptyDir: { sizeLimit: 100Gi } + - name: "{{ .Values.openlitespeed }}-vhost-data-volume" + persistentVolumeClaim: { claimName: "{{ .Values.openlitespeed }}-vhost-data-pvc" } + - name: "{{ .Values.openlitespeed }}-vhost-shared-volume" + persistentVolumeClaim: { claimName: "{{ .Values.openlitespeed }}-vhost-shared-pvc" } --- apiVersion: v1 @@ -264,7 +264,7 @@ apiVersion: traefik.io/v1alpha1 kind: MiddlewareTCP metadata: { name: "{{ .Values.openlitespeed }}-admin-allowlist", namespace: "{{ .Values.namespace }}" } spec: - ipAllowList: { sourceRange: [ {{ .Values.olsAdminWhiteList }} ] } + ipAllowList: { sourceRange: [ {{ .Values.openlitespeedAdminWhiteList }} ] } --- apiVersion: traefik.io/v1alpha1 diff --git a/sodew-bash-main/assets/openlitespeed/rules/php.rules b/sodew-bash-main/assets/openlitespeed/rules/php.rules deleted file mode 100644 index 000a3cd..0000000 --- a/sodew-bash-main/assets/openlitespeed/rules/php.rules +++ /dev/null @@ -1,13 +0,0 @@ -RewriteEngine On - -RewriteCond %{DOCUMENT_ROOT}/.php81 -f -RewriteRule ^ - [H=application/x-httpd-lsphp81] - -RewriteCond %{DOCUMENT_ROOT}/.php82 -f -RewriteRule ^ - [H=application/x-httpd-lsphp82] - -RewriteCond %{DOCUMENT_ROOT}/.php83 -f -RewriteRule ^ - [H=application/x-httpd-lsphp83] - -RewriteCond %{DOCUMENT_ROOT}/.php84 -f -RewriteRule ^ - [H=application/x-httpd-lsphp84] diff --git a/sodew-bash-main/assets/openlitespeed/templates/virtual.host.conf b/sodew-bash-main/assets/openlitespeed/templates/virtual.host.conf deleted file mode 100644 index cdc7fa2..0000000 --- a/sodew-bash-main/assets/openlitespeed/templates/virtual.host.conf +++ /dev/null @@ -1,37 +0,0 @@ -allowSymbolLink 1 -enableScript 1 -restrained 1 -setUIDMode 2 -vhRoot /var/www/vhosts/$VH_NAME - -virtualHostConfig { - docRoot $VH_ROOT/www/ - vhDomain $VH_NAME - vhAliases *.$VH_NAME - - index { - useServer 0 - indexFiles index.php - } - - phpIniOverride { - php_admin_value upload_tmp_dir $VH_ROOT/tmp - php_admin_value session.save_path $VH_ROOT/session - php_admin_value open_basedir "$VH_ROOT/www:$VH_ROOT/tmp:$VH_ROOT/session:/var/www/private/$VH_NAME:/var/www/public" - php_admin_value auto_prepend_file /var/www/private/$VH_NAME/bootstrap.php - } - - rewrite { - enable 1 - autoLoadHtaccess 1 - rules <<.config` -- `DIR` - existence of the directory `$olsVhostsPath/` +- `DIR` - existence of the directory `$vhostsPath/` - `OLS` - existence of an entry in the `OpenLiteSpeed` configuration - `MD` - existence of the database (based on the entry in the configuration file) - `MU` - existence of the database user (based on the entry in the configuration file) - `RU` - existence of the Redis user (based on the entry in the configuration file) -- `WP` - existence of the WP configuration file `$olsVhostsPath//www/wp-config.php` +- `WP` - existence of the WP configuration file `$vhostsPath//www/wp-config.php` ) diff --git a/sodew-bash-main/kube.sh b/sodew-bash-main/kube.sh index e671b1a..6a2d241 100644 --- a/sodew-bash-main/kube.sh +++ b/sodew-bash-main/kube.sh @@ -2,7 +2,7 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -readonly appVersion="7.1.553" +readonly appVersion="7.0.539" readonly appName="KUBE" readonly appPath="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" readonly appFile="$(basename -- "$0")" @@ -16,8 +16,7 @@ function appDev() { printRow printFill 30 "◤◢" "$fontYellow" "◤$fontReset" - - +cmdOpenlitespeedRestart printFill 30 "◤◢" "$fontYellow" "◤$fontReset" } diff --git a/sodew-bash-main/libs/app.sh b/sodew-bash-main/libs/app.sh index dc7c70c..981c369 100644 --- a/sodew-bash-main/libs/app.sh +++ b/sodew-bash-main/libs/app.sh @@ -51,7 +51,7 @@ function appFailure() { if [[ "${1:-}" =~ ^[0-9]+$ ]]; then code="$1" - shift || true + shift fi printf '%b\n' "\033[0;91mCrash: $*\033[0m" @@ -70,18 +70,18 @@ function appLoadFile() { function appCheckConfig() { local value - local -a values=('hostName' 'hostIp' 'hostUuid' 'hostSalt' 'k3sNamespace' 'redisKube' 'mariadbKube' 'olsKube' 'postfixKube' 'workerKube' 'redisFileUsersAcl' 'postfixIp' 'postfixHost' 'postfixPostmaster' 'postfixDkimSelector' 'workerApiUrl' 'workerName' 'backupType' 'backupFirstDir') + local -a values=('hostName' 'hostIp' 'hostUuid' 'hostSalt' 'k3sNamespace' 'redisKube' 'mariadbKube' 'openlitespeedKube' 'postfixKube' 'workerKube' 'redisFileUsersAcl' 'postfixIp' 'postfixHost' 'postfixPostmaster' 'postfixDkimSelector' 'workerApiUrl' 'workerName' 'backupType' 'backupFirstDir') for value in "${values[@]}"; do [[ -n "${!value-}" ]] || appFailure 4 "$value: not specified" done - values=('appAssetsPath' 'appDataPath' 'basePath' 'olsVhostsPath' 'domainsList' 'k3sCmd' 'redisPath' 'mariadbMasterPath' 'mariadbSlavePath' 'olsPath' 'olsAdminPath' 'olsPhpIniPath' 'olsLogsPath' 'olsConfigFile' 'olsPrivatePath' 'olsPublicPath' 'olsVhostsConfigPath' 'postfixPath' 'postfixDkimPath' 'workerPath' 'workerAgentPath' 'workerTasksPath' 'workerFilesPath' 'logPath' 'logFile' 'backupDailyPath' 'backupArchivePath' 'storagePath' 'rsyncPath' 'ftpPath' 'sshPath') + values=('appAssetsPath' 'appDataPath' 'basePath' 'vhostsPath' 'domainsList' 'k3sCmd' 'redisPath' 'mariadbMasterPath' 'mariadbSlavePath' 'openlitespeedPath' 'openlitespeedAdminPath' 'openlitespeedPhpIniPath' 'openlitespeedLogsPath' 'openlitespeedConfigFile' 'openlitespeedVhostDataPath' 'openlitespeedVhostSharedPath' 'openlitespeedVhostsPath' 'postfixPath' 'postfixDkimPath' 'workerPath' 'workerAgentPath' 'workerTasksPath' 'workerFilesPath' 'logPath' 'logFile' 'backupDailyPath' 'backupArchivePath' 'storagePath' 'rsyncPath' 'ftpPath' 'sshPath') for value in "${values[@]}"; do [[ "${!value-}" == /* ]] || appFailure 4 "$value: a variable must begin with /" [[ "${!value-}" != */ ]] || appFailure 4 "$value: a variable cannot end in /" done - values=('backupParallelJobs' 'k3sReadyRetries' 'k3sReadySleep' 'workerApiGettingPause' 'workerApiSendingPause' 'backupDailyKeep' 'backupArchiveInterval' 'storageDailyKeep' 'storageArchiveKeep' 'olsQuotaBlockLimit' 'olsQuotaInodeLimit') + values=('backupParallelJobs' 'k3sReadyRetries' 'k3sReadySleep' 'workerApiGettingPause' 'workerApiSendingPause' 'backupDailyKeep' 'backupArchiveInterval' 'storageDailyKeep' 'storageArchiveKeep' 'openlitespeedQuotaBlockLimit' 'openlitespeedQuotaInodeLimit') for value in "${values[@]}"; do [[ "${!value-}" =~ ^[0-9]+$ ]] && (( ${!value} >= 1 )) || appFailure 4 "$value: incorrect number value" done diff --git a/sodew-bash-main/libs/commands/backup.sh b/sodew-bash-main/libs/commands/backup.sh index ac419fa..f851af7 100644 --- a/sodew-bash-main/libs/commands/backup.sh +++ b/sodew-bash-main/libs/commands/backup.sh @@ -10,7 +10,7 @@ function cmdBackupSitesArchive() { local type="${2:-$backupType}" local error vhostList total - run vhostList error openlitespeedConfigVhostList || { printDanger "Failed get list of vhosts: $error"; return 1; } + run vhostList error openlitespeedVhostList || { printDanger "Failed get list of virtual hosts: $error"; return 1; } total=$(grep -c . <<< "$vhostList") printSection "Config" @@ -68,13 +68,13 @@ function cmdBackupSitesRsync() { printDotText "Path" "$path" local error vhostList - run vhostList error openlitespeedConfigVhostList || { printDanger "Failed get list of vhosts: $error"; return 1; } + run vhostList error openlitespeedVhostList || { printDanger "Failed get list of virtual hosts: $error"; return 1; } printText "Files..." if [[ "$path" == *"$backupFirstDir" ]]; then - runError error rsync -a --mkpath -- "$olsVhostsPath/" "$path" || printDanger "$error" + runError error rsync -a --mkpath -- "$vhostsPath/" "$path" || printDanger "$error" else - runError error rsync -a --link-dest="$backupDailyPath/$backupFirstDir" -- "$olsVhostsPath/" "$path" || printDanger "$error" + runError error rsync -a --link-dest="$backupDailyPath/$backupFirstDir" -- "$vhostsPath/" "$path" || printDanger "$error" fi printText "Databases..." @@ -84,7 +84,7 @@ function cmdBackupSitesRsync() { printText "Configs..." while read -r domain; do - runError error cp -p -- "$olsVhostsConfigPath/$domain.conf" "$path/$domain.conf" || printDanger "$error" + runError error cp -p -- "$openlitespeedVhostsPath/$domain.conf" "$path/$domain.conf" || printDanger "$error" done < <(awk 'NF' <<< "$vhostList") } @@ -302,7 +302,6 @@ function cmdBackupDispatch() { # [$3] (type): backup type. function cmdBackupRun() { local target="$1" - [[ -n "$target" ]] || { printRow; printDanger "Target not specified"; return 1; } local path="$2" path=$(backupPathGenerate "$path") @@ -328,56 +327,3 @@ function cmdBackupRun() { fi fi } - -function cmdBackupList() { - printRow - - local dirList archiveList dailyList backupList backupCount error - run dirList error fileList "$backupArchivePath" d || { printDanger "$error"; return 1; } - archiveList=$(printf '%s\n' "$dirList" | grep -E -- "$backupArchiveDirPattern" | sort || true) - - run dirList error fileList "$backupDailyPath" d || { printDanger "$error"; return 1; } - dailyList=$(printf '%s\n' "$dirList" | grep -E -- "$backupDailyDirPattern" | sort || true) - - backupList=$(printf '%s\n' "$archiveList" "$dailyList" | awk 'NF' | sort) - backupCount=$(grep -c . <<< "$backupList" || true) - local i=0 num dir label - while read -r dir; do - ((++i)) - num=$(printf "%0${#backupCount}d" "$i") - label="$num: $fontBlue$dir$fontReset" - - if listContains "$dir" "$archiveList"; then - printDotText "$label" "${fontGreen}archive$fontReset" - elif listContains "$dir" "$dailyList"; then - printDotText "$label" "${fontGreen}daily$fontReset" - else - printDotText "$label" "$labelUnknown" - fi - done < <(awk 'NF' <<< "$backupList") -} - -function cmdBackupSize() { - local dirList file size total=0 archiveList dailyList - - printSection "Archive: $backupArchivePath" - run dirList error fileList "$backupArchivePath" d || { printDanger "$error"; return 1; } - archiveList=$(printf '%s\n' "$dirList" | grep -E -- "$backupArchiveDirPattern" | sort || true) - while IFS= read -r file; do - size=$(pathSize "$backupArchivePath/$file" "gb") - printDotText "$file" "$size Gb" - (( total += size )) - done <<< "$archiveList" - - printSection "Daily: $backupDailyPath" - run dirList error fileList "$backupDailyPath" d || { printDanger "$error"; return 1; } - dailyList=$(printf '%s\n' "$dirList" | grep -E -- "$backupDailyDirPattern" | sort || true) - while IFS= read -r file; do - size=$(pathSize "$backupDailyPath/$file" "gb") - printDotText "$file" "$size Gb" - (( total += size )) - done <<< "$dailyList" - - printRow - printDotText "total" "$total Gb" -} diff --git a/sodew-bash-main/libs/commands/help.sh b/sodew-bash-main/libs/commands/help.sh index 21f47eb..8407880 100644 --- a/sodew-bash-main/libs/commands/help.sh +++ b/sodew-bash-main/libs/commands/help.sh @@ -3,14 +3,14 @@ function cmdHelpPrint() { } function cmdHelpK3S() { - local title="-k|--k3s " + local title="-k|--k3s [option]" local desc=" create - create all resources in k3s remove - remove all resources in k3s info - detail about a k3s status - status about a k3s top - top pod - res [] - get resource info (all|pod|event|pv|pvc|deploy|ds|rs|sts|svc|ing|ip|secret|cm|job|cj|ep|no|ns|cs|netpol)" + res [resource] - get resource info (all|pod|event|pv|pvc|deploy|ds|rs|sts|svc|ing|ip|secret|cm|job|cj|ep|no|ns|cs|netpol)" cmdHelpPrint "$title" "$desc" } @@ -26,8 +26,8 @@ function cmdHelpMariaDB() { replica - replica rebuild database - database list user - user list - dump [all|] [] - dump specified database or all databases from Master - dump_slave [] - full dump from Slave" + dump [all|] [file] - dump specified database or all databases from Master + dump_slave [file] - full dump from Slave" cmdHelpPrint "$title" "$desc" } @@ -50,21 +50,22 @@ function cmdHelpRedis() { function cmdHelpOpenLiteSpeed() { local title="-o|--ols " local desc=" - install - install OpenLiteSpeed in k3s - update - update OpenLiteSpeed in k3s - uninstall - uninstall OpenLiteSpeed from k3s - info - detail about a OpenLiteSpeed - list