From c08734f4b81ef1d8b8c5ed600dab325cbeb582bb Mon Sep 17 00:00:00 2001 From: Rodgger Date: Thu, 9 Feb 2023 09:19:57 -0500 Subject: [PATCH] =?UTF-8?q?servi=C3=A7o=20qlogd=20para=20systemd=20-=20qlo?= =?UTF-8?q?gd.service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../var_lib_asterisk/scripts/qlog/qlogd.php | 11 +++++++ .../scripts/qlog/qlogd.service | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 asterisk/var_lib_asterisk/scripts/qlog/qlogd.service diff --git a/asterisk/var_lib_asterisk/scripts/qlog/qlogd.php b/asterisk/var_lib_asterisk/scripts/qlog/qlogd.php index 0a87e7e1..dc4ca420 100644 --- a/asterisk/var_lib_asterisk/scripts/qlog/qlogd.php +++ b/asterisk/var_lib_asterisk/scripts/qlog/qlogd.php @@ -215,6 +215,17 @@ function GetDaemon($notDaemon) { exit(0); //success } + /* PIDFile SYSTEMD + * SYSTEMD irá monitorar esse pid para verificar se ainda ativo + */ + $PIDFile = fopen( "/var/lock/subsys/qlog.pid", "w+" ); + $pid = getmypid( ) + if( $pid == false ){ + exit( 1 ); + } + fwrite( $PIDFile, $pid); + fclose( $PIDFile ); + // posix_setsid(); } diff --git a/asterisk/var_lib_asterisk/scripts/qlog/qlogd.service b/asterisk/var_lib_asterisk/scripts/qlog/qlogd.service new file mode 100644 index 00000000..7e9c4f3c --- /dev/null +++ b/asterisk/var_lib_asterisk/scripts/qlog/qlogd.service @@ -0,0 +1,30 @@ +# +# ExecStartPre +# If more than one command is specified, the +# commands are invoked sequentially in the +# order they appear in the unit file. If one +# of the commands fails (and is not prefixed +# with "-"), other lines are not executed, +# and the unit is considered failed. +# + +[Unit] +Description=Monitoramento dos eventos gerados na central - Simples IP + +[Service] +Type=forking + +# verifica se o serviço está rodando +ExecStartPre=/bin/bash -c '! /usr/bin/systemctl is-active --quiet qlogd.service' + +# Limpa pid em /var/lock/subsys/qlog.pid +ExecStartPre=/bin/bash -c "echo > /var/lock/subsys/qlog.pid" + +ExecStart=/var/lib/asterisk/scripts/qlog/qlogd.php --log=/var/log/qlog.log +PIDFile=/var/lock/subsys/qlog.pid + +Restart=always +RestartSec=1 + +[Install] +WantedBy=multi-user.target