systemd: require NTP sync Announcing the arrival of Valued Associate #679: Cesar Manara ...

How does the math work when buying airline miles?

Why are my pictures showing a dark band on one edge?

An adverb for when you're not exaggerating

Did any compiler fully use 80-bit floating point?

How many morphisms from 1 to 1+1 can there be?

How to compare two different files line by line in unix?

Can a sorcerer use careful spell on himself?

Is there hard evidence that the grant peer review system performs significantly better than random?

What does Turing mean by this statement?

1-probability to calculate two events in a row

Random body shuffle every night—can we still function?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

How do living politicians protect their readily obtainable signatures from misuse?

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

Semigroups with no morphisms between them

How does light 'choose' between wave and particle behaviour?

AppleTVs create a chatty alternate WiFi network

What is the meaning of 'breadth' in breadth first search?

How much damage would a cupful of neutron star matter do to the Earth?

How many time has Arya actually used Needle?

What does 丫 mean? 丫是什么意思?

What is an "asse" in Elizabethan English?

Significance of Cersei's obsession with elephants?

Misunderstanding of Sylow theory



systemd: require NTP sync



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionWhy do I get this at the end of a `last` command?Make systemd reload only single openvpn process and not the whole groupAdding a systemd .service (Debian)Why is systemd stopping service immediately after it is started?Systemd irregular timing issueInstruct to execute an unit after completing another unit successfullysystemd: finish the execution of custom shell script before starting nginxScript handling systemd service's return codeNTP time sync takes a long timeStopping systemd unit together with another. Starting worksSystemd Unit File - WantedBy and After





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5















What should I put in my unit file to ensure my service starts AFTER the time is set via ntp?



I have a raspberry pi with a small python script that logs data to a SQL data base. Since the rpi doesn't have an RTC battery, on startup or without an internet connection, the time and data are wrong. To avoid misleading timestamps in the database, the script should run after the correct time is acquired.



My unit file so far:



[Unit]
Description=desc
Requires=mysql.service
After=syslog.target mysql.service

[Service]
Type=simple
ExecStart= /usr/bin/python3 /etc/script/script.py
SyslogIdentifier=test
StandardOutput=null
StandardError=syslog
Restart=always
RestartSec=5
User=pi

[Install]
WantedBy=multi-user.target


How should I modify my unit file?



My systemd version is:



#> systemctl --version
systemd 232









share|improve this question




















  • 1





    No, i'm stuck with what i've got for now.

    – Marvin Noll
    Apr 3 at 12:29






  • 1





    a RTC battery is roughly 2 euros in aliexpress.

    – Rui F Ribeiro
    Apr 3 at 13:58











  • I don't have a raspberry pi distro to test against; my initiali instinct is to order mysql after ntp; is that sufficient?

    – Jeff Schaller
    Apr 3 at 20:11











  • @RuiFRibeiro is a Raspberry PI. It does not have a RTC clock at all. It's a module that is sold separately and need to be plugged in (Real Time Clock RTC DS3231 GPIO Module).

    – user34720
    Apr 3 at 20:13






  • 1





    @RuiFRibeiro thats cool. shame on my country that has lot of taxes so, importing hardware is a pain :P

    – user34720
    Apr 4 at 10:48


















5















What should I put in my unit file to ensure my service starts AFTER the time is set via ntp?



I have a raspberry pi with a small python script that logs data to a SQL data base. Since the rpi doesn't have an RTC battery, on startup or without an internet connection, the time and data are wrong. To avoid misleading timestamps in the database, the script should run after the correct time is acquired.



My unit file so far:



[Unit]
Description=desc
Requires=mysql.service
After=syslog.target mysql.service

[Service]
Type=simple
ExecStart= /usr/bin/python3 /etc/script/script.py
SyslogIdentifier=test
StandardOutput=null
StandardError=syslog
Restart=always
RestartSec=5
User=pi

[Install]
WantedBy=multi-user.target


How should I modify my unit file?



My systemd version is:



#> systemctl --version
systemd 232









share|improve this question




















  • 1





    No, i'm stuck with what i've got for now.

    – Marvin Noll
    Apr 3 at 12:29






  • 1





    a RTC battery is roughly 2 euros in aliexpress.

    – Rui F Ribeiro
    Apr 3 at 13:58











  • I don't have a raspberry pi distro to test against; my initiali instinct is to order mysql after ntp; is that sufficient?

    – Jeff Schaller
    Apr 3 at 20:11











  • @RuiFRibeiro is a Raspberry PI. It does not have a RTC clock at all. It's a module that is sold separately and need to be plugged in (Real Time Clock RTC DS3231 GPIO Module).

    – user34720
    Apr 3 at 20:13






  • 1





    @RuiFRibeiro thats cool. shame on my country that has lot of taxes so, importing hardware is a pain :P

    – user34720
    Apr 4 at 10:48














5












5








5


1






What should I put in my unit file to ensure my service starts AFTER the time is set via ntp?



I have a raspberry pi with a small python script that logs data to a SQL data base. Since the rpi doesn't have an RTC battery, on startup or without an internet connection, the time and data are wrong. To avoid misleading timestamps in the database, the script should run after the correct time is acquired.



My unit file so far:



[Unit]
Description=desc
Requires=mysql.service
After=syslog.target mysql.service

[Service]
Type=simple
ExecStart= /usr/bin/python3 /etc/script/script.py
SyslogIdentifier=test
StandardOutput=null
StandardError=syslog
Restart=always
RestartSec=5
User=pi

[Install]
WantedBy=multi-user.target


How should I modify my unit file?



My systemd version is:



#> systemctl --version
systemd 232









share|improve this question
















What should I put in my unit file to ensure my service starts AFTER the time is set via ntp?



I have a raspberry pi with a small python script that logs data to a SQL data base. Since the rpi doesn't have an RTC battery, on startup or without an internet connection, the time and data are wrong. To avoid misleading timestamps in the database, the script should run after the correct time is acquired.



My unit file so far:



[Unit]
Description=desc
Requires=mysql.service
After=syslog.target mysql.service

[Service]
Type=simple
ExecStart= /usr/bin/python3 /etc/script/script.py
SyslogIdentifier=test
StandardOutput=null
StandardError=syslog
Restart=always
RestartSec=5
User=pi

[Install]
WantedBy=multi-user.target


How should I modify my unit file?



My systemd version is:



#> systemctl --version
systemd 232






systemd ntp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 3 at 20:08









Jeff Schaller

45.1k1164147




45.1k1164147










asked Apr 3 at 10:21









Marvin NollMarvin Noll

262




262








  • 1





    No, i'm stuck with what i've got for now.

    – Marvin Noll
    Apr 3 at 12:29






  • 1





    a RTC battery is roughly 2 euros in aliexpress.

    – Rui F Ribeiro
    Apr 3 at 13:58











  • I don't have a raspberry pi distro to test against; my initiali instinct is to order mysql after ntp; is that sufficient?

    – Jeff Schaller
    Apr 3 at 20:11











  • @RuiFRibeiro is a Raspberry PI. It does not have a RTC clock at all. It's a module that is sold separately and need to be plugged in (Real Time Clock RTC DS3231 GPIO Module).

    – user34720
    Apr 3 at 20:13






  • 1





    @RuiFRibeiro thats cool. shame on my country that has lot of taxes so, importing hardware is a pain :P

    – user34720
    Apr 4 at 10:48














  • 1





    No, i'm stuck with what i've got for now.

    – Marvin Noll
    Apr 3 at 12:29






  • 1





    a RTC battery is roughly 2 euros in aliexpress.

    – Rui F Ribeiro
    Apr 3 at 13:58











  • I don't have a raspberry pi distro to test against; my initiali instinct is to order mysql after ntp; is that sufficient?

    – Jeff Schaller
    Apr 3 at 20:11











  • @RuiFRibeiro is a Raspberry PI. It does not have a RTC clock at all. It's a module that is sold separately and need to be plugged in (Real Time Clock RTC DS3231 GPIO Module).

    – user34720
    Apr 3 at 20:13






  • 1





    @RuiFRibeiro thats cool. shame on my country that has lot of taxes so, importing hardware is a pain :P

    – user34720
    Apr 4 at 10:48








1




1





No, i'm stuck with what i've got for now.

– Marvin Noll
Apr 3 at 12:29





No, i'm stuck with what i've got for now.

– Marvin Noll
Apr 3 at 12:29




1




1





a RTC battery is roughly 2 euros in aliexpress.

– Rui F Ribeiro
Apr 3 at 13:58





a RTC battery is roughly 2 euros in aliexpress.

– Rui F Ribeiro
Apr 3 at 13:58













I don't have a raspberry pi distro to test against; my initiali instinct is to order mysql after ntp; is that sufficient?

– Jeff Schaller
Apr 3 at 20:11





I don't have a raspberry pi distro to test against; my initiali instinct is to order mysql after ntp; is that sufficient?

– Jeff Schaller
Apr 3 at 20:11













@RuiFRibeiro is a Raspberry PI. It does not have a RTC clock at all. It's a module that is sold separately and need to be plugged in (Real Time Clock RTC DS3231 GPIO Module).

– user34720
Apr 3 at 20:13





@RuiFRibeiro is a Raspberry PI. It does not have a RTC clock at all. It's a module that is sold separately and need to be plugged in (Real Time Clock RTC DS3231 GPIO Module).

– user34720
Apr 3 at 20:13




1




1





@RuiFRibeiro thats cool. shame on my country that has lot of taxes so, importing hardware is a pain :P

– user34720
Apr 4 at 10:48





@RuiFRibeiro thats cool. shame on my country that has lot of taxes so, importing hardware is a pain :P

– user34720
Apr 4 at 10:48










1 Answer
1






active

oldest

votes


















0














Since it appears that raspbian use timesyncd, I would adjust your unit file to depend on that target:



[Unit]
Description=desc
Requires=mysql.service
After=syslog.target mysql.service systemd-timesyncd
# ^^^ the addition ^^^

[Service]
Type=simple
...


If you've disabled timesyncd in favor of ntp, then substitute the NTP service name.



It appears that newer (239+) systemd versions support a time-sync service which sounds more useful, as it waits until the clock has been synchronized, versus just the beginning of the sync process.



If a short startup time isn't critical, and you find that your service is still startinb before the time has been sync'd, you may find it sufficient to add a brief delay in your service's startup with an ExecStartPre:



...
ExecStartPre=sleep 30
...


Adjust the sleep time based on experimentation with the time it reliably takes your pi to sync the time.






share|improve this answer
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f510252%2fsystemd-require-ntp-sync%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Since it appears that raspbian use timesyncd, I would adjust your unit file to depend on that target:



    [Unit]
    Description=desc
    Requires=mysql.service
    After=syslog.target mysql.service systemd-timesyncd
    # ^^^ the addition ^^^

    [Service]
    Type=simple
    ...


    If you've disabled timesyncd in favor of ntp, then substitute the NTP service name.



    It appears that newer (239+) systemd versions support a time-sync service which sounds more useful, as it waits until the clock has been synchronized, versus just the beginning of the sync process.



    If a short startup time isn't critical, and you find that your service is still startinb before the time has been sync'd, you may find it sufficient to add a brief delay in your service's startup with an ExecStartPre:



    ...
    ExecStartPre=sleep 30
    ...


    Adjust the sleep time based on experimentation with the time it reliably takes your pi to sync the time.






    share|improve this answer




























      0














      Since it appears that raspbian use timesyncd, I would adjust your unit file to depend on that target:



      [Unit]
      Description=desc
      Requires=mysql.service
      After=syslog.target mysql.service systemd-timesyncd
      # ^^^ the addition ^^^

      [Service]
      Type=simple
      ...


      If you've disabled timesyncd in favor of ntp, then substitute the NTP service name.



      It appears that newer (239+) systemd versions support a time-sync service which sounds more useful, as it waits until the clock has been synchronized, versus just the beginning of the sync process.



      If a short startup time isn't critical, and you find that your service is still startinb before the time has been sync'd, you may find it sufficient to add a brief delay in your service's startup with an ExecStartPre:



      ...
      ExecStartPre=sleep 30
      ...


      Adjust the sleep time based on experimentation with the time it reliably takes your pi to sync the time.






      share|improve this answer


























        0












        0








        0







        Since it appears that raspbian use timesyncd, I would adjust your unit file to depend on that target:



        [Unit]
        Description=desc
        Requires=mysql.service
        After=syslog.target mysql.service systemd-timesyncd
        # ^^^ the addition ^^^

        [Service]
        Type=simple
        ...


        If you've disabled timesyncd in favor of ntp, then substitute the NTP service name.



        It appears that newer (239+) systemd versions support a time-sync service which sounds more useful, as it waits until the clock has been synchronized, versus just the beginning of the sync process.



        If a short startup time isn't critical, and you find that your service is still startinb before the time has been sync'd, you may find it sufficient to add a brief delay in your service's startup with an ExecStartPre:



        ...
        ExecStartPre=sleep 30
        ...


        Adjust the sleep time based on experimentation with the time it reliably takes your pi to sync the time.






        share|improve this answer













        Since it appears that raspbian use timesyncd, I would adjust your unit file to depend on that target:



        [Unit]
        Description=desc
        Requires=mysql.service
        After=syslog.target mysql.service systemd-timesyncd
        # ^^^ the addition ^^^

        [Service]
        Type=simple
        ...


        If you've disabled timesyncd in favor of ntp, then substitute the NTP service name.



        It appears that newer (239+) systemd versions support a time-sync service which sounds more useful, as it waits until the clock has been synchronized, versus just the beginning of the sync process.



        If a short startup time isn't critical, and you find that your service is still startinb before the time has been sync'd, you may find it sufficient to add a brief delay in your service's startup with an ExecStartPre:



        ...
        ExecStartPre=sleep 30
        ...


        Adjust the sleep time based on experimentation with the time it reliably takes your pi to sync the time.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Jeff SchallerJeff Schaller

        45.1k1164147




        45.1k1164147






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f510252%2fsystemd-require-ntp-sync%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...