Ver código fonte

调整安装脚本,适配于 systemd。

James Iter 7 anos atrás
pai
commit
6a5470fb02
6 arquivos alterados com 65 adições e 64 exclusões
  1. 20 44
      INSTALL.sh
  2. 4 4
      docs/todo.md
  3. 1 1
      gunicorn_config.py
  4. 1 1
      jimvc/themes/default/templates/about.html
  5. 25 0
      misc/jimvc.service
  6. 14 14
      requirements.txt

+ 20 - 44
INSTALL.sh

@@ -14,19 +14,14 @@
 #   bash -c "$(curl -fsSL https://raw.githubusercontent.com/jamesiter/JimV-C/dev/INSTALL.sh)" -- --version dev
 
 export PYPI='https://mirrors.aliyun.com/pypi/simple/'
-export JIMVC_REPOSITORY_URL='https://github.com/jamesiter/JimV-C.git'
-export JIMVC_REPOSITORY_URL_CN='https://gitee.com/jimit/JimV-C.git'
 export JIMVC_REPOSITORY_RAW_URL='https://raw.githubusercontent.com/jamesiter/JimV-C'
-export COUNTRY=`curl http://iit.im/ip/country`
+export JIMVC_DOWNLOAD_URL='https://github.com/jamesiter/JimV-C/archive/master.tar.gz'
+export JIMVC_PATH='/usr/local/JimV-C'
 export GENERATE_PASSWORD_SCRIPT_TMP_PATH='/tmp/gen_pswd.sh'
 export SMTP_HOST=''
 export SMTP_USER=''
 export SMTP_PASSWORD=''
 
-if [ ${COUNTRY} = 'CN' ]; then
-    export JIMVC_REPOSITORY_URL=${JIMVC_REPOSITORY_URL_CN}
-fi
-
 ARGS=`getopt -o h --long rdb_root_password:,rdb_jimv_password:,redis_password:,jwt_secret:,secret_key:,version:,help -n 'INSTALL.sh' -- "$@"`
 
 eval set -- "${ARGS}"
@@ -56,6 +51,7 @@ do
             ;;
         --version)
             export JIMV_VERSION=$2
+            export JIMVC_DOWNLOAD_URL=$(sed s@master@${JIMV_VERSION}@ <<< ${JIMVC_DOWNLOAD_URL})
             shift 2
             ;;
         -h|--help)
@@ -259,46 +255,32 @@ function install_Nginx() {
 }
 
 function create_web_user() {
-    useradd -m www
-}
-
-function create_web_sites_directory() {
-    su - www -c "mkdir ~/sites"
+    useradd -M www
 }
 
-function clone_and_checkout_JimVC() {
-    su - www -c "git clone ${JIMVC_REPOSITORY_URL} ~/sites/JimV-C"
-    su - www -c "cd ~/sites/JimV-C && git checkout ${JIMV_VERSION}"
+function get_JimVC() {
+    mkdir -p ${JIMVC_PATH}
+    curl -sL ${JIMVC_DOWNLOAD_URL} | tar -zxf - --strip-components 1 -C ${JIMVC_PATH}
 }
 
 function install_dependencies_library() {
-    # 指定 www 用户 pip 源
-    su - www -c "mkdir -p ~/.pip"
-    su - www -c "cat > ~/.pip/pip.conf << EOF
+    mkdir -p ~/.pip
+    cat > ~/.pip/pip.conf << EOF
 [global]
 index-url = ${PYPI}
 EOF
-"
 
     # 创建 python 虚拟环境
-    su - www -c "virtualenv --system-site-packages ~/venv"
+    virtualenv --system-site-packages /usr/local/venv-jimv
 
     # 导入 python 虚拟环境
-    su - www -c "source ~/venv/bin/activate"
+    source /usr/local/venv-jimv/bin/activate
 
-    # 使切入 www 用户时自动导入 python 虚拟环境
-    su - www -c "echo '. ~/venv/bin/activate' >> .bashrc"
+    # 自动导入 python 虚拟环境
+    echo '. /usr/local/venv-jimv/bin/activate' >> .bashrc
 
     # 安装 JimV-C 所需扩展库
-    su - www -c "pip install -r ~/sites/JimV-C/requirements.txt -i ${PYPI}"
-}
-
-function fit_www_user_permission() {
-    mkdir -p /var/log/jimv
-    chown www.www /var/log/jimv
-
-    mkdir -p /run/jimv
-    chown www.www /run/jimv
+    pip install -r ${JIMVC_PATH}/requirements.txt -i ${PYPI}
 }
 
 function initialization_db() {
@@ -306,7 +288,7 @@ function initialization_db() {
     mysql -u root -p${RDB_ROOT_PSWD} -e "grant all on jimv.* to jimv@localhost identified by \"${RDB_JIMV_PSWD}\"; flush privileges"
 
     # 初始化数据库
-    su - www -c "mysql -u jimv -p${RDB_JIMV_PSWD} < ~/sites/JimV-C/misc/init.sql"
+    mysql -u jimv -p${RDB_JIMV_PSWD} < ~/sites/JimV-C/misc/init.sql
 
     # 确认是否初始化成功
     mysql -u jimv -p${RDB_JIMV_PSWD} -e 'show databases'
@@ -321,13 +303,9 @@ function generate_config_file() {
     sed -i "s/\"smtp_host\".*$/\"smtp_host\": \"${SMTP_HOST}\",/" /etc/jimvc.conf
     sed -i "s/\"smtp_user\".*$/\"smtp_user\": \"${SMTP_USER}\",/" /etc/jimvc.conf
     sed -i "s/\"smtp_password\".*$/\"smtp_password\": \"${SMTP_PASSWORD}\",/" /etc/jimvc.conf
-}
 
-function generate_pid_directory_ad_reboot() {
-    chmod +x /etc/rc.d/rc.local
-    echo '' >> /etc/rc.d/rc.local
-    echo 'mkdir /run/jimv' >> /etc/rc.d/rc.local
-    echo 'chown www.www /run/jimv' >> /etc/rc.d/rc.local
+    cp -v /usr/local/JimV-C/misc/jimvc.service /etc/systemd/system/jimvc.service
+    systemctl daemon-reload
 }
 
 function display_summary_information() {
@@ -342,7 +320,8 @@ function display_summary_information() {
     echo "JimV-C 已经安装完成,您再需如下几步就能完成整个 JimV 的部署: "
     echo
     echo "--->"
-    echo "1: 执行 '/home/www/sites/JimV-C/startup.sh' 启动 JimV-C。"
+    echo "1: 现在可以通过命令 'systemctl start jimvc.service' 启动运行 JimV-C。"
+    echo "可通过 'systemctl enable jimvc.service' 把 JimV-C 注册为随系统启动服务。"
     echo
     echo "--->"
     echo "2: 通过 Web 页面 http://`hostname -I` 初始化 JimV-C。"
@@ -365,15 +344,12 @@ function deploy() {
     prepare
     set_ntp
     create_web_user
-    create_web_sites_directory
-    clone_and_checkout_JimVC
-    fit_www_user_permission
+    get_JimVC
     install_MariaDB
     install_Redis
     install_Nginx
     install_dependencies_library
     initialization_db
-    generate_pid_directory_ad_reboot
     generate_config_file
     display_summary_information
 }

+ 4 - 4
docs/todo.md

@@ -58,7 +58,7 @@
 - [ ] 考虑开辟一个单独的消息处理线程。所有业务消息都塞到进程中的队列内,由该线程统一处理。这样可以更好的处理数据库重连问题。
 - [ ] 实现 CentOS 7 单机版一建安装脚本(包括全新的数据库安装、配置、部署)
 - [ ] 实现磁盘联动机制。即当删除宿主机时,相随的所有磁盘一并删除
-- [ ] 融入 Systemd
+- [x] 融入 Systemd
 - [ ] 增加模板镜像上传功能
 - [ ] 加入 Tag或分组,类似qq用户分组 功能
 - [ ] 添加对 Guest 的 IP 管理功能
@@ -76,7 +76,7 @@
 - [ ] 考虑热更新、升级的问题
 - [ ] 加入清除老旧日志的功能
 - [ ] 忽略 guestfs- 为首的日志
-- [ ] 周期轮询试的同步虚拟机状态
+- [x] 周期轮询试的同步虚拟机状态
 - [ ] 实现类似于VMware的故障转移功能
 - [x] 实现变配功能
 - [ ] 迁移中的虚拟机,不允许做任何操作
@@ -91,8 +91,8 @@
 - [x] 计算节点以 JimV-C 为第一 NTP 服务器
 - [ ] 数据库时间戳,采用 JimV-N 的时间。避免 JimV-C 挂掉后,监控数据批量集中在同一个时间点上
 - [ ] 加入监控图标汇聚功能,时间范围内的平均值、最高值
-- [ ] 加入 About 页面
-- [ ] 在 About 页面,展现当前版本号
+- [x] 加入 About 页面
+- [x] 在 About 页面,展现当前版本号
 - [ ] 在 About 页面,展现是否可以升级信息
 - [ ] 在 About 页面,加入更新功能
 - [ ] 大于 内存、负载 百分比后,禁止创建虚拟机

+ 1 - 1
gunicorn_config.py

@@ -26,7 +26,7 @@ bind = _config['listen'] + ':' + _config['port'].__str__()
 workers = multiprocessing.cpu_count() * 2 + 1
 worker_class = 'gevent'
 worker_connections = 1000
-daemon = True
+daemon = False
 
 accesslog = '/'.join([log_file_dir, 'access.log'])
 errorlog = '/'.join([log_file_dir, 'error.log'])

+ 1 - 1
jimvc/themes/default/templates/about.html

@@ -37,7 +37,7 @@
             <h3 class="title-hero" style="text-transform: unset;">
                 关于 JimV
             </h3>
-            <div class="example-box-wrapper" style="text-align: center; top: 50px;">
+            <div class="example-box-wrapper" style="text-align: center; top: 40px;">
                 <a href="javascript:;" class="logo-content-big" title="JimV" style="font-family: Baskerville; font-size: 120px; color: #0275d8; text-decoration: none; display: block; text-align: center;">
                     JimV
                 </a>

+ 25 - 0
misc/jimvc.service

@@ -0,0 +1,25 @@
+[Unit]
+Requisite=network-online.target mariadb.service redis.service nginx.service
+After=network-online.target network.target mariadb.service redis.service nginx.service
+
+[Install]
+WantedBy=multi-user.target
+
+[Service]
+PIDFile=/run/jimv/jimvc.pid
+Type=idle
+User=www
+Group=www
+RestartSec=2s
+ExecStartPre=/usr/bin/mkdir -p /run/jimv
+ExecStartPre=/usr/bin/mkdir -p /var/log/jimv
+ExecStartPre=/usr/bin/chown -R www.www /run/jimv
+ExecStartPre=/usr/bin/chown -R www.www /var/log/jimv
+ExecStartPre=-/usr/bin/chown -R www.www /tmp/jimv
+PermissionsStartOnly=true
+#工作目录
+WorkingDirectory=/usr/local/JimV-C/
+#命令行(必须使用绝对路径)
+ExecStart=/usr/local/venv-jimv/bin/gunicorn -c gunicorn_config.py main:app
+#启动或者停止服务最大允许花费60秒
+TimeoutSec=60s

+ 14 - 14
requirements.txt

@@ -1,14 +1,14 @@
-Flask=0.10.1
-mysql-connector-python-rf=2.2.2
-enum34=1.1.2
-jimit=0.62
-requests=2.9.1
-PyJWT=1.4.1
-Flask-Session=0.3.0
-IPy=0.83
-gunicorn=19.4.5
-gevent=1.1.2
-redis=2.10.5
-websockify=0.8.0
-Werkzeug=0.11.4
-flask-themes2=0.1.4
+Flask==0.10.1
+mysql-connector-python-rf==2.2.2
+enum34==1.1.2
+jimit==0.62
+requests==2.9.1
+PyJWT==1.4.1
+Flask-Session==0.3.0
+IPy==0.83
+gunicorn==19.4.5
+gevent==1.1.2
+redis==2.10.5
+websockify==0.8.0
+Werkzeug==0.11.4
+flask-themes2==0.1.4