supervisor-20190416-Ubuntu 14.04 利用 supervisord 守护 Tomcat 进程

41 篇文章 0 订阅
19 篇文章 0 订阅

Intro

背景: binary tar 包的 tomcat 需要一个守护进程完成开机自启,以及服务意外退出的守护启动。

解决思路

supervisord 和 systemd 对比

比对了 supervisor 和 systemd,自动重启部分 systemd 更加满足日常运维的需要。

systemd vs supervisord

关于 Tomcat 的 systemd 参考:

How To Install Apache Tomcat 8 on CentOS 7

tomcat systemd service script

但是当前使用的是 Ubuntu 14.04,默认没有 systemd 服务。

以下内容参考链接: 如何在 Ubuntu 14.04中使用systemctl?
我刚刚自己遇到了这个问题,发现Ubuntu 14.04使用Upstart而不是Systemd,所以systemctl命令不起作用。

Ubuntu Startup

Ubuntu 有很多不同的配置开机自启动的方式,/etc/init.d/ 和 /etc/init 目录的保留就是为了版本的上下兼容

以下内容参考链接: ubuntu的service,update-rc.d和systemctl命令

init类型说明识别
Systemd新出现的init,很多linux发行版都已经或者计划转向Systemd如果你的系统目录文件中/usr/lib/systemd和/etc/systemd,说明你有systemd,例如我的ubuntu 17.10就有
Upstartubuntu曾经使用的init,但是现在已经转向了systemd系统目录有/etc/init,而且其中有许多conf文件,说明你的系统有upstart(除非你的系统是debian7,那说明你使用的是System V init),同时,我发现我的ubuntu 17.10也有这个目录,我猜测可能是为了兼容(此处存疑问,现在的ubuntu的init确实是systemd)
System V init传统的init,大多数的linux发行版都会兼容系统有/etc/inittab文件,说明你很可能是System V init

理解备注:

  1. System V init 就是 service,也就是 /etc/init.d 下的脚本
  2. update-rc.d 一般是在不同的运行级别 runlevel 下创建软链接: /etc/rc[runlevel].d/NNname => /etc/init.d/name,可以通过运行 runlevel命令来查看当前的运行级别,然后到对应的 /etc/rc[runlevel].d/下找到可配置自启动的项

以下内容参考链接: ubuntu 14.04 /etc/init.d/ vs /etc/init/ start service at startup

It is true that /etc/init was introduced by Upstart, while /etc/init.d goes back to SysV. However, my point was that /etc/init.d contains scripts to be executed, while /etc/init contains configuration. But, upstart is dead anyway, and systemd introduces /etc/systemd. Note that /etc/init as well as /etc/init.d still exist on current Ubuntus (15.04 here), but I guess these are just transitional files installed by packages that support all three init systems.

以下内容参考链接: Ubuntu 系统 Update-rc.d 命令

Ubuntu中的运行级别
0(关闭系统)
1(单用户模式,只允许root用户对系统进行维护。)
2 到 5(多用户模式,其中3为字符界面,5为图形界面。)
6(重启系统)

以下内容参考链接:Ubuntu startup – init scripts, runlevels, upstart jobs explained

Run levelNameDescription
1Single-user modeMode for administrative tasks.
2Multi-User ModeDoes not configure network interfaces and does not export networks services
3Multi-User Mode with NetworkingStarts the system normally
4Not used / user definableFor special purposes
5Start the system normally with GUI display managerRun level 3 + display manager
6RebootReboots the system
s or SSingle-user modeDoes not configure network interfaces, or start daemons.
0HaltShuts down the system

supervisord

确定使用 supervisor 自启,然后维护 Tomcat 程序作为最终解决方法。
确保 supervisor 开机自启,update-rc.d supervisor defaults是相对简单的配置开机自启的方式,有更多 runlevel 的改变的话,可以再查 update-rc.d 的相关设置文档。

查看 supervisord 的配置文件 /etc/supervisor/supervisord.conf,最后一行是

[include]
files = /etc/supervisor/conf.d/*.conf

所以,可以直接操作 /etc/supervisor/conf.d 目录下以 conf 作为尾缀的配置文件

以下内容参考链接: jenkins安装部署-用supervisord守护进程自启动

# /etc/supervisor/conf.d/tomcat.conf 

[program:jenkins]                                                   # 随便起一个程序名
command=/home/eng-admin/apache-tomcat-8.5.23/bin/catalina.sh run    # 检查 / 启动的脚本
numprocs=1                                                          # 启动进程的数目
user=eng-admin
directory=/home/eng-admin/apache-tomcat-8.5.23/bin
autostart=true                                                      # 跟随 supervisor 开机自启
autorestart=true                                                    # 自动重启
startretries=30                                                     # 重启最多次数
startsecs=30                                                        # 每次重启间隔时间

最后,重新加载 supervisord 配置文件即可

以下内容参考链接: supervisor更改某项目配置后 需要重新启动才有效

# 更新新的配置到 supervisord
supervisorctl update
# 重新启动配置中的所有程序
supervisorctl reload
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值