From a67b05a197f1e47c23c2ed882bc9026e8186468e Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Sat, 9 Mar 2024 11:04:12 -0600 Subject: [PATCH] Fix abbey-core/files/, abbey-weather/templates/, README.html. Fix the first abbey-core/files/ src block so that it :mkdirp yes. Remove abbey-weather/template/ daemon script, which is no longer tangled, replaced by abbey-weather/files/daemon-anoat. Update README.html. --- README.org | 2 +- .../abbey-weather/templates/weather-daemon.j2 | 176 ------------------ 2 files changed, 1 insertion(+), 177 deletions(-) delete mode 100644 roles_t/abbey-weather/templates/weather-daemon.j2 diff --git a/README.org b/README.org index 332bac1..e7c50d7 100644 --- a/README.org +++ b/README.org @@ -1030,7 +1030,7 @@ includes yet another version, ~abbey_pisensors~, that reports any recognizable temperature in the ~sensors~ output. #+CAPTION: =roles_t/abbey-core/files/abbey_pisensors= -#+BEGIN_SRC sh :tangle roles_t/abbey-core/files/abbey_pisensors +#+BEGIN_SRC sh :tangle roles_t/abbey-core/files/abbey_pisensors :mkdirp yes #!/bin/sh PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" diff --git a/roles_t/abbey-weather/templates/weather-daemon.j2 b/roles_t/abbey-weather/templates/weather-daemon.j2 deleted file mode 100644 index dc8f19a..0000000 --- a/roles_t/abbey-weather/templates/weather-daemon.j2 +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/perl -w -# -*- CPerl -*- -# -# Weather/daemon -# -# Fetches data from the local owserver once per minute. Appends to -# Log/YEAR/MONTH/DAY.txt. - -use strict; -use IO::File; -use Date::Format; - -sub mysystem (@) -{ - if (system (@_) != 0) { - my $status = $?; - my $sig = $status & 127; - my $CMD = join ", ", map { "\"$_\"" } @_; - if ($status == -1) { - die "Failed to execute: $CMD: $!\n"; - } - elsif ($sig) { - $! = 1; - die "Died with signal $sig: $CMD\n"; - } - else { - return $status >> 8; - } - } - return 0; -} - -sub mybacktick ($) -{ - my ($cmdline) = @_; - - my @lines = `$cmdline`; - my $status = $?; - my $sig = $status & 127; - $status >>= 8; - if ($status == 0) { return @lines; } - elsif ($sig) { - $! = 1; - die "Died with signal $sig: $cmdline\n"; - } - else { - die "Failed to execute: $cmdline: $!\n"; - } -} - -sub mymkdir ($) -{ - my ($dirpath) = @_; - - my @path_names = split /\//, $dirpath; - my $path; - if (!$path_names[0]) { - $path = "/"; - shift @path_names; - } else { - $path = "."; - } - my @created; - while (@path_names) { - $path .= "/" . shift @path_names; - if (! -d $path) { - if (-e $path) { - die "mkdir $dirpath: already exists; not a directory!\n"; - } - if (! mkdir $path) { - die "mkdir $path: $!\n"; - } else { - chmod 02775, $path; - push @created, $path; - } - } - } - return @created; -} - -my $LOG; -my $ymd = ""; -sub reopen_log ($$$) -{ - my ($year, $month, $day) = @_; - my $new_ymd = "$year/$month/$day"; - return if $new_ymd eq $ymd; - close $LOG if defined $LOG; - umask 07; - mymkdir "$year/$month"; - umask 027; - my $filename = "$new_ymd.txt"; - $LOG = new IO::File; - open $LOG, ">>$filename" or die "Could not open $filename: $!\n"; - $ymd = $new_ymd; -} - -my $hostname; -sub sensor_name ($) -{ - my ($num) = @_; - if ($hostname eq "carida") { - my $name = ("pool")[$num]; - return $name; - } - elsif ($hostname eq "dathomir") { - my $name = ("inside", "outside")[$num]; - warn "Bogus sensor number ($num) for host $hostname.\n" if !$name; - return $name; - } - warn "Bogus hostname: $hostname\n"; - return undef; -} - -sub owread ($$) -{ - my ($name, $query) = @_; - - my $tries = 0; - while ($tries < 3) { - my $time = time; - my $datime = time2str ("%Y-%m-%d %H:%M:%S", $time, "UTC"); - my ($y, $m, $d) = $datime =~ /^(\d{4})-(\d\d)-(\d\d) /; - reopen_log $y, $m, $d; - $tries += 1; - my @lines = `/usr/bin/owread $query`; - chomp @lines; - my $status = $?; - my $sig = $status & 127; - $status >>= 8; - if ($status != 0) { - my $L = join "\\n", @lines; - print $LOG "$datime\t$name\terror: status $status: $L\n"; - $LOG->flush; - } elsif (@lines != 1) { - my $L = join "\\n", @lines; - print $LOG "$datime\t$name\terror: multiple lines: $L\n"; - $LOG->flush; - } elsif ($lines[0] !~ /^ *(-?\d+(\.\d+)?)$/) { - my $L = $lines[0]; - print $LOG "$datime\t$name\terror: bogus line: $L\n"; - $LOG->flush; - } else { - my $datum = $1; - print $LOG "$datime\t$name\t$datum\n"; - $LOG->flush; - return; - } - } -} - -sub main () { - $hostname = `hostname`; - chomp $hostname; - die "usage: $0\n" if @ARGV != 0; - $0 = "weatherd"; - chdir "/home/monkey/Weather/Log" or die; - umask 027; - my $start = time; - { - my $secs = 60 - $start % 60; - $start += $secs; - sleep ($secs); - } - while (1) { - owread "T", "{{ owread_path }}temperature"; - owread "H", "{{ owread_path }}HIH4000/humidity"; - $start += 60; - my $now = time; - while ($start < $now) { $start += 60; } - my $secs = $start - $now; - sleep ($secs); - } -} - -main; -- 2.25.1