From df67c38959cd3eaf45e04d298cc7b3e2d779af9c Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Sat, 2 Dec 2023 10:23:03 -0500 Subject: [PATCH] added a parameterixed unit that inherits from the standard unit. use system config files from pkg directory instead of trying to match/adapt those in weewx_data/util, which serve different purpose. --- pkg/debian/rules | 22 +++--------- pkg/etc/default/weewx | 4 +++ .../weewx.debian => pkg/etc/logrotate.d/weewx | 0 pkg/etc/systemd/system/weewx.service | 19 +++++++++++ pkg/etc/systemd/system/weewx@.service | 13 +++++++ pkg/etc/udev/rules.d/weewx.rules | 34 +++++++++++++++++++ pkg/weewx.spec.in | 33 ++++++------------ src/weewx_data/util/logrotate.d/weewx.redhat | 9 ----- 8 files changed, 86 insertions(+), 48 deletions(-) create mode 100644 pkg/etc/default/weewx rename src/weewx_data/util/logrotate.d/weewx.debian => pkg/etc/logrotate.d/weewx (100%) create mode 100644 pkg/etc/systemd/system/weewx.service create mode 100644 pkg/etc/systemd/system/weewx@.service create mode 100644 pkg/etc/udev/rules.d/weewx.rules delete mode 100644 src/weewx_data/util/logrotate.d/weewx.redhat diff --git a/pkg/debian/rules b/pkg/debian/rules index 7ab03978..598e2220 100755 --- a/pkg/debian/rules +++ b/pkg/debian/rules @@ -62,12 +62,9 @@ install: # copy selected ancillary files to the config dir cp -r $(SRC)/src/weewx_data/examples $(DST_CFGDIR) cp -r $(SRC)/src/weewx_data/skins $(DST_CFGDIR) - cp -r $(SRC)/src/weewx_data/util/apache $(DST_CFGDIR) cp -r $(SRC)/src/weewx_data/util/import $(DST_CFGDIR) - cp -r $(SRC)/src/weewx_data/util/logrotate.d $(DST_CFGDIR) cp -r $(SRC)/src/weewx_data/util/logwatch $(DST_CFGDIR) cp -r $(SRC)/src/weewx_data/util/rsyslog.d $(DST_CFGDIR) - cp -r $(SRC)/src/weewx_data/util/udev $(DST_CFGDIR) # create the default configuration cat $(SRC)/src/weewx_data/weewx.conf | sed \ @@ -82,15 +79,8 @@ install: # create the system init configuration # FIXME: if no systemd, then install sysV script - cat $(SRC)/src/weewx_data/util/systemd/weewx.service | sed \ - -e 's%ExecStart=.*%ExecStart=/usr/bin/weewxd --daemon --pidfile=/run/weewx/weewxd.pid /etc/weewx/weewx.conf%' \ - -e 's%#Type=.*%Type=forking%' \ - -e 's%#RuntimeDirectory=.*%RuntimeDirectory=weewx%' \ - -e 's%#RuntimeDirectoryMode=.*%RuntimeDirectoryMode=775%' \ - -e 's%#PIDFile=.*%PIDFile=/run/weewx/weewxd.pid%' \ - -e 's%#User=weewx%User=weewx%' \ - -e 's%#Group=weewx%Group=weewx%' \ - > $(DST)/lib/systemd/system/weewx.service + cp $(SRC)/pkg/systemd/system/weewx.service $(DST)/lib/systemd/system + cp $(SRC)/pkg/systemd/system/weewx@.service $(DST)/lib/systemd/system # create the entry points for f in $(ENTRIES); do \ @@ -98,17 +88,15 @@ install: done # the defaults file indicates which python and weewx to use - cat $(SRC)/src/weewx_data/util/default/weewx | sed \ + cat $(SRC)/pkg/etc/default/weewx | sed \ -e 's%WEEWX_PYTHON=.*%WEEWX_PYTHON=$(PYTHON)%' \ - -e 's%WEEWX_BINDIR=.*%WEEWX_BINDIR=/usr/share/weewx%' \ - -e 's%WEEWX_CFG=.*%WEEWX_CFG=/etc/weewx/weewx.conf%' \ > $(DST)/etc/default/weewx # install logrotate configuration - cp $(SRC)/src/weewx_data/util/logrotate.d/weewx.debian $(DST)/etc/logrotate.d/weewx + cp $(SRC)/pkg/etc/logrotate.d/weewx $(DST)/etc/logrotate.d # put the udev rules in place - cp $(SRC)/src/weewx_data/util/udev/rules.d/weewx.rules $(DST)/lib/udev/rules.d + cp $(SRC)/pkg/etc/udev/rules.d/weewx.rules $(DST)/lib/udev/rules.d # additional debian control files that dpkg-buildpackage seems to ignore mkdir -p $(DST)/DEBIAN diff --git a/pkg/etc/default/weewx b/pkg/etc/default/weewx new file mode 100644 index 00000000..f03ede80 --- /dev/null +++ b/pkg/etc/default/weewx @@ -0,0 +1,4 @@ +WEEWX_PYTHON=python3 +WEEWX_PYTHON_ARGS= +WEEWX_BINDIR=/usr/share/weewx +WEEWX_CFG=/etc/weewx/weewx.conf diff --git a/src/weewx_data/util/logrotate.d/weewx.debian b/pkg/etc/logrotate.d/weewx similarity index 100% rename from src/weewx_data/util/logrotate.d/weewx.debian rename to pkg/etc/logrotate.d/weewx diff --git a/pkg/etc/systemd/system/weewx.service b/pkg/etc/systemd/system/weewx.service new file mode 100644 index 00000000..754c8db9 --- /dev/null +++ b/pkg/etc/systemd/system/weewx.service @@ -0,0 +1,19 @@ +# unit file for WeeWX + +[Unit] +Description=WeeWX weather system +Documentation=https://weewx.com/docs +Requires=time-sync.target +After=time-sync.target + +[Service] +ExecStart=weewxd --daemon --pidfile /run/weewx/weewxd.pid /etc/weewx/weewx.conf +Type=forking +RuntimeDirectory=weewx +RuntimeDirectoryMode=775 +PIDFile=/run/weewx/weewxd.pid +User=weewx +Group=weewx + +[Install] +WantedBy=multi-user.target diff --git a/pkg/etc/systemd/system/weewx@.service b/pkg/etc/systemd/system/weewx@.service new file mode 100644 index 00000000..7a6e5f24 --- /dev/null +++ b/pkg/etc/systemd/system/weewx@.service @@ -0,0 +1,13 @@ +# unit file for WeeWX named instance +# +# Inherit the standard weewx service settings, then make them unique for a +# specific instance of the WeeWX daemon. + +.include /lib/systemd/system/weewx.service + +[Service] +ExecStart=weewxd --daemon --pidfile /run/weewx/weewxd-%i.pid --log-label weewx-%i /etc/weewx/weewx-%i.conf +PIDFile=/run/weewx/weewxd-%i.pid + +[Install] +WantedBy=multi-user.target diff --git a/pkg/etc/udev/rules.d/weewx.rules b/pkg/etc/udev/rules.d/weewx.rules new file mode 100644 index 00000000..2b8fe73c --- /dev/null +++ b/pkg/etc/udev/rules.d/weewx.rules @@ -0,0 +1,34 @@ +# udev rules for hardware recognized by weewx +# +# copy this file to /etc/udev/rules.d +# sudo udevadm control --reload-rules +# unplug then replug the USB device + +# make any acurite station connected via usb accessible to non-root +SUBSYSTEM=="usb",ATTRS{idVendor}=="24C0",ATTRS{idProduct}=="0003",MODE="0664",GROUP="weewx" + +# make any fine offset station connected via usb accessible to non-root +SUBSYSTEM=="usb",ATTRS{idVendor}=="1941",ATTRS{idProduct}=="8021",MODE="0664",GROUP="weewx" + +# make any te923 station connected via usb accessible to non-root +SUBSYSTEM=="usb",ATTRS{idVendor}=="1130",ATTRS{idProduct}=="6801",MODE="0664",GROUP="weewx" + +# make any oregon scientific wmr100 connected via usb accessible to non-root +SUBSYSTEM=="usb",ATTRS{idVendor}=="0FDE",ATTRS{idProduct}=="CA01",MODE="0664",GROUP="weewx" + +# make any oregon scientific wmr200 connected via usb accessible to non-root +SUBSYSTEM=="usb",ATTRS{idVendor}=="0FDE",ATTRS{idProduct}=="CA01",MODE="0664",GROUP="weewx" + +# make any oregon scientific wmr300 connected via usb accessible to non-root +SUBSYSTEM=="usb",ATTRS{idVendor}=="0FDE",ATTRS{idProduct}=="CA08",MODE="0664",GROUP="weewx" + +# make any ws28xx transceiver connected via usb accessible to non-root +SUBSYSTEM=="usb",ATTRS{idVendor}=="6666",ATTRS{idProduct}=="5555",MODE="0664",GROUP="weewx" + +# make any rainwise cc3000 connected via usb-serial accessible to non-root +# and make a symlink +SUBSYSTEM=="tty",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6001",MODE="0664",GROUP="weewx",SYMLINK+="cc3000" + +# make any davis vantage connected via usb-serial accessible to non-root +# and make a symlink +SUBSYSTEM=="tty",ATTRS{idVendor}=="10c4",ATTRS{idProduct}=="ea60",MODE="0664",GROUP="weewx",SYMLINK+="vantage" diff --git a/pkg/weewx.spec.in b/pkg/weewx.spec.in index c81857a1..04a34f2c 100644 --- a/pkg/weewx.spec.in +++ b/pkg/weewx.spec.in @@ -60,7 +60,7 @@ %global relnum RPMREVISION %global release %{relnum}%{?relos:%{relos}} -%global dst_bin_dir %{_datadir}/%{name} +%global dst_code_dir %{_datadir}/%{name} %global dst_cfg_dir %{_sysconfdir}/%{name} %global dst_user_dir %{dst_cfg_dir}/bin/user %global cfg_file %{dst_cfg_dir}/weewx.conf @@ -94,7 +94,7 @@ PWSweather.com, or CWOP. %install rm -rf %{buildroot} mkdir -p %{buildroot}%{_bindir} -mkdir -p %{buildroot}%{dst_bin_dir} +mkdir -p %{buildroot}%{dst_code_dir} mkdir -p %{buildroot}%{dst_cfg_dir} mkdir -p %{buildroot}%{dst_user_dir} mkdir -p %{buildroot}/etc/default @@ -111,7 +111,7 @@ cp docs_src/copyright.md %{buildroot}/usr/share/weewx-doc/copyright cp LICENSE.txt %{buildroot}/usr/share/weewx-doc/license # copy the weewx code -cp -r src/* %{buildroot}%{dst_bin_dir} +cp -r src/* %{buildroot}%{dst_code_dir} # create the user extensions directory cp src/weewx_data/bin/user/__init__.py %{buildroot}%{dst_user_dir} @@ -120,12 +120,9 @@ cp src/weewx_data/bin/user/extensions.py %{buildroot}%{dst_user_dir} # copy the ancillary files to the correct location cp -r src/weewx_data/examples %{buildroot}%{dst_cfg_dir} cp -r src/weewx_data/skins %{buildroot}%{dst_cfg_dir} -cp -r src/weewx_data/util/apache %{buildroot}%{dst_cfg_dir} cp -r src/weewx_data/util/import %{buildroot}%{dst_cfg_dir} -cp -r src/weewx_data/util/logrotate.d %{buildroot}%{dst_cfg_dir} cp -r src/weewx_data/util/logwatch %{buildroot}%{dst_cfg_dir} cp -r src/weewx_data/util/rsyslog.d %{buildroot}%{dst_cfg_dir} -cp -r src/weewx_data/util/udev %{buildroot}%{dst_cfg_dir} # create the weewx configuration cat src/weewx_data/weewx.conf | sed \ @@ -139,15 +136,8 @@ cat src/weewx_data/weewx.conf | sed \ cp %{buildroot}%{dst_cfg_dir}/weewx.conf %{buildroot}%{dst_cfg_dir}/weewx.conf.dist # create the init configuration -cat src/weewx_data/util/systemd/weewx.service | sed \ - -e 's%ExecStart=.*%ExecStart=/usr/bin/weewxd --daemon --pidfile=/run/weewx/weewxd.pid /etc/weewx/weewx.conf%' \ - -e 's%#Type=.*%Type=forking%' \ - -e 's%#RuntimeDirectory=.*%RuntimeDirectory=weewx%' \ - -e 's%#RuntimeDirectoryMode=.*%RuntimeDirectoryMode=775%' \ - -e 's%#PIDFile=.*%PIDFile=/run/weewx/weewxd.pid%' \ - -e 's%#User=weewx%User=weewx%' \ - -e 's%#Group=weewx%Group=weewx%' \ - > %{buildroot}/lib/systemd/system/weewx.service +cp pkg/etc/systemd/system/weewx.service %{buildroot}/lib/systemd/system +cp pkg/etc/systemd/system/weewx@.service %{buildroot}/lib/systemd/system # create the entry points for f in %{entry_points}; do \ @@ -155,17 +145,15 @@ for f in %{entry_points}; do \ done # configure defaults -cat src/weewx_data/util/default/weewx | sed \ +cat pkg/etc/default/weewx | sed \ -e 's%WEEWX_PYTHON=.*%WEEWX_PYTHON=%{python}%' \ - -e 's%WEEWX_BINDIR=.*%WEEWX_BINDIR=/usr/share/weewx%' \ - -e 's%WEEWX_CFG=.*%WEEWX_CFG=/etc/weewx/weewx.conf%' \ > %{buildroot}/etc/default/weewx # logrotate script -cp src/weewx_data/util/logrotate.d/weewx.redhat %{buildroot}/etc/logrotate.d/weewx +cp pkg/etc/logrotate.d/weewx %{buildroot}/etc/logrotate.d # udev rules for known devices -cp src/weewx_data/util/udev/rules.d/weewx.rules %{buildroot}/lib/udev/rules.d +cp pkg/etc/udev/rules.d/weewx.rules %{buildroot}/lib/udev/rules.d %pre @@ -182,7 +170,7 @@ fi %post # pre-compile the python code -%{python} -m compileall %{dst_bin_dir} +%{python} -m compileall %{dst_code_dir} if [ "$1" = "1" ]; then # this is a new installation # create a sane configuration file with simulator as the station type @@ -228,8 +216,9 @@ rm -rf %{buildroot} %{_bindir}/weewxd %{_bindir}/weectl /lib/systemd/system/weewx.service +/lib/systemd/system/weewx@.service /lib/udev/rules.d/weewx.rules -%{dst_bin_dir}/ +%{dst_code_dir}/ %doc /usr/share/weewx-doc %config(noreplace) %{_sysconfdir}/default/weewx %config(noreplace) %{_sysconfdir}/logrotate.d/weewx diff --git a/src/weewx_data/util/logrotate.d/weewx.redhat b/src/weewx_data/util/logrotate.d/weewx.redhat deleted file mode 100644 index c4393a7b..00000000 --- a/src/weewx_data/util/logrotate.d/weewx.redhat +++ /dev/null @@ -1,9 +0,0 @@ -/var/log/weewx/*.log { - weekly - missingok - rotate 4 - compress - delaycompress - copytruncate - notifempty -}