Bash Script – Test Veeam Linux Agent Socket and Restart Service if Needed

I recently started using the full version of Veeam Backup & Replication (Build 11.01.1261) in a corporate production environment and was kind of shocked to find that the Veeam Agent for Linux (Agent version: 5.0.1.4493) fails so regularly with the following warning and error messages:

Processing ServerName Error: Failed to execute agent management command print. Connection refused Failed to connect: /var/tmp/veeam/socket/veeamservice.sock. Failed to connect to veeamservice daemon.

and

Task failed. Error: Failed to execute agent management command print. Connection refused Failed to connect: /var/tmp/veeam/socket/veeamservice.sock. Failed to connect to veeamservice daemon.

Apparently, Veeam offers no error checking or resolution process for automatically restarting the service, so I had to write a quick script to resolve this ongoing issue.

This really simple script, that was written and tested on Ubuntu Server 14.04 and 20.04 (but should work for Debian as well), checks the veeamservice socket state, and restarts the service if necessary. Then, all you need to do is run it as a cron job at a regular interval and problem solved.

Install dependency

apt-get install socat

Create script file ‘/usr/local/bin/veeam_service_state.sh’

#!/bin/bash
#
# Check Veeam service socket state to see if it is accepting connections and restart if needed.
# Author: Nathan Thomas
# Date: 01/16/2023

VMSOCKET='/var/tmp/veeam/socket/veeamservice.sock'
VMSERVICENAME='veeamservice'
SERVICEBIN='/usr/sbin/service'

socat -u OPEN:/dev/null UNIX-CONNECT:${VMSOCKET} > /dev/null 2>&1
RETVAL="$?"
if [ "${RETVAL}" -ne 0 ] ; then
        ${SERVICEBIN} ${VMSERVICENAME} restart  > /dev/null 2>&1
fi

Make the script executable.

chmod +x /usr/local/bin/veeam_service_state.sh

Make a cron job entry using nano editor (runs every 5 minutes).

crontab -e
*/5       *       *       *       *       /usr/local/bin/veeam_service_state.sh > /dev/null 2&>1
Ctrl+x, then press y, and then Enter  to exit saving changes

Cheers!

Leave a Reply