upstart script to start a task after hardware clock has been started

142 views Asked by At

I have a process that tries to make an SSL connection after start up, but that fails if the clock has not yet been set (the dates don't match the effective dates on the certificates). Is it possible to configure upstart to only start the process after the internal clock is set?

The default setting for the clock is 2010-01-01, so perhaps something like date >= 2014 is sufficient (obviously not legit upstart syntax, but the concept holds).

The best I could figure out was to start up after NTP has started, but that doesn't necessarily mean the clock has been set as the network connection establishment may be delayed or not available for a while.

2

There are 2 answers

1
Michael R. On

The simple solution is probably to just poll the date and wait 500ms or whatever before trying again if the date isn't sane yet.

0
Tim Tisdall On

Here's what I ended up doing:

start on started connman
stop on runlevel [016]

script
        YEAR=$(date +'%Y')
        until [ $YEAR -ge "2014" ]; do
                sleep 5
                YEAR=$(date +'%Y')
        done
        python access_point.py
end script

I wait until the connection manager is running and then I check the year every 5 seconds until the year is 2014 or greater.