Ubuntu,upstart和创建一个pid进行监控

下面是redis的upstart脚本。如何创建一个pid,所以我使用monit进行监控?
#!upstart
description "Redis Server"

env USER=redis

start on startup
stop on shutdown

respawn

exec sudo -u $USER sh -c "/usr/local/bin/redis-server /etc/redis/redis.conf 2>&1 >> /var/log/redis/redis.log"
如果启动 – 停止 – 守护程序在您的机器上可用,我强烈建议使用它启动您的过程。 start-stop-daemon将处理作为非特权用户启动进程,而不从sudo或su( recommended in the upstart cookbook)分支,并且它还内置支持pid文件管理。例如:

/etc/init/app_name.conf

#!upstart
description "Redis Server"

env USER=redis

start on startup
stop on shutdown

respawn

exec start-stop-daemon --start --make-pidfile --pidfile /var/run/app_name.pid --chuid $USER --exec /usr/local/bin/redis-server /etc/redis/redis.conf >> /var/log/redis/redis.log 2>&1

或者,您可以使用启动后脚本节来创建pid文件并使用停止后脚本节来手动管理pid文件。例如:

/etc/init/app_name.conf

#!upstart
description "Redis Server"

env USER=redis

start on startup
stop on shutdown

respawn

exec sudo -u $USER sh -c "/usr/local/bin/redis-server /etc/redis/redis.conf 2>&1 >> /var/log/redis/redis.log"

post-start script
    PID=`status app_name | egrep -oi '([0-9]+)$' | head -n1`
    echo $PID > /var/run/app_name.pid
end script

post-stop script
    rm -f /var/run/app_name.pid
end script

相关文章

目录前言一、创建Hadoop用户二、更新apt和安装Vim编辑器三、...
原文连接:https://www.cnblogs.com/yasmi/p/5192694.html ...
电脑重启后,打开VirtualBox,发现一直用的虚拟机莫名的消失...
参见:https://blog.csdn.net/weixin_38883338/article/deta...
Ubuntu 18.04 LTS 已切换到 Netplan 来配置网络接口。Netpla...
介绍每个 Web 服务都可以通过特定的 URL 在 Internet 上访问...