Skip to content

Commit

Permalink
always start weewx on new install. on an upgrade, only start weewx if…
Browse files Browse the repository at this point in the history
… it was running before the upgrade. ignore systemd presets.
  • Loading branch information
matthewwall committed Jul 4, 2024
1 parent b01e628 commit 8d5116d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
1 change: 1 addition & 0 deletions pkg/changelog.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* Wed Jul 04 2024 Matthew Wall <mwall.weewx@gmail.com> - 5.1.0b5-2
- fix bug in the instance count
- ignore systemd presets
* Wed Jul 03 2024 Matthew Wall <mwall.weewx@gmail.com> - 5.1.0b5-1
- new upstream release
- use systemd presets
Expand Down
1 change: 1 addition & 0 deletions pkg/changelog.suse
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* Wed Jul 04 2024 Matthew Wall <mwall.weewx@gmail.com> - 5.1.0b5-2
- fix bug in the instance count
- ignore systemd presets
* Wed Jul 03 2024 Matthew Wall <mwall.weewx@gmail.com> - 5.1.0b5-1
- new upstream release
- use systemd presets
Expand Down
31 changes: 19 additions & 12 deletions pkg/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ setup_init() {
-e "s/Group=.*/Group=${WEEWX_GROUP}/" \
/etc/weewx/systemd/$f > $dst/$f
done
systemctl daemon-reload > /dev/null || true
systemctl daemon-reload > /dev/null 2>&1 || true
fi
elif [ "$1" = "sysv" ]; then
echo "Installing SysV rc script"
Expand Down Expand Up @@ -463,19 +463,23 @@ migrate_extensions() {
fi
}

# we explicitly do *not* pay attention to the systemd.preset, since that
# just causes unnecessary confusion, for example between presets for a
# server or workstation configuration, or even from one version of systemd
# to another. just always enable weewx.
enable_weewxd() {
echo "Enabling startup using $1"
if [ "$1" = "systemd" ]; then
cfgs=$2
if [ "$cfgs" = "" ]; then
systemctl enable weewx > /dev/null || true
systemctl enable weewx > /dev/null 2>&1 || true
else
for i in $cfgs; do
systemctl enable weewx@$i > /dev/null || true
systemctl enable weewx@$i > /dev/null 2>&1 || true
done
fi
elif [ "$1" = "sysv" ]; then
update-rc.d weewx defaults > /dev/null || true
update-rc.d weewx defaults > /dev/null 2>&1 || true
fi
}

Expand All @@ -484,27 +488,27 @@ start_weewxd() {
if [ "$1" = "systemd" ]; then
cfgs=$2
if [ "$cfgs" = "" ]; then
systemctl start weewx > /dev/null || true
systemctl start weewx > /dev/null 2>&1 || true
else
for i in $cfgs; do
systemctl start weewx@$i > /dev/null || true
systemctl start weewx@$i > /dev/null 2>&1 || true
done
fi
elif [ "$1" = "sysv" ]; then
invoke-rc.d weewx start > /dev/null || true
invoke-rc.d weewx start > /dev/null 2>&1 || true
fi
}

# just in case there is an old weewxd running somehow, shut it down. this is
# normally not necessary, since the prerm for prior version does a shutdown.
stop_old_weewxd() {
if [ -f /etc/init.d/weewx-multi ]; then
invoke-rc.d weewx-multi stop > /dev/null || true
invoke-rc.d weewx-multi stop > /dev/null 2>&1 || true
fi
if [ "$1" = "systemd" ]; then
systemctl stop weewx > /dev/null || true
systemctl stop weewx > /dev/null 2>&1 || true
elif [ "$1" = "sysv" ]; then
invoke-rc.d weewx stop > /dev/null || true
invoke-rc.d weewx stop > /dev/null 2>&1 || true
fi
}

Expand Down Expand Up @@ -533,8 +537,9 @@ case "$1" in
configure)
num_weewxd=1
if [ "$2" != "" ]; then
# this is an upgrade so ensure that weewxd is not running
# this is an upgrade, so see if weewx is already running
num_weewxd=$(count_instances)
# this is an upgrade so ensure that weewxd is not running
stop_old_weewxd $pid1
fi
get_user_info
Expand Down Expand Up @@ -564,7 +569,9 @@ case "$1" in
setup_init $pid1
enable_weewxd $pid1
if [ $num_weewxd -gt 0 ]; then
start_weewxd $pid1
# if this is a new install, start weewx no matter what. if this
# is an upgrade, start weewx only if it was running before.
start_weewxd $pid1
fi
;;

Expand Down
15 changes: 11 additions & 4 deletions pkg/weewx.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,18 @@ migrate_extensions() {
fi
}

# we explicitly do *not* pay attention to the systemd.preset, since that
# just causes unnecessary confusion, for example between presets for a
# server or workstation configuration, or even from one version of systemd
# to another. just always enable weewx.
enable_weewxd() {
if [ "$1" = "systemd" ]; then
cfgs=$2
if [ "$cfgs" = "" -o "$cfgs" = "weewx" ]; then
systemctl preset weewx > /dev/null 2>&1 || :
systemctl enable weewx > /dev/null 2>&1 || :
else
for i in $cfgs; do
systemctl preset weewx@$i > /dev/null 2>&1 || :
systemctl enable weewx@$i > /dev/null 2>&1 || :
done
fi
fi
Expand All @@ -393,7 +397,7 @@ start_weewxd() {
stop_old_weewxd() {
if [ "$1" = "systemd" ]; then
if [ -f /etc/init.d/weewx-multi ]; then
service stop weewx-multi 2>&1 || :
service stop weewx-multi > /dev/null 2>&1 || :
fi
systemctl stop weewx > /dev/null 2>&1 || :
fi
Expand All @@ -420,8 +424,9 @@ echo "Using $WEEWX_USER:$WEEWX_GROUP as user:group"
# default to running an instance of weewxd
num_weewxd=1
if [ $1 -gt 1 ]; then
# this is an upgrade, so ensure that weewx is not running
# this is an upgrade, so see if weewx is already running
num_weewxd=$(count_instances)
# this is an upgrade, so ensure that weewx is not running
stop_old_weewxd $pid1
fi
setup_defaults $pid1
Expand All @@ -448,6 +453,8 @@ set_config_permissions
setup_init $pid1
enable_weewxd $pid1
if [ $num_weewxd -gt 0 ]; then
# if this is a new install, start weewx no matter what. if this
# is an upgrade, start weewx only if it was running before.
start_weewxd $pid1
fi

Expand Down

0 comments on commit 8d5116d

Please sign in to comment.