vogelchr / radioclkd2

Quick and dirty fork of http://www.jonatkins.com/page/software/radioclkd2 adding Linux GPIO pin support.
19 stars 7 forks source link

systemd #13

Open EwaldvanGeffen opened 8 months ago

EwaldvanGeffen commented 8 months ago

Hi, Just wanted to let you know how I did systemd. Just a suggestion, there might be even more native methods.

root@acerola:~# cat /etc/systemd/system/radioclkd2.service
[Unit]
Description=Radio Clock service
Before=chrony.service

[Service]
EnvironmentFile=/etc/default/radioclkd2
ExecStart=
ExecStart=/usr/local/bin/radioclkd2 $OPTS

[Install]
WantedBy=multi-user.target
Alias=radioclkd2
root@acerola:~# cat /etc/systemd/system/radioclkd2.service.d/set-gpio.conf 
[Service]
ExecStartPre=/usr/local/bin/setgpio.sh 13
root@acerola:~# cat /usr/local/bin/setgpio.sh 
#!/bin/sh
if [ ! -f /sys/class/gpio/gpio$1/value ]; then
  echo $1 > /sys/class/gpio/export 
fi
echo both > /sys/class/gpio/gpio$1/edge

I also adjusted some things in main.c; because I don't want to daemonize for systemd. Maybe there's a better way to integrate into systemd more natively.

root@acerola:~/radioclkd2# git diff
diff --git a/decode_dcf77.c b/decode_dcf77.c
index 132560a..45e7022 100644
--- a/decode_dcf77.c
+++ b/decode_dcf77.c
@@ -156,7 +156,7 @@ dcf77Decode ( clkInfoT* clock, time_f minstart )
        if ( dectime.tm_min > 60 )
                return -1;
        /*                                   year mon  mday     wday hour min  TZ-info-leap-ant */
-       loggerf ( LOGGER_DEBUG, "DCF77 time: %04d-%02d-%02d (day %d) %02d:%02d %s%s%s%s\n",
+       loggerf ( LOGGER_INFO, "DCF77 time: %04d-%02d-%02d (day %d) %02d:%02d %s%s%s%s\n",
                dectime.tm_year+1900, dectime.tm_mon+1, dectime.tm_mday,
                dectime.tm_wday, dectime.tm_hour, dectime.tm_min,
                GET(17) ? "CEST" : "CET", GET(16) ? " timezone change soon":"",
diff --git a/main.c b/main.c
index aab6a9d..a0c8360 100644
--- a/main.c
+++ b/main.c
@@ -390,7 +390,7 @@ main ( int argc, char** argv )
                        loggerSyslog ( 1, LOGGER_DEBUG );
                        break;
                }
-               setDemon();
+               //setDemon();
                setRealtime();
        }
        else
@@ -478,7 +478,7 @@ StartClocks ( serDevT* serdev )
        {
                if ( serWaitForSerialChange ( serdev ) < 0 )
                {
-                       loggerf ( LOGGER_DEBUG, "no serial line change\n" );
+                       loggerf ( LOGGER_INFO, "no serial line change\n" );
                        continue;
                }

diff --git a/shm.c b/shm.c
index 75c42ce..521bef2 100644
--- a/shm.c
+++ b/shm.c
@@ -56,7 +56,7 @@ shmStore ( shmTimeT* volatile shm, time_f radioclock, time_f localrecv, time_f t
 {
        struct timeval radioclocktv,localrecvtv;

-       loggerf ( LOGGER_DEBUG, "shm: storing time "TIMEF_FORMAT" local "TIMEF_FORMAT" err "TIMEF_FORMAT" leap %d\n", radioclock, localrecv, time_err, leap );
+       loggerf ( LOGGER_INFO, "shm: storing time "TIMEF_FORMAT" local "TIMEF_FORMAT" err "TIMEF_FORMAT" leap %d\n", radioclock, localrecv, time_err, leap );

        time_f2timeval ( radioclock, &radioclocktv );
        time_f2timeval ( localrecv, &localrecvtv );

I run 3x https://github.com/beta-tester/RPi-GPS-PPS-StratumOne boxes with radioclkd2 added to it, pics https://imgur.com/a/CLW7pzF