Warm tip: This article is reproduced from serverfault.com, please click

linux-Centos 7:如果停止,则自动重新启动应用程序

(linux - Centos 7: Auto restart application if it stopped)

发布于 2015-08-07 13:01:52

我想自动重启我的应用程序“ Fiware IoT Agent”,如果它停止了,问题在于它取决于Mongo Db数据库和Mosquitto代理。我的操作系统是centOS 7

这是我用来按以下顺序启动三个应用程序的命令:

*蒙哥:

/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$

*蚊帐经纪人

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

物联网代理:

比我使用此命令启动我的应用程序

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

如果它停止运行又又取决于其他两个应用程序,我该如何启动它?例如,如果Mongo DB停止了,我必须能够重新启动它,然后重新启动我的应用程序。

Questioner
sabrina2020
Viewed
0
Murad Tagirov 2015-08-07 22:23:40

CentOS 7使用systemd。你可以为每个应用程序创建systemd服务,并指定它们之间的依赖关系。为需要自动重启的服务指定“ Restart = always ”。