PM2 - Process Manager 2 and WeeWX

318 views
Skip to first unread message

garrya...@gmail.com

unread,
Mar 28, 2021, 2:11:53 PM3/28/21
to weewx-user
PM2 (https://pm2.keymetrics.io/) is a process manager often associated with node.js apps written in Java Script. It can also manage processes written in Python (see: https://pm2.io/blog/2018/09/19/Manage-Python-Processes).

I was not able to get PM2 working with WeeWX - has anyone got it going?

I was able to get the example 'hello.py' script working.

When I tried 'sudo pm2 start /home/weewx/bin/weewxd' I got the following error (viewed using 'sudo pm2 logs'):

1|weewxd  | /home/weewx/bin/weewxd:2
1|weewxd  | #
1|weewxd  | ^
1|weewxd  | SyntaxError: Invalid or unexpected token
1|weewxd  |     at Module._compile (internal/modules/cjs/loader.js:723:23)
1|weewxd  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
1|weewxd  |     at Module.load (internal/modules/cjs/loader.js:653:32)
1|weewxd  |     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
1|weewxd  |     at Function.Module._load (internal/modules/cjs/loader.js:585:3)
1|weewxd  |     at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
1|weewxd  |     at Module._compile (internal/modules/cjs/loader.js:778:30)
1|weewxd  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
1|weewxd  |     at Module.load (internal/modules/cjs/loader.js:653:32)
1|weewxd  |     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
PM2       | App [weewxd:1] exited with code [1] via signal [SIGINT]
PM2       | Script /home/weewx/bin/weewxd had too many unstable restarts (16). Stopped. "errored"

I suspected that was because PM2 uses the file extension to determine the script language so I changed the name of 'weewxd' to 'weewxd.py'.  Things progressed a little further but I got:

/root/.pm2/logs/weewxd-out.log last 15 lines:
/root/.pm2/logs/weewxd-error.log last 15 lines:
0|weewxd   |   File "/home/weewx/bin/weewxd.py", line 20, in <module>
0|weewxd   |     import configobj
0|weewxd   | ImportError: No module named configobj
0|weewxd   | Traceback (most recent call last):
0|weewxd   |   File "/home/weewx/bin/weewxd.py", line 20, in <module>
0|weewxd   |     import configobj
0|weewxd   | ImportError: No module named configobj
0|weewxd   | Traceback (most recent call last):
0|weewxd   |   File "/home/weewx/bin/weewxd.py", line 20, in <module>
0|weewxd   |     import configobj
0|weewxd   | ImportError: No module named configobj
0|weewxd   | Traceback (most recent call last):
0|weewxd   |   File "/home/weewx/bin/weewxd.py", line 20, in <module>
0|weewxd   |     import configobj
0|weewxd   | ImportError: No module named configobj

I assume that WeeWx is starting up but the Python interpreter can't find the file for the the import, so perhaps something needs to be tweaked in PATH?  I don't want to change anything in that area with advice.

Starting/stopping WeeWX with '/etc/init.d/weewx' works perfectly.

Regards and thanks in advance,

Garry


Tom Keffer

unread,
Mar 28, 2021, 2:18:24 PM3/28/21
to weewx-user
I don't know anything about PM2, but it would be useful to know where you're trying to get. Weewx is extremely stable and can literally run for years without rebooting. If it is crashing, it would be better to fix that problem, rather than use a process manager.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/830dc248-93ad-489e-b4d8-d2169332a318n%40googlegroups.com.

Garry A Lockyer

unread,
Mar 28, 2021, 2:30:29 PM3/28/21
to weewx...@googlegroups.com
Totally agree with your comments.

I’m trying to handle network and remote server issues for a station I don’t have remote access to, and sometimes (depending on time of year) have to wait a few days before I can go onsite.  So I am trying to handle conditions external to WeeWX.

One issue is Raspberry Pi OS “wlan0 carrier lost problem” (see https://www.raspberrypi.org/forums/viewtopic.php?t=233847 for a conversation).

Even if I fix each problem as they arise, I’d like to have a “belts & suspenders” backup solution.

Regards,

Garry Lockyer
E: Ga...@Lockyer.ca


On Mar 28, 2021, at 11:18, Tom Keffer <tke...@gmail.com> wrote:



tomn...@frontier.com

unread,
Mar 28, 2021, 4:03:52 PM3/28/21
to weewx-user
Hi Gary,  esp. in a remote location like that, can you use ethernet instead of wi-fi?  I ran into a similar problem recently with an RPi-zero that was losing wi-fi, even though it's right across the room with nothing in between.  From what I found researching solutions, in some cases, it takes a reboot to recover.  In any case, I ended up writing a script that will try the 2-3 non-boot things to recover wi-fi, and reboot when all else fails.  I can share it, but it's got a few dependencies...
Not positive it works, since the device seems to have stayed up since I set it up in cron, and I haven't checked the system logs.  There were a couple of other minor things I updated related to some boot warnings
with wi-fi.

Chris

vince

unread,
Mar 28, 2021, 4:05:27 PM3/28/21
to weewx-user
See if https://github.com/vinceskahan/raspi-odds-and-ends/blob/master/netmon.sh helps you any for trying to self-heal your wifi.  I haven't run it in years since I fixed my home wifi setup by switching to Ubiquiti gear and essentially out-radiating the badly configured neighbors, but it used to work for me.   Probably needs a little tweaking for modern Raspbian but it should be self-evident.

I wouldn't run pm2 for what you're trying to do.  Maybe supervisord but even that is way overkill.   Personally I'd do it in bash called periodically from crontab if you can figure out a way to tell when (if) you need to touch weewx at all.

garrya...@gmail.com

unread,
Apr 2, 2021, 1:09:33 PM4/2/21
to weewx-user
Sorry for late response.

Using a RPi Zero W so no chance to use wire.  In fact, virtually no chance to make any changes to network at remote site.

Regards,

Garry

garrya...@gmail.com

unread,
Apr 2, 2021, 1:12:12 PM4/2/21
to weewx-user
Thanks for the advice.  I will forego using PM2, or any other process manager, at this time, and give "netmon.sh" a try.

But!  Re: "if you can figure out a way to tell when (if) you need to touch weewx at all."  that's why I was hoping to use something like PM2 'casue it seems to me they figured it out.

Regards,

Garry

vince

unread,
Apr 2, 2021, 1:18:22 PM4/2/21
to weewx-user
In the absence of a detailed description of your setup, what problem you are trying to solve, and why you think you need to touch weewx at all after it starts up, there's nothing we can do to help you here.    You're jumping to a conclusion that you have to touch something, but you've given us no data to understand what you're seeing at all.


p q

unread,
Apr 2, 2021, 1:21:17 PM4/2/21
to weewx...@googlegroups.com
Off on a tangent...

Not impossible to use wired internet with a Pi Zero. You just need a USB to Ethernet dongle. https://www.amazon.com/AmazonBasics-USB-Ethernet-Network-Adapter/dp/B00M77HLII
I don't have this one exactly, but a similar one. For my application I needed a USB adaptor from the micro B on the Zero to a full size Type A Female and then to a USB hub and then to the adaptor, because I needed more than one USB. But it works fine that way. 



--
Peter Quinn
(415)794-2264

Garry A Lockyer

unread,
Apr 2, 2021, 1:32:45 PM4/2/21
to weewx...@googlegroups.com
You of course are correct!  Adding a USB dongle would also mean adding a USB hub so a nice “small box with only Davis console connection” becomes more grand.  Not impossible but not something I want to do.


Regards,

Garry Lockyer
E: Ga...@Lockyer.ca


On Apr 2, 2021, at 10:21, p q <peterq...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages