Why LXD's errors are not logged in journal by systemd if LXD commands are run by a service?

That’s something weird :slight_smile: . I created a systemd’s service, triggered by a timer, for backing up my instances. The service runs a bash script that runs lxc snapshot, lxc copy etc. I explicitly made the service log everything in the journal:

StandardOutput=journal
StandardError=journal

However, errors returned by LXC commands, for some reason, don’t appear in the journal. If the command failed, the service exists with an error, it’s just the message of the error is not visible in the journal, which is pretty annoying, as you don’t know what exactly failed and why. Do you guys have an idea, what’s going on here? It’s the first time I see something like that. :slight_smile:

This is the script that I’m currently using, but that’s a work in progress:

#!/usr/bin/env bash

RUNNING_HOSTS=($(lxc list status=running -c n --format csv))
STOPPED_HOSTS=($(lxc list status=stopped -c n --format csv))
DATE_FORMAT="%Y-%m-%d_%H-%M-%S"
BACKUP_ERRORS_COUNTER=0

if [ -z ${LXC_BACKUP_REMOTE} ]; then
  echo "LXC_BACKUP_REMOTE enviromental variable is required."
  exit 1
fi

function error() {
  echo "[ERROR]"
  ((BACKUP_ERRORS_COUNTER=BACKUP_ERRORS_COUNTER+1))
}

function backup() {
  lxc copy --refresh ${1} ${2}: || error
}

echo "[BACKUP START]"

# Sync profiles.
PROFILES=($(lxc profile list --format csv | cut -f1 -d,))
for PROFILE in "${PROFILES[@]}"; do
  echo "Backing up profile: ${PROFILE}"
  $(lxc profile show ${PROFILE} | lxc profile edit ${LXC_BACKUP_REMOTE}:${PROFILE}) || error
done

# Sync containers.
for HOST in "${RUNNING_HOSTS[@]}"; do
  echo "Backing up active container: ${HOST}"
  lxc stop ${HOST} || error
  lxc snapshot ${HOST} "snapshot-$(date +"${DATE_FORMAT}")" || error
  backup ${HOST} ${LXC_BACKUP_REMOTE}
  lxc start ${HOST} || error
done

for HOST in "${STOPPED_HOSTS[@]}"
do
  echo "Backing up inactive container: ${HOST}"
  backup ${HOST} ${LXC_BACKUP_REMOTE}
done

FINAL_MESSAGE_PREFIX="[BACKUP RESULT]"

if [ $BACKUP_ERRORS_COUNTER -gt 0 ]; then
  echo "$FINAL_MESSAGE_PREFIX ERRORS: $BACKUP_ERRORS_COUNTER"
  exit 1
  else
  echo "$FINAL_MESSAGE_PREFIX SUCCESS"
  exit 0
fi