Isn't that what I already said a few post up?
That is why I have added the extra log file to be able to check the age in monit and restart dtgbot when it is over 2 minutes old.
Jos
Moderator: leecollings
Isn't that what I already said a few post up?
Code: Select all
linaro@cubietruck:~/dtgbot$ ls -l *.sh
-rwxr-xr-x 1 root root 963 Jan 24 12:22 restartbot.sh
-rwxr-xr-x 1 root root 442 Jan 24 12:22 stopbot.sh
Code: Select all
linaro@cubietruck:~/dtgbot$ ls /var/tmp -l
-rw-r--r-- 1 root root 5384 Jan 27 20:31 dtb.log
-rw-r--r-- 1 root root 738547 Jan 27 20:31 dtgloop.txt
Code: Select all
linaro@cubietruck:~/dtgbot$ /home/linaro/dtgbot/restartbot.sh
/home/linaro/dtgbot/restartbot.sh: line 11: /var/tmp/dtgloop.txt: Permission denied
/home/linaro/dtgbot/restartbot.sh: line 13: /var/tmp/dtgloop.txt: Permission denied
/home/linaro/dtgbot/restartbot.sh: line 15: /var/tmp/dtgloop.txt: Permission denied
/home/linaro/dtgbot/restartbot.sh: line 19: /var/tmp/dtgloop.txt: Permission denied
/home/linaro/dtgbot/restartbot.sh: line 22: /var/tmp/dtgloop.txt: Permission denied
/home/linaro/dtgbot/restartbot.sh: line 23: /var/tmp/dtgloop.txt: Permission denied
Code: Select all
Before Monit is started the first time, you can test the control file for syntax errors:
$ monit -t
$ Control file syntax OK
Code: Select all
start program = "sudo /home/linaro/dtgbot/restartbot.sh" timeout 20 seconds
Code: Select all
Jan 27 21:56:28 cubietruck monit[741]: Starting daemon monitor: monit/etc/monit/monitrc:156: Program does...sudo'
Jan 27 21:56:28 cubietruck monit[741]: /etc/monit/monitrc:157: Program does not exist: 'sudo'
Jan 27 21:56:28 cubietruck monit[741]: /etc/monit/monitrc:163: Program does not exist: 'sudo'
Code: Select all
linaro@cubietruck:~$ sudo monit -t
/etc/monit/monitrc:156: Program does not exist: 'sudo'
/etc/monit/monitrc:157: Program does not exist: 'sudo'
/etc/monit/monitrc:163: Program does not exist: 'sudo'
Control file syntax OK
Looking at your outputs you are running on a Cubietruck (its helpful to include this in your forum signature) not a Raspberry Pi, and you don't appear to have sudo installed, which would explain why nothing happens when you add sudo into monitrc.
Code: Select all
pi@domoticz:~/dtgbot$ ls -l /var/tmp
-rw-r--r-- 1 root root 2691 Jan 27 22:40 dtb.log
-rw-r--r-- 1 root root 0 Jan 15 14:14 dtb.log.errors
-rw-r--r-- 1 root root 97580 Jan 27 23:00 dtgloop.txt
-rw-r----- 1 root root 2763 Jan 27 22:41 monit.log
Code: Select all
pi@domoticz:~/dtgbot$ ps -ef | grep -i monit
root 617 1 0 Jan15 ? 00:09:14 /usr/bin/monit -c /etc/monit/monitrc
Code: Select all
# dtgbot running normally
pi@domoticz:~/dtgbot$ ps -ef | grep -i bot
root 8884 1 0 Jan25 ? 00:00:00 /bin/sh /home/pi/dtgbot/dtgbot /var/run/dtgbot.pid
root 8885 8884 0 Jan25 ? 00:02:31 /usr/bin/lua5.2 /home/pi/dtgbot/dtgbot.lua
pi 21259 20106 0 22:38 pts/1 00:00:00 grep -i bot
# dtgbot stopped by stopbot
pi@domoticz:~/dtgbot$ sudo ./stopbot.sh
pi@domoticz:~/dtgbot$ ps -ef | grep -i bot
pi 21477 20106 0 22:39 pts/1 00:00:00 grep -i bot
# monit launches restartbot.sh
pi@domoticz:~/dtgbot$ ps -ef | grep -i bot
root 21526 617 2 22:39 ? 00:00:00 /bin/bash /home/pi/dtgbot/restartbot.sh
pi 21570 20106 0 22:39 pts/1 00:00:00 grep -i bot
# restartbot.sh starts the dtgbot service
pi@domoticz:~/dtgbot$ ps -ef | grep -i bot
root 21526 617 0 22:39 ? 00:00:00 /bin/bash /home/pi/dtgbot/restartbot.sh
root 21592 21526 0 22:39 ? 00:00:00 sudo service dtgbot start
root 21596 21592 0 22:39 ? 00:00:00 /bin/sh /usr/sbin/service dtgbot start
pi 21603 20106 0 22:39 pts/1 00:00:00 grep -i bot
# monit has now restarted dtgbot successfully
pi@domoticz:~/dtgbot$ ps -ef | grep -i bot
root 21621 1 0 22:39 ? 00:00:00 /bin/sh /home/pi/dtgbot/dtgbot /var/run/dtgbot.pid
root 21623 21621 49 22:39 ? 00:00:02 /usr/bin/lua5.2 /home/pi/dtgbot/dtgbot.lua
pi 21631 20106 0 22:40 pts/1 00:00:00 grep -i bot
Code: Select all
[GMT Jan 27 22:39:41] error : 'dtgbot' process is not running
[GMT Jan 27 22:39:41] info : 'dtgbot' trying to restart
[GMT Jan 27 22:39:41] info : 'dtgbot' start: /home/pi/dtgbot/restartbot.sh
[GMT Jan 27 22:41:55] info : 'dtgbot' process is running with pid 21621
Sudo is surely installed, it's workin, but it seems that adding just sudo to monit rc does not work.
Code: Select all
start program = "/home/linaro/dtgbot/restartbot.sh" as uid root and gid root timeout 20 seconds
stop program = "/home/linaro/dtgbot/stopbot.sh" as uid root and gid root timeout 20 seconds
All the files (logs) in the /var/tmp are owned by root:root too in my case.simonrg wrote: ↑Sunday 28 January 2018 0:05 The owner of restartbot.sh shouldn't matter as long as it is executable by all users, you can find the owner of dtgloop.txt by ls -l on the temporary directory, mine is owned by root.Code: Select all
pi@domoticz:~/dtgbot$ ls -l /var/tmp -rw-r--r-- 1 root root 2691 Jan 27 22:40 dtb.log -rw-r--r-- 1 root root 0 Jan 15 14:14 dtb.log.errors -rw-r--r-- 1 root root 97580 Jan 27 23:00 dtgloop.txt -rw-r----- 1 root root 2763 Jan 27 22:41 monit.log
I get same result with ps command.simonrg wrote: ↑Sunday 28 January 2018 0:05 I assume that monit is running as root on your system as it is on mine, so you don't need the sudo as the scripts will be run as root:restartbot.sh and stopbot.sh are both designed to run as root by monit.Code: Select all
pi@domoticz:~/dtgbot$ ps -ef | grep -i monit root 617 1 0 Jan15 ? 00:09:14 /usr/bin/monit -c /etc/monit/monitrc
Code: Select all
[CET Jan 28 08:03:47] info : 'dtgloop' trying to restart
[CET Jan 28 08:03:47] info : 'dtgloop' start: /home/linaro/dtgbot/restartbot.sh
[CET Jan 28 08:04:07] error : 'dtgloop' failed to start (exit status -1) -- /home/linaro/dtgbot/restartbot.sh: Program timed out -- 01/28/2018 08:03:47 AM restartbot.sh started (2)
Code: Select all
echo "test" >> /var/tmp/dtgloop.txt
Sorry I thought in one of the post away back I had seen "sudo" not a recognised command, sudo is a package so it needn't be loaded but normally it is, I like the detailed signature .
Code: Select all
cd ~/dtgbot
sudo ./stopbot.sh
Code: Select all
sudo ./restartbot.sh
Code: Select all
sudo service dtgbot stop
sudo pkill -f dtgbot/dtgbot.lua
sudo service dtgbot start
Code: Select all
linaro@cubietruck:~/dtgbot$ sudo ./stopbot.sh
linaro@cubietruck:~/dtgbot$ sudo ./restartbot.sh
linaro@cubietruck:~/dtgbot$
Code: Select all
2018-01-28 09:28:16
01/28/2018 09:29:00 AM Stopping
2018-01-28 09:29:07
01/28/2018 09:29:12 AM Stopped
01/28/2018 09:29:18 AM restartbot.sh started but is already running so stopping this one. (3)
linaro@cubietruck:/var/tmp$
Code: Select all
Monitor the DTGBOT Service
check process dtgbot with pidfile /var/run/dtgbot.pid
start program = "/home/linaro/dtgbot/restartbot.sh" timeout 20 seconds
stop program = "/home/linaro/dtgbot/stopbot.sh" timeout 20 seconds
if 5 restarts within 5 cycles then timeout
# Monitor the DTGBOT loop file which should be updated each minute.
# Restart DTGBOT when not updated in 2 minutes
check file dtgloop with path /var/tmp/dtgloop.txt
start program = "/home/linaro/dtgbot/restartbot.sh" timeout 20 seconds
if timestamp > 2 minutes then restart
if 5 restarts within 5 cycles then timeout
Code: Select all
30010 ? Zs 0:00 [restartbot.sh] <defunct>
Code: Select all
chk=`sudo ps x | grep "restartbot.sh" | grep -cv grep`
if [ $chk -gt 2 ] ; then
echo "`date +"%x %X"` restartbot.sh started but is already running so s$
exit
fi
Code: Select all
01/29/2018 07:02:18 AM restartbot.sh started but is already running so stopping this one. (3)
Code: Select all
chk=`sudo ps x | grep "restartbot.sh" | grep -cv grep`
if [ $chk -gt 2 ] ; then
echo "`date +"%x %X"` restartbot.sh started but is already running so stopping this one. ($chk)" >> /var/tmp/dtgloop.txt
sudo service monit restart
exit
fi
Code: Select all
-- Load necessary Lua libraries
http = require "socket.http";
socket = require "socket";
https = require "ssl.https";
JSON = require "JSON";
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
-- Load the configuration file this file contains the list of commands
-- used to define the external files with the command function to load.
local config=""
if (file_exists(BotHomePath.."dtgbot-user.cfg")) then
config = assert(loadfile(BotHomePath.."dtgbot-user.cfg"))();
print_to_log ("Using DTGBOT config file:"..BotHomePath.."dtgbot-user.cfg")
else
config = assert(loadfile(BotHomePath.."dtgbot.cfg"))();
print_to_log ("Using DTGBOT config file:"..BotHomePath.."dtgbot.cfg")
end
Hi!jvdz wrote: ↑Tuesday 13 March 2018 18:36 The issue seems to lie in these lines so guess the best bet will be an issue with the require files:Could the issue be similar to issues reported like this one?: http://www.domoticz.com/forum/viewtopic ... on#p171940Code: Select all
-- Load necessary Lua libraries http = require "socket.http"; socket = require "socket"; https = require "ssl.https"; JSON = require "JSON"; function file_exists(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false end end -- Load the configuration file this file contains the list of commands -- used to define the external files with the command function to load. local config="" if (file_exists(BotHomePath.."dtgbot-user.cfg")) then config = assert(loadfile(BotHomePath.."dtgbot-user.cfg"))(); print_to_log ("Using DTGBOT config file:"..BotHomePath.."dtgbot-user.cfg") else config = assert(loadfile(BotHomePath.."dtgbot.cfg"))(); print_to_log ("Using DTGBOT config file:"..BotHomePath.."dtgbot.cfg") end
Jos
I can confirm this is working on Ubuntu 16.04 64bit on my NUC with VirtualBox!G3rard wrote: ↑Saturday 13 May 2017 10:49I did the following steps to make dtgbot working on my Ubuntu server 14.04 x64.maomanna wrote:How did you compile the lua libraries?
In the OP is a 32bit version supplied.
- Follow instruction from https://www.domoticz.com/wiki/Remote_Co ... legram_Bot
- sudo apt-get install lua-sec
- Follow instruction from http://www.domoticz.com/forum/viewtopic ... 23&t=10783
- Copy ssl.so from /usr/lib/i386-linux-gnu/lua/5.2 to /usr/local/lib/lua/5.2/ssl.so
Users browsing this forum: No registered users and 1 guest