weewx Server (multiple instances)
Install, configure and manage multiple instances of weewx using systemd.
2022-03-26 Raspbian buster
This is a guide to setting up multiple instances of weewx on a single Debian server using systemd. The reader is expected to be linux literate.
More accurately, it is a cookbook on how I configure my host to run separate instances of weewx to:
- collect from a Vantage Pro2;
- collect from a GW1000; and
- collect some other inputs, aggregate, and generate consolidated report.
There are several additional requirements that I implement that influence my implementation:
-
weewx instances run as user
weewx
not asroot
; - generated files are placed in ramdisk; and
- no swapping – totally RAM-resident.
Installation
graham:~ sudo apt update graham:~ sudo apt install python3-configobj python3-pil python3-serial \ python3-usb python3-pip python3-cheetah python3-ephem graham:~ wget https://weewx.com/downloads/weewx-4.8.0.tar.gz graham:~ wget https://github.com/gjr80/weewx-gw1000/releases/tag/v0.4.2/gw1000-0.4.2.tar.gz graham:~ sudo adduser weewx # owner of code, instances and processes graham:~ sudo mkdir ~weewx/public_html # ramdisk for generated reports graham:~ sudo chown weewx:weewx ~weewx/public_html graham:~ sudo vi /etc/fstab # mount ramdisk on reboot graham:~ sudo mount -a # mount ramdisk now graham:~ mount | grep tmpfs tmpfs on /run type tmpfs (rw,nosuid,nodev,size=1600104k,nr_inodes=819200,mode=755) tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,size=2097152k) tmpfs on /home/weewx/public_html type tmpfs (rw,nosuid,nodev,noexec,noatime,size=10240k,mode=775,uid=1002,gid=1002)-
Verify
/home/weewx/public_html
is mounted correctly.
- Verify no space allocated to Swap.
-
Verify
weewx.conf
has been moved aside. Now weewx commands must specify the config file using the--config=
option. Good practice: the default will fail.
-
Next login by user
weewx
will pick up environment changes.
Base configuration to support weewx instances
Although all instances run from the same codebase, we keep individual state in files named after the instance inst:
~weewx/inst.conf
-
instance configuration, based upon saved
weewx.conf-dist
~weewx/archive/inst.sdb
- instance database
~weewx/skins/inst/
- instance skin template files, based upon provided Seasons skin for the purpose of this document
~weewx/public_html/inst/
- instance report files generated at run-time
/var/log/weewx/inst.log
- instance log
/run/weewx/inst.pid
- instance PID file
Note that we will designate one weewx instance as the producer of the
official
, consolidated report, but the other instances will produce
smaller reports more specific to them.
For the systemd services, think of weewx@ as a
class
and weewx@foo as an instance
of
that class
.
We install file weewx@.service
to create
the class
as part of our systemd configuration;
we will create instances later.
First weewx instance: vp2 collector
graham:~ sudo -u weewx -i # owner of weewx data weewx:~ cp weewx.conf-dist vp2.conf # start with instance config templateskin
weewx:~ vi vp2.conf weewx:~ cp -r skins/Seasons skins/vp2 # start from Seasons as template skin weewx:~ vi skins/vp2/*- Update the skin files for the reports specific to vp2. This is outside the scope of this document.
database
weewx:~ vi vp2.confThe database is automatically created when instance first runs.
driver
weewx:~ wee_config --config=vp2.conf --reconfigure-
Ensure use correct weewx config file viz.
vp2.conf
. - When prompted, select the Vantage driver.
- It also prompts for a number of vp2 station details (e.g. latitude & longitude), beyond the scope of this document.
log
weewx:~ vi vp2.conf weewx:~ exit # good practice: 'weewx' doesn't sudo graham:~ sudo vi /etc/rsyslog.d/weewx.conf graham:~ sudo vi /etc/logrotate.d/weewx graham:~ sudo systemctl restart rsyslogstart/stop
graham:~ sudo systemctl enable weewx@vp2 # 'create' instance (start after each reboot) graham:~ sudo systemctl start weewx@vp2 # start instance now graham:~ sudo systemctl status weewx@vp2- Verify systemd thinks the instance has started okay.
-
Leave
tail
running until a reporting cycle has completed, which is within 5 minutes, watching for errors. - Verify from log details that reports have been generated without errors.
- Verify expected files have been generated.
Web-browsing to the public_html/vp2/
content
is outside scope of this document.
The vp2 instance can be stopped by:
graham:~ sudo systemctl stop weewx@vp2 # stop instance now graham:~ sudo systemctl disable weewx@vp2 # 'delete' instance (not restart after reboot)Second weewx instance: gw1000 (aka ecowitt) collector
graham:~ sudo -u weewx -i weewx:~ cp weewx.conf-dist gw1000.conf # start from instance config templateskin
weewx:~ vi gw1000.conf weewx:~ cp -r skins/Seasons skins/gw1000 # start from Seasons as template skin weewx:~ vi skins/gw1000/*- Update skin files for collector-specific reports – outside the scope of this document.
database
weewx:~ vi gw1000.confdriver
Unlike Vantage driver, which is part of the weewx distribution, GW1000 driver is an extension. We downloaded it earlier.
weewx:~ wee_extension --config=gw1000.conf --install=/home/graham/gw1000-0.4.1.tar.gz weewx:~ wee_config --config=gw1000.conf --reconfigure- Use correct weewx config file viz.
gw1000.conf
- When prompted, select GW1000 driver.
- Provide station-specific details such as location.
-
The sensor mappings need to be updated by editing
gw1000.conf
. This is outside scope of this document.
log
weewx:~ vi gw1000.conf weewx:~ exit # good practice: 'weewx' doesn't sudo graham:~ sudo vi /etc/rsyslog.d/weewx.conf graham:~ sudo vi /etc/logrotate.d/weewx graham:~ sudo systemctl restart rsyslogstart/stop
graham:~ sudo systemctl enable weewx@gw1000 # 'create' instance (start after each reboot) graham:~ sudo systemctl start weewx@gw1000 # start instance now graham:~ sudo systemctl status weewx@gw1000- Verify that systemd thinks service started properly.
- Monitor for a reporting cycle and verify no errors reported.
- Verify the expected report files have been generated.
The instance can be stopped by:
graham:~ sudo systemctl stop weewx@gw1000 # stop instance now graham:~ sudo systemctl disable weewx@gw1000 # 'delete' instance (not restart after reboot)Third weewx instance: editor aggregator
This instance is primarily to produce the official
, consolidated
report for public consumption on website.
It collates data from the collector weewx instances
and perhaps date from other sources such as forecast
or minor inputs too small to warrant their own collector instance.
This report draws from the databases of several weewx instances:
gw1000_binding
- gw1000 instance database;
vp2_binding
- vp2 instance database;
wx_binding
-
editor instance database – this one, the default binding
wx_binding
skin
weewx:~ vi editor.conf weewx:~ cp -r skins/Seasons skins/editor # start from Seasons as template skin weewx:~ vi skins/editor/*- Update skin files for editor instance-specific reports – outside the scope of this document.
-
Ensure the
HTML_ROOT
is set to top level html directory, not a subdirectory as were the collectors for their subsidiary reports. -
Data is aggregated from the various databases by specifying their
data_binding in the respective tag, where
wx_binding
is the default tag. So, for example, the maximum outside temperature today recorded by the vp2 collector instance, which has data_bindingvp2_binding
ineditor.conf
, is$day(data_binding='vp2_binding').outTemp.max
.
Details of skin and report customisation out of scope for this document.
databases
weewx:~ vi editor.confDriver
Ultimately, something must be injecting observations into
the weewx instance to keep it turning over, though this is independent
of the archive interval
at the end of each of which the reports
are generated.
This can be either a simple subsidiary input with its own driver, or
the reporter instance can be merged into one of the collector instances.
log
weewx:~ vi editor.conf weewx:~ exit # good practice: 'weewx' doesn't sudo graham:~ sudo vi /etc/rsyslog.d/weewx.conf graham:~ sudo vi /etc/logrotate.d/weewx graham:~ sudo systemctl restart rsyslogstart/stop
graham:~ sudo systemctl enable weewx@editor # 'create' instance (start after each reboot) graham:~ sudo systemctl start weewx@editor # start instance now graham:~ sudo systemctl status weewx@editor- Verify that systemd thinks service started properly.
- Monitor for a reporting cycle and verify no errors reported.
- Verify the expected report files have been generated.
-
Verify the files have been placed in
public_html
directory, not in a collector subdirectory.
The instance can be stopped by:
graham:~ sudo systemctl stop weewx@editor # stop it now graham:~ sudo systemctl disable weewx@editor # 'delete' instance (not start after reboot)Finally
Operationally, the weewx collector and aggregator instances can be started and stopped independently.
Semantically, the aggregator instance depends upon sufficiently current data being available in the collector instances databases, so be wary of keeping collectors offline for long while aggregator(s) are running.