0

I want to auto restart my application "Fiware IoT Agent" if it stopped, the problem is that it depends of Mongo Db Data Base and the Mosquitto broker. My OS is centOS 7

Here is the commands that I use to launch my three application in the following order:

*Mongo:

/usr/local/iot/mongodb-linux-x86_64-3.0.5/bin/mongod --dbpath /usr/local/iot/mongodb-linux-x86_64-3.0.5/data/db$

*Mosquitto broker

/usr/sbin/mosquitto -c /etc/iot/mosquitto.conf &
pid=$!
echo $pid > /var/run/iot/mosquitto.pid

Iot Agent:

than I start my application using this command

export LD_LIBRARY_PATH=/usr/local/iot/lib
/usr/local/iot/bin/iotagent -i 192.168.1.11 -p 80 -v DEBUG -d /usr/local/iot/lib -c /etc/iot/config.json

how can I start my application if it stopped known that it depends of the other two application? If for example Mongo DB stopped, I must be able to restart it and then to restart my application.

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
sabrina2020
  • 2,102
  • 3
  • 25
  • 54

2 Answers2

1

CentOS 7 uses systemd. You can create systemd service for each of your applications and specify dependencies between them. And specify "Restart=always" for service which need to be auto restarted.

Murad Tagirov
  • 776
  • 6
  • 10
1

You can create your own watch dog code. When you start your application get the pid of the process and the pid of mongo DB.

Every couple of second like 10 seconds check that the pid of both process still exist, or you can also make the programs touch a file every couple of seconds as well then check the file modification time to see if the programs are still alive.

If the program hasn't touched the file or if you go jus the pid route and the pid doesn't exist. Then the program has died.

Restart the program and get the new pid and go about again in a forever while loop.

jgr208
  • 2,896
  • 9
  • 36
  • 64