runinit启动小程序测试
与Supervisord类似的工具包括monit, daemontools和runit。
我还发现个神器,专门针对单容器启动多进程的神器s6: https://github.com/just-containers/s6-overlay
参考: https://github.com/faisyl/alpine-runit/blob/master/Dockerfile
https://segmentfault.com/a/1190000006644578
安装
# apt-get install runit
如果是centos,则可以使用yum进行安装,但是默认情况下centos软件仓库里并没有runit,所以需要先配置相应的仓库:
# curl -s https://packagecloud.io/install/repositories/imeyer/runit/script.rpm.sh | sudo bash
# sudo yum install runit-2.1.1-7.el7.centos.x86_64
runinit启动小程序测试
- 创建目录(2个run文件,+x)
root@no1:~# tree test/
test/
├── log
│ └── run
└── run
- 新建run(程序启动命令)
root@no1:~# cat test/run
#!/bin/sh
exec 2>&1
echo $date
echo "-------------------"
- 新建run(日志处理)
root@no1:~# cat test/log/run
#!/bin/sh
LOGDIR=/var/log/test
mkdir -p $LOGDIR
# Prefix each line with a timestamp
exec svlogd -tt $LOGDIR
- 让runint管理
cp -rp test /etc/service/
- 查看运行状态
root@no1:~# tail -f /var/log/test/current
2017-12-28_10:42:48.60753
2017-12-28_10:42:48.60757 -------------------
2017-12-28_10:42:49.60933
查看calico使用runinit怎么启动多进程的
docker run -it --rm quay.io/calico/node sh
$ ls available/
bird bird6 calico-bgp-daemon confd felix libnetwork
$ cat available/bird/run
#!/bin/sh
exec 2>&1
exec bird -R -s /var/run/calico/bird.ctl -d -c /etc/calico/confd/config/bird.cfg
$ cat available/bird/log/run
#!/bin/sh
LOGDIR=/var/log/calico/bird
mkdir -p $LOGDIR
# Prefix each line with a timestamp
exec svlogd -tt $LOGDIR
- 查看进程的日志(时间是runinit搞的)
tail -f /var/log/test/current
2017-12-28_13:15:24.81191
2017-12-28_13:15:24.81196 -------------------
2017-12-28_13:15:25.81559
2017-12-28_13:15:25.81565 -------------------