目錄:python
1、mysupervisord文件夾準備docker
2、mysupervisord容器的生成vim
3、附件centos
3.一、supervisord文件內容bash
3.二、backup.sh文件內容ide
3.三、Dockerfile文件內容ui
4、報錯及解決辦法3d
4.一、報錯:setup.py時No module named setuptoolsunix
4.二、報錯:docker build時unix:///tmp/supervisor.sock no such filerest
4.三、報錯:docker run後容器Exited沒法啓動
正文:
1、mysupervisord文件夾準備
[weis@localhost ~]$ mkdir mysupervisord
[weis@localhost mysupervisord]$ cd mysupervisord
[weis@localhost mysupervisord]$ vim supervisord #內容見附件
[weis@localhost mysupervisord]$ chmod +x supervisord
[weis@localhost mysupervisord]$ vim backup.sh #內容見附件
[weis@localhost mysupervisord]$ chmod +x backup.sh
[weis@localhost mysupervisord]$ vim Dockerfile #內容見附件
[weis@localhost mysupervisord]$ wget https://files.pythonhosted.org/packages/45/a0/317c6422b26c12fe0161e936fc35f36552069ba8e6f7ecbd99bbffe32a5f/meld3-1.0.2.tar.gz
[weis@localhost mysupervisord]$ wget https://files.pythonhosted.org/packages/44/60/698e54b4a4a9b956b2d709b4b7b676119c833d811d53ee2500f1b5e96dc3/supervisor-3.3.4.tar.gz
[weis@localhost mysupervisord]$ wget https://pypi.python.org/packages/6f/10/5398a054e63ce97921913052fde13ebf332a3a4104c50c4d7be9c465930e/setuptools-26.1.1.zip#md5=f81d3cc109b57b715d46d971737336db
[weis@localhost mysupervisord]$ wget https://files.pythonhosted.org/packages/62/af/2370dc19c942c8d0468add39b33c17963af6d49da6f36b325843e76a4f77/importlib-1.0.1.zip
[weis@localhost mysupervisord]$ unzip setuptools-26.1.1.zip #centos:6.9鏡像未帶unzip命令,因此先行解壓,再拷貝到鏡像中
[weis@localhost mysupervisord]$ unzip importlib-1.0.4.zip
[weis@localhost mysupervisord]$ rm setuptools-26.1.1.zip
[weis@localhost mysupervisord]$ rm importlib-1.0.4.zip
[weis@localhost mysupervisord]$ ll
總用量 464
-rwxrwxr-x 1 weis weis 219 5月 18 09:40 backup.sh
-rw-r--r-- 1 weis weis 727 5月 18 15:57 Dockerfile
drwxrwxr-x 3 weis weis 88 5月 18 13:56 importlib-1.0.4
-rw-rw-r-- 1 weis weis 36478 5月 18 09:33 meld3-1.0.2.tar.gz
drwxrwxr-x 7 weis weis 4096 5月 18 14:35 setuptools-26.1.1
-rw-rw-r-- 1 weis weis 419794 5月 18 09:33 supervisor-3.3.4.tar.gz
-rwxrwxr-x 1 weis weis 2836 5月 18 09:41 supervisord
2、mysupervisord容器的生成:
docker build -t mysupervisord:v1 .
docker run --name mysupervisord -d mysupervisord:v1 #不能夠加-it交互參數,具體緣由見報錯3
docker exec -it mysupervisord bash
3、附件
3.一、supervisord文件內容:
#!/bin/bash
#
# supervisord Startup script for the Supervisor process control system
#
# Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
# Jason Koppe <jkoppe@indeed.com> adjusted to read sysconfig,
# use supervisord tools to start/stop, conditionally wait
# for child processes to shutdown, and startup later
# Erwan Queffelec <erwan.queffelec@gmail.com>
# make script LSB-compliant
#
# chkconfig: 345 83 04
# description: Supervisor is a client/server system that allows \
# its users to monitor and control a number of processes on \
# UNIX-like operating systems.
# processname: supervisord
# config: /etc/supervisord.conf
# config: /etc/sysconfig/supervisord
# pidfile: /var/run/supervisord.pid
#
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $all
# Required-Stop: $all
# Short-Description: start and stop Supervisor process control system
# Description: Supervisor is a client/server system that allows
# its users to monitor and control a number of processes on
# UNIX-like operating systems.
### END INIT INFO
# Source function library
. /etc/rc.d/init.d/functions
# Source system settings
if [ -f /etc/sysconfig/supervisord ]; then
. /etc/sysconfig/supervisord
fi
# Path to the supervisorctl script, server binary,
# and short-form for messages.
supervisorctl=/usr/bin/supervisorctl
supervisord=${SUPERVISORD-/usr/bin/supervisord}
prog=supervisord
pidfile=${PIDFILE-/var/run/supervisord.pid}
lockfile=${LOCKFILE-/var/lock/subsys/supervisord}
STOP_TIMEOUT=${STOP_TIMEOUT-60}
OPTIONS="${OPTIONS--c /etc/supervisord.conf}"
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} $supervisord $OPTIONS
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
touch ${lockfile}
$supervisorctl $OPTIONS status
fi
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
LSB=1 killproc -p $pidfile $supervisord -HUP
RETVAL=$?
echo
if [ $RETVAL -eq 7 ]; then
failure $"$prog reload"
else
$supervisorctl $OPTIONS status
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $supervisord
RETVAL=$?
[ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status
;;
restart)
restart
;;
condrestart|try-restart)
if status -p ${pidfile} $supervisord >&/dev/null; then
stop
start
fi
;;
force-reload|reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}"
RETVAL=2
esac
exit $RETVAL
3.二、backup.sh文件內容:
#!/bin/bash
source="/etc /home /root /var/lib /var/spool/{cron,at,mail}"
target="/backups/backup-system-$(date +%Y-%m-%d).tar.gz"
[ ! -d /backups ] && mkdir /backups
tar -zcvf ${target} ${source} &> /backups/backup.log
3.三、Dockerfile文件內容:
FROM centos:6.9
ADD meld3-1.0.2.tar.gz /
ADD supervisor-3.3.4.tar.gz /
COPY importlib-1.0.4 /importlib
COPY setuptools-26.1.1 /setuptools
COPY supervisord /etc/init.d/
COPY backup.sh /backups/
RUN cd /importlib \
&& python setup.py install --record log \
&& cd /setuptools \
&& python setup.py install --record log \
&& cd /meld3-1.0.2 \
&& python setup.py install --record log \
&& cd /supervisor-3.3.4 \
&& python setup.py install --record log \
&& echo_supervisord_conf > /etc/supervisord.conf \
&& mkdir -p /var/log/supervisor/ \
&& chkconfig --add supervisord \
&& echo "[program:backup]" >> /etc/supervisord.conf \
&& echo "command=/backups/backup.sh" >> /etc/supervisord.conf
CMD ["supervisord","-n"]
4、報錯及解決辦法
4.一、報錯:No module named setuptools
場景:
[root@defccb488a15 ~]# python /supervisor-3.3.4/setup.py install --record log
Traceback (most recent call last):
File "/supervisor-3.3.4/setup.py", line 32, in <module>
from setuptools import setup, find_packages
ImportError: No module named setuptools
解決辦法,下載組件setuptools、importlib並解壓。
4.二、報錯:unix:///tmp/supervisor.sock no such file
場景:
docker build時報錯。解決辦法:Dockerfile文件中添加容器啓動命令:CMD ["supervisord"]。注:嘗試了將supervisord、supervisorctl放到RUN中執行是無效的。["supervisorctl","status、start、reloed等參數"]放到CMD中執行也不會起做用,由於supervisord服務未啓動,supervisord只能再CMD命令中啓動。創建容器的命令中:docker run -it --name mysupervisord -d mysupervisord:v1 最後不要加bash參數,添加的話會將Dockerfile文件中的CMD覆蓋。4.三、報錯:docker run後容器Exited沒法啓動[weis@localhost mysupervisord]$ docker ps -a #容器退出了(Exited)CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES75a2d6509a53 mysupervisord:v1 "/bin/sh -c supervis…" 14 minutes ago Exited (0) 14 minutes ago a6解決辦法:鏡像前臺必須有東西再跑。Dockerfile文件中將supervisord放到前臺運行;docker run容器生成時不加-it交互參數。