Skip to content

Commit

Permalink
v159
Browse files Browse the repository at this point in the history
+ NTPD Modes | NTP is now uninstalled when SystemD timedatectl is
enabled. Reinstalled on demand. Timedatectl pool servers are now also
set:
https://github.com/Fourdee/DietPi/issues/1208#issuecomment-343762480
  • Loading branch information
Fourdee committed Nov 13, 2017
1 parent 818b96a commit 5f48e21
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 40 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ v159
(xx/11/17)

Changes / Improvements / Optimizations:
NTPD Modes | NTP is now uninstalled when SystemD timedatectl is enabled. Reinstalled on demand. Timedatectl pool servers are now also set: https://github.com/Fourdee/DietPi/issues/1208#issuecomment-343762480

Bug Fixes:


Allo Web Interface v4:

-----------------------------------------------------------------------------------------------------------
Expand Down
15 changes: 1 addition & 14 deletions dietpi/dietpi-config
Original file line number Diff line number Diff line change
Expand Up @@ -1329,20 +1329,7 @@
CHOICE=$?
if (( $CHOICE == 0 )); then

sed -i "/ntpd_update_mode=/c\ntpd_update_mode=$OPTION" /DietPi/dietpi.txt

# - Drift mode, use SystemD
if (( $OPTION == 4 )); then

timedatectl set-ntp true

# - NTPD
else

systemctl disable systemd-timesyncd
/DietPi/dietpi/func/run_ntpd

fi
/DietPi/dietpi/func/dietpi-set_software ntpd-mode $OPTION

REBOOT_REQUIRED=1

Expand Down
34 changes: 31 additions & 3 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ _EOF_

Reset_NTPD(){

killall -w /DietPi/dietpi/func/run_ntpd
killall -w ntpd
killall -w /DietPi/dietpi/func/run_ntpd &> /dev/null
killall -w ntpd &> /dev/null
rm /etc/dietpi/.ntpd_exit_status &> /dev/null

}
Expand Down Expand Up @@ -308,7 +308,7 @@ _EOF_
# - Software
#NB: All software has a unique index that must not be changed (eg: DESKTOP_LXDE = 23)
TOTAL_SOFTWARE_INDEXS=0
TOTAL_SOFTWARE_INDEXS_HARDLIMIT=170 #Increase as needed. Must be higher than TOTAL_SOFTWARE_INDEXS once calculated in Software_Arrays_Init
TOTAL_SOFTWARE_INDEXS_HARDLIMIT=171 #Increase as needed. Must be higher than TOTAL_SOFTWARE_INDEXS once calculated in Software_Arrays_Init

INSTALLING_INDEX=0 #Which software index is currently being installed?

Expand Down Expand Up @@ -2347,6 +2347,14 @@ _EOF_

aSOFTWARE_AVAIL_HW_MODEL[$index_current,21]=1

#------------------
index_current=170

aSOFTWARE_WHIP_NAME[$index_current]='NTP'
aSOFTWARE_WHIP_DESC[$index_current]='date and time sync'
aSOFTWARE_CATEGORY_INDEX[$index_current]=3
aSOFTWARE_TYPE[$index_current]=-1 #Hidden, use dietpi-config > advanced > timesync to setup

#Shared Libs
#--------------------------------------------------------------------------------
index_current=7
Expand Down Expand Up @@ -7873,6 +7881,20 @@ _EOF_

fi

INSTALLING_INDEX=170
if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

Banner_Installing
AGI ntp

# Remove service, as DietPi ntpd-mode launches the binary with custom commands
systemctl stop ntp
rm /etc/init.d/ntp

killall -w ntpd &> /dev/null

fi

INSTALLING_INDEX=17
if (( ${aSOFTWARE_INSTALL_STATE[$INSTALLING_INDEX]} == 1 )); then

Expand Down Expand Up @@ -10414,6 +10436,7 @@ case "\$1" in
done
xset dpms force on #disable screen blanking
x11vnc -display :0 -usepw -forever &
fi
Expand Down Expand Up @@ -13820,6 +13843,11 @@ _EOF_
rm /etc/systemd/system/alsa-init.service
rm -R /home/dietpi/assistant.json

elif (( $1 == 170 )); then

Reset_NTPD
AGP ntp

elif (( $1 == 158 )); then

# Remove service
Expand Down
60 changes: 60 additions & 0 deletions dietpi/func/dietpi-set_software
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# - /DietPi/dietpi/func/dietpi-set_software userdel X=delete user with name X
# - /DietPi/dietpi/func/dietpi-set_software apt-mirror url/default
# - /DietPi/dietpi/func/dietpi-set_software ntpd-mirror url/default
# - /DietPi/dietpi/func/dietpi-set_software ntpd-mode configures NTPD mode (eg: ntp/systemd)
#////////////////////////////////////

#Exit path for non-root logins.
Expand Down Expand Up @@ -177,6 +178,61 @@ _EOF_

}

#/////////////////////////////////////////////////////////////////////////////////////
# Set NTPD Mode
#/////////////////////////////////////////////////////////////////////////////////////
NtpdMode_Main(){

if [ -n "$INPUT_MODE_VALUE" ]; then

# - Reset global to disabled, prevents run_ntpd
sed -i "/ntpd_update_mode=/c\ntpd_update_mode=0" /DietPi/dietpi.txt

# - Uninstall ntp if not required
if (( $INPUT_MODE_VALUE <= 0 || $INPUT_MODE_VALUE >= 4 )); then

/DietPi/dietpi/dietpi-software uninstall 170

# - Update DietPi.txt
sed -i "/ntpd_update_mode=/c\ntpd_update_mode=$INPUT_MODE_VALUE" /DietPi/dietpi.txt

fi

#Setup Drift mode, use SystemD
if (( $INPUT_MODE_VALUE == 4 )); then

# - Set default pool servers
cat << _EOF_ > /etc/systemd/timesyncd.conf
[Time]
Servers=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
_EOF_

# - enable
systemctl daemon-reload
timedatectl set-ntp true

#Set NTPD
else

systemctl stop systemd-timesyncd
systemctl disable systemd-timesyncd
/DietPi/dietpi/dietpi-software install 170

# - Update DietPi.txt
sed -i "/ntpd_update_mode=/c\ntpd_update_mode=$INPUT_MODE_VALUE" /DietPi/dietpi.txt

/DietPi/dietpi/func/run_ntpd status

fi

else

Unknown_Input_Mode

fi

}

#/////////////////////////////////////////////////////////////////////////////////////
# allo
#/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -320,6 +376,10 @@ _EOF_

NtpdMirror_Main

elif [ "$INPUT_MODE_NAME" = "ntpd-mode" ]; then

NtpdMode_Main

elif [ "$INPUT_MODE_NAME" = "allo" ]; then

Allo_Main
Expand Down
55 changes: 32 additions & 23 deletions dietpi/func/run_ntpd
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
EXIT_CODE=-1

FP_EXIT_CODE='/etc/dietpi/.ntpd_exit_status'
NTPD_UPDATE_MODE=0
NTPD_UPDATE_MODE=$(grep -m1 '^ntpd_update_mode=' /DietPi/dietpi.txt | sed 's/.*=//')

Update_NTPD(){

#Dont run twice
if (( $(ps aux | grep -ci -m1 '[[:space:]][n]tpd') )); then
if (( $(ps aux | grep -ci -m1 '[[:space:]][n]tpd[[:space:]]') )); then

/DietPi/dietpi/func/dietpi-notify 2 "NTPD: is already running"

Expand All @@ -47,12 +47,10 @@

fi

NTPD_UPDATE_MODE=$(cat /DietPi/dietpi.txt | grep -m1 '^ntpd_update_mode=' | sed 's/.*=//')

#NTPD: run, exit when updated.
if (( $NTPD_UPDATE_MODE >= 1 && $NTPD_UPDATE_MODE <= 3 )); then

/DietPi/dietpi/func/dietpi-notify 2 "NTPD: Running time sync update"
/DietPi/dietpi/func/dietpi-notify 2 "NTPD: Running time sync update ($NTPD_UPDATE_MODE)"
ntpd -gq -l /var/log/ntpd.log &> /dev/null
EXIT_CODE=$?

Expand All @@ -77,32 +75,43 @@
#-----------------------------------------------------------------------------------
if [ "$INPUT_MODE" = "status" ]; then

MAX_LOOPS=30
CURRENT_LOOP=1
while (( $CURRENT_LOOP <= $MAX_LOOPS ))
do
#NTPD:
if (( $NTPD_UPDATE_MODE >= 1 && $NTPD_UPDATE_MODE <= 3 )); then

# Update NTPD if its not running, and, no exit file exists
if [ ! -f "$FP_EXIT_CODE" ] && (( ! $(ps aux | grep -ci -m1 '[[:space:]][n]tpd') )); then
MAX_LOOPS=30
CURRENT_LOOP=1
while (( $CURRENT_LOOP <= $MAX_LOOPS ))
do

/DietPi/dietpi/func/dietpi-notify 2 "NTPD: Has not yet been launched, running now, please wait..."
Update_NTPD &
sleep 1
# Update NTPD if its not running, and, no exit file exists
if [ ! -f "$FP_EXIT_CODE" ] && (( ! $(ps aux | grep -ci -m1 '[[:space:]][n]tpd[[:space:]]') )); then

elif [ -f "$FP_EXIT_CODE" ]; then
/DietPi/dietpi/func/dietpi-notify 2 "NTPD: Has not yet been launched, running now, please wait..."
Update_NTPD &
sleep 1

EXIT_CODE=$(cat "$FP_EXIT_CODE")
break
elif [ -f "$FP_EXIT_CODE" ]; then

else
EXIT_CODE=$(cat "$FP_EXIT_CODE")
break

/DietPi/dietpi/func/dietpi-notify 2 "NTPD: Waiting for completion of time sync ($CURRENT_LOOP/$MAX_LOOPS)"
sleep 1
((CURRENT_LOOP++))
else

fi
/DietPi/dietpi/func/dietpi-notify 2 "NTPD: Waiting for completion of time sync ($CURRENT_LOOP/$MAX_LOOPS)"
sleep 1
((CURRENT_LOOP++))

fi

done

done
#systemD-timesyncd/other method: assume status is ok
else

/DietPi/dietpi/func/dietpi-notify 0 "NTPD: non-NTPD mode detected. Completed"
EXIT_CODE=0

fi

#Run NTPD
else
Expand Down
2 changes: 2 additions & 0 deletions dietpi/patch_file
Original file line number Diff line number Diff line change
Expand Up @@ -2835,6 +2835,8 @@ _EOF_
# Allo GUI (full)
/DietPi/dietpi/dietpi-software reinstall 159
#-------------------------------------------------------------------------------
#Add .installed ntp 170 if dpkg --get selections exists
#-------------------------------------------------------------------------------

fi

Expand Down

0 comments on commit 5f48e21

Please sign in to comment.