diff --git a/LibreNMS/service.py b/LibreNMS/service.py index 8dc41496d2..cd6bb10922 100644 --- a/LibreNMS/service.py +++ b/LibreNMS/service.py @@ -23,6 +23,12 @@ from socket import gethostname from signal import signal, SIGTERM, SIGQUIT, SIGINT, SIGHUP, SIGCHLD, SIG_DFL from uuid import uuid1 +try: + from systemd.daemon import notify +except ImportError: + pass + + class ServiceConfig: def __init__(self): @@ -290,6 +296,7 @@ class Service: self.watchdog_timer = LibreNMS.RecurringTimer(self.config.poller.frequency, self.logfile_watchdog, 'watchdog') else: info("Watchdog is disabled.") + self.systemd_watchdog_timer = LibreNMS.RecurringTimer(10, self.systemd_watchdog, 'systemd-watchdog') self.is_master = False def service_age(self): @@ -353,6 +360,7 @@ class Service: if self.config.update_enabled: self.daily_timer.start() self.stats_timer.start() + self.systemd_watchdog_timer.start() if self.config.watchdog_enabled: self.watchdog_timer.start() @@ -577,6 +585,7 @@ class Service: self.daily_timer.stop() self.stats_timer.stop() + self.systemd_watchdog_timer.stop() if self.config.watchdog_enabled: self.watchdog_timer.stop() @@ -668,6 +677,10 @@ class Service: except pymysql.err.Error: exception("Unable to log performance statistics - is the database still online?") + def systemd_watchdog(self): + if 'systemd.daemon' in sys.modules: + notify("WATCHDOG=1") + def logfile_watchdog(self): try: diff --git a/doc/Extensions/Dispatcher-Service.md b/doc/Extensions/Dispatcher-Service.md index 65a212d44a..b9fff95201 100644 --- a/doc/Extensions/Dispatcher-Service.md +++ b/doc/Extensions/Dispatcher-Service.md @@ -177,6 +177,16 @@ install run `cp /opt/librenms/misc/librenms.service /etc/systemd/system/librenms.service && systemctl enable --now librenms.service` +## systemd-watchdog + +A systemd unit file can be found in `misc/librenms-watchdog.service`. To +install run `cp /opt/librenms/misc/librenms-watchdog.service +/etc/systemd/system/librenms.service && systemctl enable --now +librenms.service` + +This requires: python3-systemd (or python-systemd on older systems) +or https://pypi.org/project/systemd-python/ + ## OS-Specific Instructions ### RHEL/CentOS diff --git a/doc/Installation/Install-LibreNMS.md b/doc/Installation/Install-LibreNMS.md index 8de3768d50..23053c1e80 100644 --- a/doc/Installation/Install-LibreNMS.md +++ b/doc/Installation/Install-LibreNMS.md @@ -24,7 +24,7 @@ Connect to the server command line and follow the instructions below. apt install software-properties-common add-apt-repository universe apt update - apt install acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools + apt install acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd ``` === "Apache" @@ -32,7 +32,7 @@ Connect to the server command line and follow the instructions below. apt install software-properties-common add-apt-repository universe apt update - apt install acl curl apache2 composer fping git graphviz imagemagick libapache2-mod-fcgid mariadb-client mariadb-server mtr-tiny nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip rrdtool snmp snmpd whois python3-pymysql python3-dotenv python3-redis python3-setuptools + apt install acl curl apache2 composer fping git graphviz imagemagick libapache2-mod-fcgid mariadb-client mariadb-server mtr-tiny nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip rrdtool snmp snmpd whois python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd ``` === "CentOS 8" @@ -41,7 +41,7 @@ Connect to the server command line and follow the instructions below. dnf -y install epel-release dnf module reset php dnf module enable php:7.3 - dnf install bash-completion cronie fping git ImageMagick mariadb-server mtr net-snmp net-snmp-utils nginx nmap php-fpm php-cli php-common php-curl php-gd php-json php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd python3 python3-PyMySQL python3-redis python3-memcached python3-pip rrdtool unzip + dnf install bash-completion cronie fping git ImageMagick mariadb-server mtr net-snmp net-snmp-utils nginx nmap php-fpm php-cli php-common php-curl php-gd php-json php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd python3 python3-PyMySQL python3-redis python3-memcached python3-pip python3-systemd rrdtool unzip ``` === "Apache" @@ -49,13 +49,13 @@ Connect to the server command line and follow the instructions below. dnf -y install epel-release dnf module reset php dnf module enable php:7.3 - dnf install bash-completion cronie fping git httpd ImageMagick mariadb-server mtr net-snmp net-snmp-utils nmap php-fpm php-cli php-common php-curl php-gd php-json php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd python3 python3-PyMySQL python3-redis python3-memcached python3-pip rrdtool unzip + dnf install bash-completion cronie fping git httpd ImageMagick mariadb-server mtr net-snmp net-snmp-utils nmap php-fpm php-cli php-common php-curl php-gd php-json php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd python3 python3-PyMySQL python3-redis python3-memcached python3-pip python3-systemd rrdtool unzip ``` === "Debian 10" === "NGINX" ``` - apt install acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.3-cli php7.3-curl php7.3-fpm php7.3-gd php7.3-json php7.3-mbstring php7.3-mysql php7.3-snmp php7.3-xml php7.3-zip python3-dotenv python3-pymysql python3-redis python3-setuptools rrdtool snmp snmpd whois + apt install acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.3-cli php7.3-curl php7.3-fpm php7.3-gd php7.3-json php7.3-mbstring php7.3-mysql php7.3-snmp php7.3-xml php7.3-zip python3-dotenv python3-pymysql python3-redis python3-setuptools python3-systemd rrdtool snmp snmpd whois ``` ## Add librenms user diff --git a/misc/librenms-watchdog.service b/misc/librenms-watchdog.service new file mode 100644 index 0000000000..467b94effe --- /dev/null +++ b/misc/librenms-watchdog.service @@ -0,0 +1,16 @@ +[Unit] +Description=LibreNMS SNMP Poller Service +After=network.target + +[Service] +ExecStart=/opt/librenms/librenms-service.py -v +ExecReload=/bin/kill -HUP $MAINPID +WorkingDirectory=/opt/librenms +User=librenms +Group=librenms +RestartSec=10 +Restart=always +WatchdogSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/requirements.txt b/requirements.txt index 499fee0055..b5d86ebea7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ PyMySQL python-dotenv redis>=3.0 setuptools -psutil \ No newline at end of file +psutil