Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: PH Heartbeat Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
renard
Groupie
Groupie
Avatar

Joined: November 01 2009
Location: United States
Online Status: Offline
Posts: 72
Posted: July 31 2022 at 15:48 | IP Logged Quote renard

I have upgraded to beta5 and still have the issues with PLM resets and triggers getting missed during the countdown but I also have another problem. Perhaps every two or so weeks, PH just dies. There is no issue with Windows, PH just stops running. There is no indication in the PH log of a problem, it just stops with a final unrelated routine entry and disappears.

I have a remote reboot facility that allow me to restart the PC from anywhere with Internet service but I was wondering if there is anything about PH that I can test programmatically that indicates it is running, a heartbeat. I can have a process running on Windows that checks for the heartbeat and restarts PH if it dies. PH is part of our security system and failing can cause security-issues such as leaving our security lights on during the day. Thoughts are welcome.

__________________
Terry
Back to Top View renard's Profile Search for other posts by renard
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: August 01 2022 at 16:05 | IP Logged Quote gg102

renard:

I also have noticed that sometimes PH does just quit without warning. It just seems to go away; no warning, no errors. For me, it only happens once every month or three. To
handle this issue, I wrote a little Python program to check every 30 seconds if PH is running, and if it is NOT, it will relaunch it and send me a text message. You can ignore
those routines if you prefer.

If you speak Python this might help, if not, nevermind.

You'll need a Python-2-exe conversion program.

I tried to post the code here, but some additional codes get added to the code.
If you want, please respond, and I'll make a temp email account and send the code to ya.

Back to Top View gg102's Profile Search for other posts by gg102
 
renard
Groupie
Groupie
Avatar

Joined: November 01 2009
Location: United States
Online Status: Offline
Posts: 72
Posted: August 01 2022 at 16:53 | IP Logged Quote renard

Thanks gg,

I can also write a C++ program to do it. What are you testing? Checking if a file (the log?) is locked, examining some Registry item, or something else. If I have no joy with the C++, I'll come back to you for the Python.

I did some looking and check this script out:

While True
If (ProcessExists("pwrhome.exe") = 0) Then
    Run("pwrhome.exe")
EndIf
Sleep(1000)
Wend

from:

https://superuser.com/questions/1045703/automatically-check- if-a-program-is-still-running-if-not-start-it


__________________
Terry
Back to Top View renard's Profile Search for other posts by renard
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: August 01 2022 at 17:15 | IP Logged Quote gg102

I never thought about checking if the database was locked. That's a clever and simple idea Though, I don't know if the database might remain locked if PH
terminates. Your method is much simpler.


In my code, the process that looks for PH is: check_if_process_running(process_name).


This is the routine in Python to check if the process is still running:


# Imports
import   sys,os
import   datetime
from     datetime import date
from     datetime import datetime
import   time

import   psutil   #process utilities
import   requests # URL requests for emergency turn off in case it runs too long

#Defines
my_process_name        = "pwrhome.exe"
my_process_relaunch_name= "e:\powerhome\pwrhome.exe"
check_interval_time     = 30



def check_if_process_running(process_name):
    #Iterate over the all the running process...
    for proc in psutil.process_iter():
        try:
             # Check if process name contains the given name string.
             if ( process_name.lower() in proc.name().lower() ):
                return( True )
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
             pass
    return( False )
#
# and the main program loop
if (__name__ == '__main__'):

    print("Check if PH is running. " )
    write_log_file("Started Ckecking PH running: " + time.strftime('%m/%d/%Y %H:%M:%S') +".\n" )
    time.sleep(60)
    while(True):
        if ( check_if_process_running( my_process_name) ):
             #print("PH is running. " + time.strftime('%m/%d/%Y %H:%M:%S') )
             time.sleep(1)
        else:
             my_current_time = datetime.now()
             if ( ( my_current_time.hour > 21 ) or ( my_current_time.hour < 6 ) ):
                print("Night mode, don't send text message.")
                write_log_file("Night mode, don't send text message." )
             else:
                print("Send text message.")
                send_email(toaddr, fromaddr, "KEEP PH Running", "Restarted PH: " + time.strftime('%m/%d/%Y %H:%M:%S') )
             #
             print("PH has stopped, relaunching it.")
             write_log_file("Restarted PH: " + time.strftime('%m/%d/%Y %H:%M:%S') +".\n" )
             os.startfile(my_process_relaunch_name)
             #subprocess.call('notepad.exe')

        time.sleep(check_interval_time)
        #
    #
Back to Top View gg102's Profile Search for other posts by gg102
 
renard
Groupie
Groupie
Avatar

Joined: November 01 2009
Location: United States
Online Status: Offline
Posts: 72
Posted: August 01 2022 at 18:24 | IP Logged Quote renard

Thanks gg,

The simple script that I found needs to be run under Powershell and needs elevated rights. Not a real problem but just a complication. Your solution is very elegantly done and well documented. Let me see of the locking db test works but looking for the active process is even better since it makes the unknown DB or Log files locking processes irrelevant.

__________________
Terry
Back to Top View renard's Profile Search for other posts by renard
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: August 12 2022 at 12:36 | IP Logged Quote gg102

Dave,

I may have accidentally captured something related to this topic. I was doing some network changes, and I unplugged my
network from the PH server. During that time, I noticed PH had disappeared. I reconnected the network, and restarted PH.
Sometime during that process I got 32 of these messages seemingly from several macros.
Looks interesting.

Here's part of the log:





This was the very first error:




I'm just sharing what I might have captured.


Back to Top View gg102's Profile Search for other posts by gg102
 
jeffw_00
Super User
Super User


Joined: June 30 2007
Online Status: Offline
Posts: 929
Posted: September 03 2022 at 15:09 | IP Logged Quote jeffw_00

I have PH writing a "heartbeat" file to windows every few minutes, and
an independent perl script that checks the file date every few minutes.
If the file is too old, it terminates and restarts PH (this prevents against
"hung" PH as well as "missing" PH).
Back to Top View jeffw_00's Profile Search for other posts by jeffw_00
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: September 06 2022 at 12:54 | IP Logged Quote gg102

You know....

Three of us have independently identified the same issue. We have each figured out different viable solutions to solve/handle this issue.

Seems that this might be a real "thing" for Dave to investigate, but I know this will be almost impossible to find. When I was adjusting my network, I got "Execution
Queue" issues as I identified above (sorry for the jumbo size picture). I would assume that's a pretty critical problem and outside what I can test/fix.
Either way, it's way above my pay grade.

Maybe we all have something in common.
What I'm wondering is how can we give Dave a path to investigate? What can we identify that might help him?

I'll start. In my app I have:
over 500 macros and 11,000 total lines of code.
I have a whole lot of timed events with various auto-adaptable times like sunrise/sunset some with +/-.
I have a lot of triggers.
I use FILEMON to monitor about 20 files. (and there's a bug in this)
I have a vary extensive CC/RCC that update live.
I use a few remaining X10 devices and mostly now I use Shelly WiFi devices that I control with ph_geturl1()
I don't have any Insteon or other devices.
I call ph_run() a lot. Like 5-10 times a minute to ping lots of external devices.
I occasionally use ph_ping1().
My machine is a headless configuration with tons of available RAM. LAN not WiFi.
I use speech and sendmail (for texting)
I run PH on a ramdisk Drive-E, not drive-C.

Can anyone else add anything that might shead a little more light on this to help Dave?

Thanks.


Back to Top View gg102's Profile Search for other posts by gg102
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: January 17 2024 at 13:04 | IP Logged Quote gg102

So the good news is that I have NOT PH just disappear for
over a year now. Perhaps the new version fixed something.
Maybe MS fixed something in Windows or who knows, but the
result is that now, PH runs and runs and runs.

Perhaps others have noticed the same.

This is good.


Back to Top View gg102's Profile Search for other posts by gg102
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum