adv conf: add ROOT_CHECK_AVOID for container. (#64)

* adv conf: add ROOT_CHECK_AVOID for container.
import_gs only once at start

* allow parameters for automation option

Co-authored-by: Michael Stanclift <mstanclift@vmware.com>
This commit is contained in:
fbourqui 2020-07-16 20:09:44 +02:00 committed by GitHub
parent 70da7aad14
commit f6cdbc40ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 23 deletions

View File

@ -169,6 +169,11 @@ The `./gravity-sync.sh config` function will attempt to ping the remote host to
Default setting in Gravity Sync is 0, change to 1 to skip this network test.
#### `ROOT_CHECK_AVOID=''`
The `./gravity-sync.sh` check that it's deployed with it's own user, but for container deployment it's a nuisance, to install a user and gave it passwordless sudo power, witch result with the same security risk as running as root.
Default setting in Gravity Sync is 0, change to 1 to skip this root user test.
#### `BACKUP_RETAIN=''`
The `./gravity-sync.sh backup` function will retain a defined number of days worth of `gravity.db` and `custom.list` backups.
@ -212,11 +217,22 @@ If your code is still not updating after this, reinstallation is suggested rathe
## Automation
There are many automation methods available to run scripts on a regular basis of a Linux system. The one built into all of them is cron, but if you'd like to utilize something different then the principles are still the same.
To automate the deployment of automation option, you can call it with 2 parameters:
first interval in minutes to run sync [0-30],
then the hour to run backup [0-24]
Note: 0 will disable the cron entry.
for example:
gravity-sync.sh automate 15 23
will sync every 15 minutes and backup at 23:00.
If you prefer to still use cron but modify your settings by hand, using the entry below will cause the entry to run at the top and bottom of every hour (1:00 PM, 1:30 PM, 2:00 PM, etc) but you are free to dial this back or be more agressive if you feel the need.
```bash
crontab -e
*/30 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh > /home/USER/gravity-sync/gravity-sync.cron
*/15 * * * * /bin/bash /home/USER/gravity-sync/gravity-sync.sh > /home/USER/gravity-sync/gravity-sync.cron
0 23 * * * /bin/bash /home/USER//gravity-sync/gravity-sync.sh backup >/dev/null 2>&1
```
## Reference Architectures

View File

@ -33,5 +33,6 @@ REMOTE_PASS=''
# SKIP_CUSTOM=''
# DATE_OUTPUT=''
# PING_AVOID=''
# ROOT_CHECK_AVOID=''
# BACKUP_RETAIN=''

View File

@ -31,6 +31,7 @@ VERIFY_PASS='0' # replace in gravity-sync.conf to overwrite
SKIP_CUSTOM='0' # replace in gravity-sync.conf to overwrite
DATE_OUTPUT='0' # replace in gravity-sync.conf to overwrite
PING_AVOID='0' # replace in gravity-sync.conf to overwrite
ROOT_CHECK_AVOID='0' # replace in gravity-sync.conf to overwrite
# Backup Customization
BACKUP_RETAIN='7' # replace in gravity-sync.conf to overwrite
@ -770,7 +771,6 @@ function logs_export {
### Output Sync Logs
function logs_gs {
import_gs
MESSAGE="Tailing ${LOG_PATH}/${SYNCING_LOG}"
echo_info
@ -794,7 +794,6 @@ function logs_gs {
## Crontab Logs
### Core Crontab Logs
function show_crontab {
import_gs
MESSAGE="Replaying Last Cronjob"
echo_stat
@ -1610,8 +1609,6 @@ function task_automate {
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
CRON_EXIST='0'
CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0')
if [ ${CRON_CHECK} == 1 ]
@ -1624,9 +1621,14 @@ function task_automate {
MESSAGE="Configuring Hourly Smart Sync"
echo_info
MESSAGE="Sync Frequency in Minutes (1-30) or 0 to Disable"
echo_need
read INPUT_AUTO_FREQ
if [[ $1 =~ ^[0-9][0-9]?$ ]]
then
INPUT_AUTO_FREQ=$1
else
MESSAGE="Sync Frequency in Minutes (1-30) or 0 to Disable"
echo_need
read INPUT_AUTO_FREQ
fi
if [ $INPUT_AUTO_FREQ -gt 30 ]
then
@ -1660,9 +1662,14 @@ function task_automate {
MESSAGE="Configuring Daily Backup Frequency"
echo_info
MESSAGE="Hour of Day to Backup (1-24) or 0 to Disable"
echo_need
read INPUT_AUTO_BACKUP
if [[ $2 =~ ^[0-9][0-9]?$ ]]
then
INPUT_AUTO_BACKUP=$2
else
MESSAGE="Hour of Day to Backup (1-24) or 0 to Disable"
echo_need
read INPUT_AUTO_BACKUP
fi
if [ $INPUT_AUTO_BACKUP -gt 24 ]
then
@ -1820,8 +1827,7 @@ function task_compare {
TASKTYPE='COMPARE'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
validate_gs_folders
validate_ph_folders
validate_os_sshpass
@ -1970,8 +1976,11 @@ function root_check {
MESSAGE="Evaluating Arguments"
echo_stat
root_check
import_gs
if [ "${ROOT_CHECK_AVOID}" != "1" ]
then
root_check
fi
case $# in
@ -1980,7 +1989,6 @@ case $# in
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
validate_gs_folders
validate_ph_folders
validate_os_sshpass
@ -1996,7 +2004,6 @@ case $# in
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
validate_gs_folders
validate_ph_folders
validate_os_sshpass
@ -2010,7 +2017,6 @@ case $# in
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
validate_gs_folders
validate_ph_folders
validate_os_sshpass
@ -2023,8 +2029,7 @@ case $# in
TASKTYPE='PULL'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
validate_gs_folders
validate_ph_folders
validate_os_sshpass
@ -2037,8 +2042,7 @@ case $# in
TASKTYPE='PUSH'
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
validate_gs_folders
validate_ph_folders
validate_os_sshpass
@ -2052,7 +2056,6 @@ case $# in
MESSAGE="${MESSAGE}: ${TASKTYPE} Requested"
echo_good
import_gs
validate_gs_folders
validate_ph_folders
@ -2125,6 +2128,24 @@ case $# in
;;
esac
;;
2)
case $1 in
automate)
task_automate
;;
esac
;;
3)
case $1 in
automate)
task_automate $2 $3
;;
esac
;;
*)
task_invalid