zoukankan      html  css  js  c++  java
  • 【前端】CentOS 7 系列教程之四: 配置 git 服务器自动部署

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/linux_4.html

    安装pm2守护进程,备用

    npm install -g pm2

    创建/srv/www文件夹

    mkdir /srv/www

    进入/srv/www文件夹

    cd /srv/www

    克隆服务器的本地仓库

    git clone /data/git/test.git

    把/srv/www的权限给git

    chown -R git:git /srv/www

    创建git钩子文件post-receive,会在接收完push请求后执行,这个文件不一定存在,不过无所谓

    vim /data/git/test.git/hooks/post-receive

    内容如下

    echo "==========================================="
    cd /srv/www/test
    unset GIT_DIR
    git pull
    if [ -f "package.json" ];then
    echo "存在package.json文件,开始部署"
    echo -e "node version: c"
    node -v
    echo -e "npm version: vc"
    npm -v
    # 杀掉进程test-production
    pm2 delete test-production
    # 删除node_modules
    rm -rf node_modules
    # 重新初始化
    npm install
    # 以test-production为名启动pm2的守护进程
    pm2 start index.js -i 1 --name "test-production"
    else
    echo "package.json文件不存"
    fi
    echo "==========================================="

    然后让这个文件变为可执行文件

    chmod +x /data/git/test.git/hooks/post-receive

    然后把权限重新给git一下

    chown -R git:git /data/git

    然后在客户端提交一下试试看

    注意remote开头的那一段,都是服务器端打印的。

    不过此时pm2的守护进程是由git用户开启的,其他用户看不到,pm2在start的时候虽然有个--username的参数,貌似是可以指定用户,但是并没有什么效果,有谁知道可以说一下

    所以如果要操作此守护进程,比如查看实时日志,需要切换到git用户,。

    好了,现在git自动部署已经完成了。

  • 相关阅读:
    Mac下搭建php开发环境
    phalcon:跟踪sql语句
    phalcon的CLI应用
    phalcon遇到的那些坑
    浏览器 批量大文件上传下载
    网页 批量大文件上传下载
    B/S 批量大文件上传下载
    JavaScript 批量大文件上传下载
    js 批量大文件上传下载
    vue 批量大文件上传下载
  • 原文地址:https://www.cnblogs.com/shamoyuu/p/linux_4.html
Copyright © 2011-2022 走看看