Automatic restart 123solar.php

Talks about solar stuff
Post Reply
ginorosi
Posts: 36
Joined: Sun Jun 22, 2014 10:47 pm

Automatic restart 123solar.php

Post by ginorosi » Mon Sep 27, 2021 5:53 pm

Hi, I have a problem:

using 123solar since 2013 on a system with Danfoss TLX , I have adapted rklogger to 123 and it has always worked, every 1 or 2 year reinstall new archlinux on SD with everything updated;
after the last installation , every 3-4 days I a fatal error in the rklogger script and 123solar.php goes to STOP , before it never did .....
is it possible to automatically restart 123solar if STOP every 30 minutes or 10 minutes before sunset , to have at least the total daily energy?
I do not live where I have the system and therefore the stop blocks me then also the following days until I restart from admin.

Thank you

jeanmarc
Posts: 2143
Joined: Thu Aug 29, 2013 7:16 am

Re: Automatic restart 123solar.php

Post by jeanmarc » Wed Sep 29, 2021 4:22 pm

Hi,
I guess rklogger hang for a reason, if you enable debug you should have more hints. Maybe add this in protocol's scripts :

Code: Select all

..
$timeout_setup = 'timeout --kill-after=15s 10s'; // TERM after 10" & KILL after 15"
$a = exec("$timeout_setup rklogger 11 ${'ADR'.$invt_num} 2 28 8");
..  and so on
Another idea is to have a script that kill and clear, if there is a port lock

Code: Select all

#!/usr/bin/php
<?php
// A simple script to clear a stuck com port
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
date_default_timezone_set('Europe/Brussels');
$lockfile = '/var/lock/LCK..sdm';

if (file_exists($lockfile)) {
    $now = time();
    $ft  = filemtime($lockfile);
    if ($now - $ft > 30) { // 30 sec
        exec('pkill -f sdm120c');
        sleep(2);
        if (file_exists($lockfile)) {
            exec("rm -f $lockfile");
        }
    } 
}
?>
Also you can use another script based on boot123s.php that check if it's 123s running. A thing like this (haven't test)

Code: Select all

<?php
if ($_SERVER['SERVER_ADDR'] != '127.0.0.1' && $_SERVER['SERVER_ADDR'] != '::1') {
	die('Direct access not permitted');
}

define('checkaccess', TRUE);
include '../config/config_main.php';
date_default_timezone_set($DTZ);
$DATADIR = dirname(dirname(__FILE__)) . '/data/';
$pid    = null;
$now    = date($DATEFORMAT . ' H:i:s');

if (!file_exists('123solar.pid')) {
	exec('pkill -f 123solar.php> /dev/null 2>&1 &'); // make sure there is only one instance
	usleep(500000);
	$command    = 'php 123solar.php' . ' > /dev/null 2>&1 & echo $!;';
	$pid        = exec($command);
	file_put_contents('123solar.pid', $pid);
	$stringData = "#* $now\tRestarting 123Solar ($pid)\n\n";
	
	for ($i = 1; $i <= $NUMINV; $i++) {
	$INVTDIR    = $DATADIR . "invt$i/";
	$stringData .= file_get_contents($INVTDIR . 'infos/events.txt');
	file_put_contents($INVTDIR . 'infos/events.txt', $stringData);
	}
} else { // Runs
}
?>
You can start thoses scripts with systemd timers.

ginorosi
Posts: 36
Joined: Sun Jun 22, 2014 10:47 pm

Re: Automatic restart 123solar.php

Post by ginorosi » Wed Sep 29, 2021 9:58 pm

Hello,
I enabled debugging, rklogger does not crash, rklogger fails to read a data and with this version of PHP it becomes a fatal error which is then passed from rklogger.php into 123solar.php and blocks 123, perhaps first the non-reading or the wrong data it was a venial mistake, I don't think that in 7-8 years of operation Rklogger has always read the data perfectly, thanks
then I'll read you exactly the error that appears in debug, now I don't have the text.
and I try your script, I just have to test every 30 'if it is running and if anything, restart it
bye

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests