--
You received this message because you are subscribed to the Google Groups "Weewx user's group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I thought I would give something back to the group since I have gotten good help to my questions. I have created a Python utility script that can be ran periodically (cron?) to check if weewx is running and if it is not, it will send out an email with a number of lines from the end of the log (/var/log/messages, or whatever log you want) that would show the error that weewx encountered. The script will try to restart weex a number of pre configurable times, in case the error was a fluke rather than a fatal one.The script will stop trying to send messages after it has reached the indicated restarts times in the configuration times, and you will need to delete the flagFile that has been created. (or write a 0 in it). The script has a configurable log rotation, where you can indicate the log rotation interval (in days) and the days of logs to keep.logOutput is the temporary tail of the messages log (or could be the syslog or whatever you specify) that will be emailed as an attachment if weewx is found not to be running.I hope everyone finds this somewhat useful. If you are somewhat paranoid about your weather station being up 24/7 like me then you probably will. :-)Questions and comments are welcome.
#configuration file for checking routine[mail]fromaddr=us...@gmail.comtoaddr=toU...@gmail.commsgSubj=weewx process is not runningbody=weewx process is not running. Please check the attached log and address the issue
userName=gmailuserName@gmail.com
password=yourPwdsmtpServer=smtp.gmail.com:587[logging]logDir=/home/user/scriptslogFile=checkWeewx.loglogOutput=tail.loglinesToTail=200logToTail=/var/log/messageslogRotationDayInterval=1logDaysToKeep=5[weewx]#how many times to try and restart the weewx processrestarts=3flagLogDir=/home/user/scriptsflagFile=weewxNotRunning.txtstartCommand=sudo /etc/init.d/weewx startYou can launch the script by typing: Python ./checkWeewx.py /pathToConfigFile/checkWeewx.configThe configuration format:
#configuration file for checking routine[mail]fromaddr=us...@gmail.comtoaddr=toU...@gmail.commsgSubj=weewx process is not runningbody=weewx process is not running. Please check the attached log and address the issue
userName=gmailuserName@gmail.com
--
You received this message because you are subscribed to the Google Groups "Weewx user's group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi, hi,The sudo implies you have this in your own / non-root crontab. Is that correct?If instead, you use "sudo crontab -e" so root is calling your script, then you can omit the sudo in the script. That much alone may be the solution to your problem.
Meanwhile, you didn't say what OS you're running, but on newer systems, those RC / init.d scripts are often presented via legacy wrappers for use by systemctl. In that case the systemctl mechanism for restarting the service might be less susceptible to foreground vs. background / disconnected usage. Meaning where you are using "sudo /etc/init.d/weewx start" from command-line and it works, but doesn't work from cron, substituting the systemctl equivalent may be a way out.You could try these from command line to verify your system has the legacy RC / init.d wrappers, then substitute the the "sudo systemctl start weewx" of calling the init.d script directly...Here again, however, putting any of these in a script that runs from the root crontab will avoid needing to prefix with sudo...# Check status:$ sudo systemctl status weewx# Restart$ sudo systemctl restart weewx# Stop$ sudo systemctl stop weewx# Start
$ sudo systemctl start weewxRegards,Leon--Leon Shaner :: Dearborn, Michigan (iPad Pro)
--I got this running as a cronjob, and I get a mail when weewx is not running when the cronjob is executed. But I don't get the script to start weewx again.This is the last part of checkweewx.config:[weewx]
#how many times to try and restart the weewx process
restarts=3
flagLogDir=/home/pliggen/scripts
flagFile=weewxNotRunning.txt
startCommand=sudo /etc/init.d/weewx startIf I run /etc/init.d/weewx start in terminal it starts.Any tips where to check to get this working?
Den söndag 11 oktober 2015 kl. 02:45:50 UTC+2 skrev Constantine Samaklis:The script file and configuration file can be anywhere you want.You can launch the script by typing: python <path>/checkWeewx.py <path>/checkWeewx.configThere are no changes required in the weewx.conf. You will need to just fill the pertinent information for your setup in checkWeewx.config as it is the configuration file that drives the python script.
On Saturday, October 10, 2015 at 5:22:12 PM UTC-4, Arild Halvorsen wrote:This looks exciting. How do I implement this solution in weewx? Where do I put the files. Which information is nødvenidig in weewx.conf?
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx...@googlegroups.com.
and thanks for the help! I was running my own non-root crontab. So I tried to put the command in sudo crontab -e.
Stopped the service and tried it and now the service started as expected. Great! And it worked with /etc/init.d/weewx start as startcommand.
I'm not sure I understood everything you wrote, I'm quite new at this, but you made it clear what to try.
One more question, it seems that when I run it via sudo crontab there were some issue with the logging,
hade to remove home/pliggen/scripts from the "logDir=" line.
Got this email message:
sh: 1: cannot create /home/pliggen/scripts//var/log/syslog.txt: Directory nonexistent
Starting program...
Traceback (most recent call last):
File "/var/www/html/scripts/checkWeewx/checkWeewx.py", line 159, in <module>
sendMailFailure(logDir + "/" + logOutput, config, additionalText)
File "/var/www/html/scripts/checkWeewx/checkWeewx.py", line 86, in sendMailFailure
f = file(filename)
IOError: [Errno 2] No such file or directory: '/home/pliggen/scripts//var/log/syslog.txt'
So I removed the logDir file-path so it looks like this now:
[logging]
logDir=
logFile=checkWeewx.log
logOutput=/var/log/syslog.txt
linesToTail=200
logToTail=/var/log/messages
logRotationDayInterval=1
logDaysToKeep=5
And now I get this message in the email when the cronjob runs if the service is stopped:
sh: echo: I/O error
sh: echo: I/O error
Starting program...
It doesn't matter as long as the service now seems to start but if you see something obvious I'm glad to hear!
Thanks, and sorry for my bad english.
You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/9yskDGu9vI0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
BR Mikael
--
You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/9yskDGu9vI0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/3e10898a-5ec9-4ee1-b4ea-aceb85e8602ao%40googlegroups.com.