Time Reset Script For Laravel Homestead

Nick Poulos
1 min readJul 31, 2019

--

Vagrant being annoying

Like many others, I’ve had issues keeping my virtual machine time in sync. Ever come back to your VM console, try to run a command, and see something similar to:

{ “error”: “invalid_grant”, “error_description”: “Invalid JWT: Token must be a short-lived token and in a reasonable timeframe”} ?

Then you have too. Other solutions involve configuring your Vagrant file to trigger a re-sync if things get too out of whack, but I have had very inconsistent results using them in practice.

Instead, I prefer running a quick script that will sync the time with NTP on command.

#!/bin/bash
# Forces an ntp update
#
# Based on SO user Martin Schröder's answer to "How to force a clock update
# using ntp?": http://askubuntu.com/a/256004/41943

# Fail fast (set -e will bail at first error)
set -e

if [ "$EUID" -ne 0 ]; then
echo "ERROR: '$0' must be as root."
exit 1
fi

service ntp stop

echo "Running 'ntpd -gq'"
ntpd -gq

service ntp start

https://gist.github.com/nickpoulos/b519f9789ba367c54ca54b5b6b72bdc9

--

--

Nick Poulos
Nick Poulos

No responses yet