From 4ff51dee1ee59334439fe8d4094aef84ca65a008 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Thu, 15 Sep 2022 10:21:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=86=85=E5=AE=B9=EF=BC=8C=E6=97=A0=E9=9C=80=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pt_test/docker_mariadb/Dockerfile | 61 +++++++++ pt_test/docker_mariadb/requirements.txt | 84 ++++++++++++ pt_test/docker_mariadb/start.sh | 36 +++++ pt_test/supervisor/Supervisor.conf | 170 ++++++++++++++++++++++++ pt_test/supervisor/conf/ptools.ini | 13 ++ pt_test/supervisor/log/supervisord.log | 21 +++ pt_test/supervisor/supervisord.pid | 1 + 7 files changed, 386 insertions(+) create mode 100644 pt_test/docker_mariadb/Dockerfile create mode 100644 pt_test/docker_mariadb/requirements.txt create mode 100644 pt_test/docker_mariadb/start.sh create mode 100644 pt_test/supervisor/Supervisor.conf create mode 100644 pt_test/supervisor/conf/ptools.ini create mode 100644 pt_test/supervisor/log/supervisord.log create mode 100644 pt_test/supervisor/supervisord.pid diff --git a/pt_test/docker_mariadb/Dockerfile b/pt_test/docker_mariadb/Dockerfile new file mode 100644 index 0000000..069cc03 --- /dev/null +++ b/pt_test/docker_mariadb/Dockerfile @@ -0,0 +1,61 @@ +# myproject/Dockerfile + +# 建立 python3.9 环境 +FROM python:3.9-slim + +# 镜像作者大江狗 +MAINTAINER ngfchl ngfchl@126.com + +# 设置 python 环境变量 +ENV PYTHONUNBUFFERED 1 +ENV DJANGO_SUPERUSER_USERNAME=admin +ENV DJANGO_SUPERUSER_EMAIL=admin@eamil.com +ENV DJANGO_SUPERUSER_PASSWORD=adminadmin +ENV MARIADB_ROOT_PASSWORD=adminadmin +ENV DJANGO_WEB_PORT=8000 + +COPY pip.conf /root/.pip/pip.conf + +# 创建 myproject 文件夹 +RUN mkdir -p /var/www/html/ptools + +# 将 myproject 文件夹为工作目录 +WORKDIR /var/www/html/ptools + +# 将当前目录加入到工作目录中(. 表示当前目录) +ADD . /var/www/html/ptools +ADD ./start.sh /var/www/html + +# 更新pip版本 +#RUN /usr/local/bin/python -m pip install --upgrade pip + +# 利用 pip 安装依赖 +#RUN pip install -r requirements.txt + +# 去除windows系统编辑文件中多余的\r回车空格 +# RUN sed -i 's/\r//' ./start.sh + +# 给start.sh可执行权限 +RUN chmod +x /var/www/html/start.sh + +# 更换USTC源,并安装gcc,git +RUN #sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && apt update && yes|apt install gcc git && yes|apt autoremove gcc && apt-get autoclean +RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \ + && apt update \ +# && yes|apt upgrade \ + && yes|apt install git gcc mariadb-server default-libmysqlclient-dev build-essential \ + && pip install -r requirements.txt -U \ + && yes|apt autoremove gcc \ + && yes|apt autoremove \ + && apt-get autoclean \ + && service mariadb start \ + && rm -rf /var/lib/apt/lists/* \ + && mysqladmin -u root password $MARIADB_ROOT_PASSWORD + +VOLUME ["/var/lib/mysql"] + +EXPOSE $DJANGO_WEB_PORT + +EXPOSE 3306 + +ENTRYPOINT ["/bin/bash", "/var/www/html/start.sh"] \ No newline at end of file diff --git a/pt_test/docker_mariadb/requirements.txt b/pt_test/docker_mariadb/requirements.txt new file mode 100644 index 0000000..ca18e6b --- /dev/null +++ b/pt_test/docker_mariadb/requirements.txt @@ -0,0 +1,84 @@ +appnope==0.1.3 +APScheduler==3.9.1 +asgiref==3.5.2 +asttokens==2.0.8 +async-timeout==4.0.2 +backcall==0.2.0 +baidu-aip==4.16.7 +borax==3.5.6 +certifi==2022.6.15 +chardet==5.0.0 +charset-normalizer==2.1.1 +cloudscraper==1.2.64 +decorator==5.1.1 +defusedxml==0.7.1 +deluge-client==1.9.0 +Deprecated==1.2.13 +diff-match-patch==20200713 +Django==4.1 +django-admin-inline-paginator==0.3.0 +django-apscheduler==0.6.2 +django-import-export==2.8.0 +django-redis==5.2.0 +django-simpleui==2022.7.29 +docker==6.0.0 +et-xmlfile==1.1.0 +executing==0.10.0 +gitdb==4.0.9 +GitPython==3.1.27 +htmlgenerator==1.2.18 +idna==3.3 +importlib-metadata==4.12.0 +ipython==8.4.0 +jedi==0.18.1 +Jinja2==3.1.2 +lxml==4.9.1 +Markdown==3.4.1 +MarkupPy==1.14 +MarkupSafe==2.1.1 +matplotlib-inline==0.1.6 +mysqlclient==2.1.1 +numpy==1.23.2 +odfpy==1.4.1 +OpenCC==1.1.4 +openpyxl==3.0.10 +packaging==21.3 +pandas==1.4.3 +parso==0.8.3 +pexpect==4.8.0 +pickleshare==0.7.5 +prettytable==3.3.0 +prompt-toolkit==3.0.30 +ptyprocess==0.7.0 +pure-eval==0.2.2 +Pygments==2.13.0 +pyparsing==3.0.9 +pypushdeer==0.0.3 +python-dateutil==2.8.2 +pytz==2022.2.1 +pytz-deprecation-shim==0.1.0.post0 +PyYAML==6.0 +qbittorrent-api==2022.8.37 +redis==4.3.4 +requests==2.28.1 +requests-toolbelt==0.9.1 +simplejson==3.17.6 +six==1.16.0 +smmap==5.0.0 +sqlparse==0.4.2 +stack-data==0.5.0 +tablib==3.2.1 +traitlets==5.3.0 +transmission-rpc==3.3.2 +typing_extensions==4.3.0 +tzdata==2022.2 +tzlocal==4.2 +urllib3==1.26.12 +wcwidth==0.2.5 +websocket-client==1.4.0 +wechat-push==1.0.1 +wrapt==1.14.1 +wxpusher==2.2.0 +xlrd==2.0.1 +xlwt==1.3.0 +zipp==3.8.1 diff --git a/pt_test/docker_mariadb/start.sh b/pt_test/docker_mariadb/start.sh new file mode 100644 index 0000000..3ee0afa --- /dev/null +++ b/pt_test/docker_mariadb/start.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# 升级pip到最新 +python -m pip install --upgrade pip +service mariadb start +CONTAINER_ALREADY_STARTED="CONTAINER_ALREADY_STARTED_PLACEHOLDER" +if [ ! -e $CONTAINER_ALREADY_STARTED ]; then + echo "-- First container startup --" + # 此处插入你要执行的命令或者脚本文件 + git config --global init.defaultBranch master && +# git init && +# git remote add origin https://gitee.com/ngfchl/ptools && + # 设置拉取最新文件并覆盖 +# git config pull.ff only && +# git pull +# git checkout master && +# git branch --set-upstream-to=origin/master master + mysqladmin -u root password $MARIADB_ROOT_PASSWORD && + mysqladmin -u root -p$MARIADB_ROOT_PASSWORD create main && + pip install -r requirements.txt -U && + python manage.py makemigrations && + python manage.py migrate && + python manage.py loaddata pt.json + touch $CONTAINER_ALREADY_STARTED + # 创建超级用户 + DJANGO_SUPERUSER_USERNAME=$DJANGO_SUPERUSER_USERNAME \ + DJANGO_SUPERUSER_EMAIL=$DJANGO_SUPERUSER_EMAIL \ + DJANGO_SUPERUSER_PASSWORD=$DJANGO_SUPERUSER_PASSWORD \ + python manage.py createsuperuser --noinput +else + echo "-- Not first container startup --" + +fi +pip install -r requirements.txt -U && + python manage.py makemigrations && + python manage.py migrate && + python manage.py runserver 0.0.0.0:$DJANGO_WEB_PORT --noreload diff --git a/pt_test/supervisor/Supervisor.conf b/pt_test/supervisor/Supervisor.conf new file mode 100644 index 0000000..c603b31 --- /dev/null +++ b/pt_test/supervisor/Supervisor.conf @@ -0,0 +1,170 @@ +; Sample supervisor config file. +; +; For more information on the config file, please see: +; http://supervisord.org/configuration.html +; +; Notes: +; - Shell expansion ("~" or "$HOME") is not supported. Environment +; variables can be expanded using this syntax: "%(ENV_HOME)s". +; - Quotes around values are not supported, except in the case of +; the environment= options as shown below. +; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". +; - Command will be truncated if it looks like a config file comment, e.g. +; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ". +; +; Warning: +; Paths throughout this example file use /tmp because it is available on most +; systems. You will likely need to change these to locations more appropriate +; for your system. Some systems periodically delete older files in /tmp. +; Notably, if the socket file defined in the [unix_http_server] section below +; is deleted, supervisorctl will be unable to connect to supervisord. + +[unix_http_server] +file=/var/www/html/ptools/supervisor/supervisor.sock ; the path to the socket file +;chmod=0700 ; socket file mode (default 0700) +;chown=nobody:nogroup ; socket file uid:gid owner +;username=user ; default is no username (open server) +;password=123 ; default is no password (open server) + +; Security Warning: +; The inet HTTP server is not enabled by default. The inet HTTP server is +; enabled by uncommenting the [inet_http_server] section below. The inet +; HTTP server is intended for use within a trusted environment only. It +; should only be bound to localhost or only accessible from within an +; isolated, trusted network. The inet HTTP server does not support any +; form of encryption. The inet HTTP server does not use authentication +; by default (see the username= and password= options to add authentication). +; Never expose the inet HTTP server to the public internet. + +;[inet_http_server] ; inet (TCP) server disabled by default +port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface +username=admin ; default is no username (open server) +password=adminadmin ; default is no password (open server) + +[supervisord] +logfile=/var/www/html/ptools/supervisor/log/supervisord.log ; main log file; default $CWD/supervisord.log +logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB +logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 +loglevel=info ; log level; default info; others: debug,warn,trace +pidfile=/var/www/html/ptools/supervisor/supervisord.pid ; supervisord pidfile; default supervisord.pid +nodaemon=false ; start in foreground if true; default false +silent=false ; no logs to stdout if true; default false +minfds=1024 ; min. avail startup file descriptors; default 1024 +minprocs=200 ; min. avail process descriptors;default 200 +;umask=022 ; process file creation umask; default 022 +user=root ; setuid to this UNIX account at startup; recommended if root +;identifier=supervisor ; supervisord identifier, default is 'supervisor' +;directory=/tmp ; default is not to cd during start +;nocleanup=true ; don't clean up tempfiles at start; default false +;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP +;environment=KEY="value" ; key value pairs to add to environment +;strip_ansi=false ; strip ansi escape codes in logs; def. false + +; The rpcinterface:supervisor section must remain in the config file for +; RPC (supervisorctl/web interface) to work. Additional interfaces may be +; added by defining them in separate [rpcinterface:x] sections. + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +; The supervisorctl section configures how supervisorctl will connect to +; supervisord. configure it match the settings in either the unix_http_server +; or inet_http_server section. + +[supervisorctl] +serverurl=unix:///var/www/html/ptools/supervisor/supervisor.sock ; use a unix:// URL for a unix socket +;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket +username=admin ; should be same as in [*_http_server] if set +password=adminadmin ; should be same as in [*_http_server] if set +;prompt=mysupervisor ; cmd line prompt (default "supervisor") +;history_file=~/.sc_history ; use readline history if available + +; The sample program section below shows all possible program subsection values. +; Create one or more 'real' program: sections to be able to control them under +; supervisor. + +;[program:theprogramname] +;command=/bin/cat ; the program (relative uses PATH, can take args) +;process_name=%(program_name)s ; process_name expr (default %(program_name)s) +;numprocs=1 ; number of processes copies to start (def 1) +;directory=/tmp ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +;priority=999 ; the relative start priority (default 999) +;autostart=true ; start at supervisord start (default: true) +;startsecs=1 ; # of secs prog must stay up to be running (def. 1) +;startretries=3 ; max # of serial start failures when starting (default 3) +;autorestart=unexpected ; when to restart if exited after running (def: unexpected) +;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0) +;stopsignal=QUIT ; signal used to kill process (default TERM) +;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) +;stopasgroup=false ; send stop signal to the UNIX process group (default false) +;killasgroup=false ; SIGKILL the UNIX process group (def false) +;user=chrism ; setuid to this UNIX account to run the program +;redirect_stderr=true ; redirect proc stderr to stdout (default false) +;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO +;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) +;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stdout_events_enabled=false ; emit events on stdout writes (default false) +;stdout_syslog=false ; send stdout to syslog with process name (default false) +;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO +;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) +;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stderr_events_enabled=false ; emit events on stderr writes (default false) +;stderr_syslog=false ; send stderr to syslog with process name (default false) +;environment=A="1",B="2" ; process environment additions (def no adds) +;serverurl=AUTO ; override serverurl computation (childutils) + +; The sample eventlistener section below shows all possible eventlistener +; subsection values. Create one or more 'real' eventlistener: sections to be +; able to handle event notifications sent by supervisord. + +;[eventlistener:theeventlistenername] +;command=/bin/eventlistener ; the program (relative uses PATH, can take args) +;process_name=%(program_name)s ; process_name expr (default %(program_name)s) +;numprocs=1 ; number of processes copies to start (def 1) +;events=EVENT ; event notif. types to subscribe to (req'd) +;buffer_size=10 ; event buffer queue size (default 10) +;directory=/tmp ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +;priority=-1 ; the relative start priority (default -1) +;autostart=true ; start at supervisord start (default: true) +;startsecs=1 ; # of secs prog must stay up to be running (def. 1) +;startretries=3 ; max # of serial start failures when starting (default 3) +;autorestart=unexpected ; autorestart if exited after running (def: unexpected) +;exitcodes=0 ; 'expected' exit codes used with autorestart (default 0) +;stopsignal=QUIT ; signal used to kill process (default TERM) +;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) +;stopasgroup=false ; send stop signal to the UNIX process group (default false) +;killasgroup=false ; SIGKILL the UNIX process group (def false) +;user=chrism ; setuid to this UNIX account to run the program +;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners +;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO +;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) +;stdout_events_enabled=false ; emit events on stdout writes (default false) +;stdout_syslog=false ; send stdout to syslog with process name (default false) +;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO +;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) +;stderr_events_enabled=false ; emit events on stderr writes (default false) +;stderr_syslog=false ; send stderr to syslog with process name (default false) +;environment=A="1",B="2" ; process environment additions +;serverurl=AUTO ; override serverurl computation (childutils) + +; The sample group section below shows all possible group values. Create one +; or more 'real' group: sections to create "heterogeneous" process groups. + +;[group:thegroupname] +;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions +;priority=999 ; the relative start priority (default 999) + +; The [include] section can just contain the "files" setting. This +; setting can list multiple files (separated by whitespace or +; newlines). It can also contain wildcards. The filenames are +; interpreted as relative to this file. Included files *cannot* +; include files themselves. + +;[include] +files = ./cong/*.ini diff --git a/pt_test/supervisor/conf/ptools.ini b/pt_test/supervisor/conf/ptools.ini new file mode 100644 index 0000000..71fb7b7 --- /dev/null +++ b/pt_test/supervisor/conf/ptools.ini @@ -0,0 +1,13 @@ +[program:ptools] +command=python manage.py runserver 0.0.0.0:9000 --noreload +; the program (relative uses PATH, can take args) +;process_name=%(program_name)s ; process_name expr (default %(program_name)s) +;numprocs=1 ; number of processes copies to start (def 1) +directory=/var/www/html/ptools ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +priority=999 ; the relative start priority (default 999) +startsecs = 5 ; 启动 5 秒后没有异常退出,就当作已经正常启动了 +autostart=true +autorestart = true ; 程序异常退出后自动重启 +startretries = 3 ; 启动失败自动重试次数,默认是 3 +stdout_logfile = var/www/html/ptools/ptools.log \ No newline at end of file diff --git a/pt_test/supervisor/log/supervisord.log b/pt_test/supervisor/log/supervisord.log new file mode 100644 index 0000000..b7bf935 --- /dev/null +++ b/pt_test/supervisor/log/supervisord.log @@ -0,0 +1,21 @@ +2022-09-07 01:43:08,740 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message. +2022-09-07 01:43:08,757 INFO RPC interface 'supervisor' initialized +2022-09-07 01:43:08,759 INFO daemonizing the supervisord process +2022-09-07 01:43:08,763 INFO supervisord started with pid 78 +2022-09-07 01:46:46,843 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message. +2022-09-07 01:46:47,162 INFO RPC interface 'supervisor' initialized +2022-09-07 01:46:47,164 INFO daemonizing the supervisord process +2022-09-07 01:46:47,167 INFO supervisord started with pid 81 +2022-09-07 01:49:48,309 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message. +2022-09-07 01:57:32,859 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message. +2022-09-07 01:58:08,449 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message. +2022-09-07 01:58:08,765 INFO RPC interface 'supervisor' initialized +2022-09-07 01:58:08,767 INFO daemonizing the supervisord process +2022-09-07 01:58:08,770 INFO supervisord started with pid 108 +2022-09-07 01:58:34,406 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message. +2022-09-07 01:58:34,724 INFO RPC interface 'supervisor' initialized +2022-09-07 01:58:34,727 INFO supervisord started with pid 109 +2022-09-07 02:00:50,943 WARN received SIGINT indicating exit request +2022-09-07 02:00:58,643 INFO Set uid to user 0 succeeded +2022-09-07 02:00:58,652 INFO RPC interface 'supervisor' initialized +2022-09-07 02:00:58,655 INFO supervisord started with pid 116 diff --git a/pt_test/supervisor/supervisord.pid b/pt_test/supervisor/supervisord.pid new file mode 100644 index 0000000..4699eb3 --- /dev/null +++ b/pt_test/supervisor/supervisord.pid @@ -0,0 +1 @@ +116