mirror of
https://github.com/vmstan/gravity-sync.git
synced 2024-08-30 18:22:11 +00:00
3.7.0 (#315)
* add path removal to clear_cron * 3.6.4 * add local folder to path * templates for systemd timers * Wantedby * user root * Gonna be 3.7 * Remove legacy cron code from automate function * Core for moving replication jobs into place * Move stop before copy * Add Gravity Sync messages * Service file customization * Line break * 10 minutes to sudo * if active else * Do things quietly * Custom exec path * clear exec start * warning about cron * no longer exists
This commit is contained in:
parent
087550742a
commit
ff32465625
@ -3,7 +3,7 @@ SCRIPT_START=$SECONDS
|
|||||||
|
|
||||||
# GRAVITY SYNC BY VMSTAN #####################
|
# GRAVITY SYNC BY VMSTAN #####################
|
||||||
PROGRAM='Gravity Sync'
|
PROGRAM='Gravity Sync'
|
||||||
VERSION='3.6.3'
|
VERSION='3.7.0'
|
||||||
|
|
||||||
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
|
# For documentation or downloading updates visit https://github.com/vmstan/gravity-sync
|
||||||
# Requires Pi-Hole 5.x or higher already be installed, for help visit https://pi-hole.net
|
# Requires Pi-Hole 5.x or higher already be installed, for help visit https://pi-hole.net
|
||||||
@ -71,6 +71,7 @@ HISTORY_MD5='gravity-sync.md5' # replace in gravity-sync.conf to overwrite
|
|||||||
|
|
||||||
# OS Settings
|
# OS Settings
|
||||||
BASH_PATH='/bin/bash' # default OS bash path
|
BASH_PATH='/bin/bash' # default OS bash path
|
||||||
|
DAEMON_PATH='/etc/systemd/system' # systemd timer/service folder
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
### NEVER CHANGE ANYTHING BELOW THIS LINE! ###
|
### NEVER CHANGE ANYTHING BELOW THIS LINE! ###
|
||||||
@ -148,7 +149,7 @@ case $# in
|
|||||||
task_compare ;;
|
task_compare ;;
|
||||||
cron)
|
cron)
|
||||||
start_gs
|
start_gs
|
||||||
task_cron ;;
|
task_autocron ;;
|
||||||
config|configure)
|
config|configure)
|
||||||
start_gs_noconfig
|
start_gs_noconfig
|
||||||
task_configure ;;
|
task_configure ;;
|
||||||
|
@ -10,6 +10,61 @@ function task_automate {
|
|||||||
MESSAGE="${MESSAGE}: ${TASKTYPE}"
|
MESSAGE="${MESSAGE}: ${TASKTYPE}"
|
||||||
echo_good
|
echo_good
|
||||||
|
|
||||||
|
CRON_EXIST='0'
|
||||||
|
CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0')
|
||||||
|
if [ ${CRON_CHECK} == 1 ]
|
||||||
|
then
|
||||||
|
MESSAGE="${UI_AUTO_CRON_EXISTS}"
|
||||||
|
echo_warn
|
||||||
|
clear_cron
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESSAGE="Customizing service file username"
|
||||||
|
sed -i "/User=unknown/c\User=$USER" ${LOCAL_FOLDR}/templates/gravity-sync.service
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
MESSAGE="Customizing service file executable"
|
||||||
|
sed -i "/ExecStart=/c\ExecStart=${LOCAL_FOLDR}/${GS_FILENAME}" ${LOCAL_FOLDR}/templates/gravity-sync.service
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
if systemctl is-active --quiet gravity-sync
|
||||||
|
then
|
||||||
|
MESSAGE="Stopping existing systemd service"
|
||||||
|
sudo systemctl stop gravity-sync
|
||||||
|
error_validate
|
||||||
|
fi
|
||||||
|
|
||||||
|
MESSAGE="Moving systemd timer into place"
|
||||||
|
sudo cp ${LOCAL_FOLDR}/templates/gravity-sync.timer ${DAEMON_PATH}
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
MESSAGE="Moving systemd service into place"
|
||||||
|
sudo cp ${LOCAL_FOLDR}/templates/gravity-sync.service ${DAEMON_PATH}
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
MESSAGE="Reloading systemd daemon"
|
||||||
|
sudo systemctl daemon-reload --quiet
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
MESSAGE="Enabling Gravity Sync timer"
|
||||||
|
sudo systemctl enable gravity-sync.timer --quiet
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
MESSAGE="Starting Gravity Sync service"
|
||||||
|
sudo systemctl start gravity-sync --quiet
|
||||||
|
error_validate
|
||||||
|
|
||||||
|
exit_withchange
|
||||||
|
}
|
||||||
|
|
||||||
|
function task_autocron {
|
||||||
|
TASKTYPE='AUTOCRON'
|
||||||
|
MESSAGE="${MESSAGE}: ${TASKTYPE}"
|
||||||
|
echo_good
|
||||||
|
|
||||||
|
MESSAGE="Crontab automation is deprecated and will be removed in a future release"
|
||||||
|
echo_warn
|
||||||
|
|
||||||
CRON_EXIST='0'
|
CRON_EXIST='0'
|
||||||
CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0')
|
CRON_CHECK=$(crontab -l | grep -q "${GS_FILENAME}" && echo '1' || echo '0')
|
||||||
if [ ${CRON_CHECK} == 1 ]
|
if [ ${CRON_CHECK} == 1 ]
|
||||||
|
@ -43,7 +43,8 @@ function list_gs_arguments {
|
|||||||
echo_lines
|
echo_lines
|
||||||
echo -e "Setup Options:"
|
echo -e "Setup Options:"
|
||||||
echo -e " ${YELLOW}config${NC} Creates a new ${PROGRAM} configuration file"
|
echo -e " ${YELLOW}config${NC} Creates a new ${PROGRAM} configuration file"
|
||||||
echo -e " ${YELLOW}automate${NC} Schedules the ${PROGRAM} replication task using crontab"
|
echo -e " ${YELLOW}automate${NC} Schedules the ${PROGRAM} replication task using systemd"
|
||||||
|
echo -e " ${YELLOW}cron${NC} Schedules the ${PROGRAM} replication task using crontab (legacy)"
|
||||||
echo -e " ${YELLOW}version${NC} Shows the installed version of ${PROGRAM} and check for updates"
|
echo -e " ${YELLOW}version${NC} Shows the installed version of ${PROGRAM} and check for updates"
|
||||||
echo -e " ${YELLOW}update${NC} Upgrades ${PROGRAM} to the latest available version using Git"
|
echo -e " ${YELLOW}update${NC} Upgrades ${PROGRAM} to the latest available version using Git"
|
||||||
echo -e " ${YELLOW}dev${NC} Sets update command to use a development version of ${PROGRAM}"
|
echo -e " ${YELLOW}dev${NC} Sets update command to use a development version of ${PROGRAM}"
|
||||||
@ -57,7 +58,6 @@ function list_gs_arguments {
|
|||||||
echo_blank
|
echo_blank
|
||||||
echo -e "Debug Options:"
|
echo -e "Debug Options:"
|
||||||
echo -e " ${YELLOW}logs${NC} Shows the recent successful replication jobs/times"
|
echo -e " ${YELLOW}logs${NC} Shows the recent successful replication jobs/times"
|
||||||
echo -e " ${YELLOW}cron${NC} Displays the output of last crontab execution"
|
|
||||||
echo -e " ${YELLOW}info${NC} Shows information about the current configuration"
|
echo -e " ${YELLOW}info${NC} Shows information about the current configuration"
|
||||||
echo_lines
|
echo_lines
|
||||||
exit_nochange
|
exit_nochange
|
||||||
|
@ -112,11 +112,11 @@ UI_PURGE_DELETE_SSH_KEYS='Deleting SSH key-files'
|
|||||||
UI_PURGE_CLEANING_DIR="Purging ${PROGRAM} directory"
|
UI_PURGE_CLEANING_DIR="Purging ${PROGRAM} directory"
|
||||||
|
|
||||||
# Automation
|
# Automation
|
||||||
UI_AUTO_CRON_EXISTS='Automation task already exists in crontab'
|
UI_AUTO_CRON_EXISTS='Automation task exists in crontab'
|
||||||
UI_AUTO_CRON_DISPLAY_FREQ='Select synchronization frequency (in minutes)'
|
UI_AUTO_CRON_DISPLAY_FREQ='Select synchronization frequency (in minutes)'
|
||||||
UI_AUTO_CRON_SELECT_FREQ='Valid options are 5, 10, 15, 30 or 0 to disable (default: 15)'
|
UI_AUTO_CRON_SELECT_FREQ='Valid options are 5, 10, 15, 30 or 0 to disable (default: 15)'
|
||||||
UI_AUTO_CRON_SAVING='Saving new synchronization task to crontab'
|
UI_AUTO_CRON_SAVING='Saving new synchronization task to crontab'
|
||||||
UI_AUTO_CRON_DISABLED='Synchronization automation has been disabled'
|
UI_AUTO_CRON_DISABLED='Automation with crontab has been disabled'
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
UI_CONFIG_YESNOY="'Yes' or 'No', blank is default 'Yes'"
|
UI_CONFIG_YESNOY="'Yes' or 'No', blank is default 'Yes'"
|
||||||
|
@ -60,4 +60,5 @@ REMOTE_USER='pi'
|
|||||||
# HISTORY_MD5='' # replace in gravity-sync.conf to overwrite
|
# HISTORY_MD5='' # replace in gravity-sync.conf to overwrite
|
||||||
|
|
||||||
### OS Settings
|
### OS Settings
|
||||||
# BASH_PATH='' # default OS bash path
|
# BASH_PATH='' # default OS bash path
|
||||||
|
# DAEMON_PATH='' # systemd timer/service folder
|
12
templates/gravity-sync.service
Normal file
12
templates/gravity-sync.service
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Synchronize Pi-hole instances
|
||||||
|
After=network-online.target
|
||||||
|
Wants=gravity-sync.timer
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=unknown
|
||||||
|
ExecStart=
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
15
templates/gravity-sync.timer
Normal file
15
templates/gravity-sync.timer
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Synchronize Pi-hole instances
|
||||||
|
RefuseManualStart=no
|
||||||
|
RefuseManualStop=no
|
||||||
|
Requires=gravity-sync.service
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
Unit=gravity-sync.service
|
||||||
|
Persistent=true
|
||||||
|
OnBootSec=120
|
||||||
|
OnUnitInactiveSec=5m
|
||||||
|
RandomizedDelaySec=5m
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
Loading…
Reference in New Issue
Block a user