WeeWXv5.1.0: Devuan, init script: Logging to weewx file

37 views
Skip to first unread message

Glenn McKechnie

unread,
Aug 28, 2024, 3:41:30 AM8/28/24
to weewx-user
I'm running a pip install of WeeWx v5.1.0 under a Devuan (daedalus) installation on a raspberry pi 4 (Finally upgraded ! ?)
Devauan is one of the last SysV systems around so, Yes,  this is an edge case.

Trying to get the rsylog redirection working fails miserably and as it turns out it's because %programname% under rsyslog is showing up as root. That's because the weewx (and weewx-multi) scripts are using $LOGNAME as the --log-label within the script. This defaults to the $USER that is running the script getting the credit and their name is being used as the programname by rsyslog.

The small fix required for the init scripts to log the programname field correctly (or usefully) can be achieved by using the value of $INSTANCE  which is already available under /etc/default/weewx or weewx-multi files as $WEEWX_INSTANCES eg:-

WEEWX_INSTANCES="weatherpi weewx"

/etc/init.d/weewx and /etc/init.d/weewx-multi need one change each...
[...]
do_start() {
    INSTANCE=$1
    PROCNAME=$(get_procname $INSTANCE)
    PIDFILE=$WEEWX_RUNDIR/$PROCNAME.pid
    CFGFILE=$WEEWX_CFGDIR/$INSTANCE.conf
    DAEMON_ARGS="--daemon --log-label=$INSTANCE --pidfile=$PIDFILE $CFGFILE
[...]
That last line was originally as follows and needs the --log-label string changing...
    DAEMON_ARGS="--daemon --log-label=$LOGNAME --pidfile=$PIDFILE $CFGFILE

I tested this using /etc/init.d/weewx and/etc/init.d/weewx-multi and it now works as expected.  ie:- the following /etc/rsyslog.d/weewx.conf now works.

$template WEEWX_LOGFILE,"/var/log/weewx/%programname%.log"
if $programname startswith 'wee' then ?WEEWX_LOGFILE
:programname,startswith,"wee" stop
if $programname startswith 'wea' then ?WEEWX_LOGFILE
:programname,startswith,"wea" stop

On a related note
The timestamps used in the default Devuan rsyslog installation are overkill. If you don't need microsecond accounting, but do need the screen real estate they take up then tey the following...

Copy the following text to the top of rsyslog.conf (assuming no other $ActionFileDefaultTemplate exists) .  YMMV but it worked for me.(and no wordwrap is allowed - that's two lines only)

$template TraditionalFormat,"%timegenerated% %HOSTNAME% %syslogtag%%msg:::drop-last-lf%\n"
$ActionFileDefaultTemplate TraditionalFormat


cheers
 Glenn
Reply all
Reply to author
Forward
0 new messages