Un fichier log pour Domoticz

Du forum il est remonté (merci beaucoup à José) une manip pour activer un log texte de Domoticz.

Nous avions, jusque là, la trace, dans le menu « Configuration » et « Log » uniquement, pas pratique à lire.

Mais depuis les versions > 2025  il y à la possibilité d’avoir un log texte et de le configurer.

Configuration

Tout ce passe dans le fichier de lancement de Domoticz situé dans /etc/init.d

Si comme moi votre fichier /etc/init.d/domoticz.sh  ne ressemblait pas à celui ci-dessous, faites une copie du fichier d’origine quelque part, puis collez la version ci-dessous à la place ou le lien ici

Attention : Si vous avez introduit des particularités propres à vous (activation de GPIO, changement d’états de GPIO, et que sais-je encore) pensez à les recopier dans le nouveau domoticz.sh

Arrêtons Domoticz par un sudo /etc/init.d/domoticz.sh stop

Mettons à jour ce fichier domoticz.sh comme ceci

#! /bin/sh
### BEGIN INIT INFO
# Provides:          domoticz
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Home Automation System
# Description:       This daemon will start the Domoticz Home Automation System
### END INIT INFO

# Do NOT "set -e"

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DESC="Domoticz Home Automation System"
NAME=domoticz
USERNAME=pi
DAEMON=/home/$USERNAME/domoticz/$NAME
#DAEMON_ARGS="-daemon -www 8080 -log /tmp/domoticz.txt"
#DAEMON_ARGS="-daemon -www 8080 -syslog"
DAEMON_ARGS="-daemon -www 8080"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
        # Return
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
        start-stop-daemon --chuid $USERNAME --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
                || return 1
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
                $DAEMON_ARGS \
                || return 2
}

#
# Function that stops the daemon/service
#
do_stop()
{
        # Return
        #   0 if daemon has been stopped
        #   1 if daemon was already stopped
        #   2 if daemon could not be stopped
        #   other if a failure occurred
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
        RETVAL="$?"
        [ "$RETVAL" = 2 ] && return 2
        # Wait for children to finish too if this is a daemon that forks
        # and if the daemon is only ever run from this initscript.
        # If the above conditions are not satisfied then add some other code
        # that waits for the process to drop all resources that could be
        # needed by services started subsequently.  A last resort is to
        # sleep for some time.
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
        [ "$?" = 2 ] && return 2
        # Many daemons don't delete their pidfiles when they exit.
        rm -f $PIDFILE
        return "$RETVAL"
}

case "$1" in
  start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        do_start
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        do_stop
        case "$?" in
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
        ;;
  status)
        status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
        ;;
  restart)
        log_daemon_msg "Restarting $DESC" "$NAME"
        do_stop
        case "$?" in
          0|1)
                do_start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; # Old process is still running
                        *) log_end_msg 1 ;; # Failed to start
                esac
                ;;
          *)
                # Failed to stop
                log_end_msg 1
                ;;
        esac
        ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
        exit 3
        ;;
esac

:

En haut  du fichier on a 3 lignes intéressantes, celles avec DAEMON_ARGS =

DAEMON=/home/$USERNAME/domoticz/$NAME
#DAEMON_ARGS="-daemon -www 8080 -log /tmp/domoticz.txt"
#DAEMON_ARGS="-daemon -www 8080 -syslog"
DAEMON_ARGS="-daemon -www 8080"

Par défaut on utilise -www 8080, mais en commentant cette ligne par un # et en décommentant soit celle avec domoticz.txt soit celle avec syslog on écrira soit dans le fichier /tmp/domoticz.txt soit dans les logs linux (il ne s’agit pas de /var/log/messages ni de var/log/syslog, mais je n’ai pas trouvé ou cela écrit, si quelqu’un sait…).

l’option -log /tmp/domoticz.txt peut bien sur être modifiée pour utiliser le chemin à votre convenance.

On relance Domoticz par un /etc/init.d/domoticz.start

Et donc le log dans le fichier txt ressemble à cela :

cat /tmp/domoticz.txt

Tue Oct 21 16:06:02 2014 Domoticz V2.2066 (c)2012-2014 GizMoCuz
Tue Oct 21 16:06:02 2014 System: Raspberry Pi
Tue Oct 21 16:06:02 2014 Startup Path: /home/pi/domoticz/
Tue Oct 21 16:06:04 2014 1-Wire support available (By Kernel)...
Tue Oct 21 16:06:04 2014 1-Wire: Using Kernel...
Tue Oct 21 16:06:04 2014 1Wire: Added Device: 28-001411cb7aff
Tue Oct 21 16:06:04 2014 1Wire: Added Device: 28-001411e05dff
Tue Oct 21 16:06:04 2014 1Wire: Added Device: 28-0014145523ff
Tue Oct 21 16:06:04 2014 1Wire: Added Device: 28-001411d077ff
Tue Oct 21 16:06:04 2014 Webserver started on port: 8080
Tue Oct 21 16:06:04 2014 Camera: settings (re)loaded
Tue Oct 21 16:06:06 2014 Teleinfo: Using serial port: /dev/ttyUSB20

N’oubliez pas de repasser en mode « sans log » au risque de remplir votre SD card rapidement. 😥

 

Voila une astuce bien sympathique, qui nous dépannera et merci encore à José

 

 

 

Pour toute question technique concernant cet article, veuillez utiliser les forum situés à https://easydomoticz.com/forum/
Posted in domoticz, linux, raspberry and tagged , , , .