zoukankan      html  css  js  c++  java
  • git 利用hook 实现服务器自动更新代码

    如何利用git的hook实现提交代码后自动更新?

    因为个人开发经常需要提交代码,每次都需要连接服务器去pull代码,重启服务器就显得十分繁琐,因此github提供了一个时间钩子,用户push代码后可以通知指定服务器进行操作

    编写服务器脚本

    脚本仅仅用于接受代码托管服务器的通知,因此应该尽量比较各种依赖问题,所以我们选择在linux自带的python2 上开发,使用原生的wsgiref模块

    from wsgiref.simple_server import make_server
    import os
    def run(env,start_response):
        url=env['PATH_INFO']
        if url=="/githook/":
            out=os.system('/website/Tadmin/pub.sh')
            start_response('200 OK', [('Content-Type', 'text/html')])
            return str(out)
        start_response('200 OK', [('Content-Type', 'text/html')])
        return "hello"
    
    if __name__ == '__main__':
        httpd = make_server('', 8080, run)
        print "server running on 8080"
        httpd.serve_forever()  #allays running
    
    

    当知道服务器有新的push,可以在客户端执行一系列的更新操作,在上面我们直接调用了shell脚本执行

    cd '/website/YourProject'
    git pull
    uwsgi --reload /website/YourProject/uwsgi.pid
    ps -ef | grep uwsgi
    

    server的启动直接使用CMD:nohup python server.py &
    最后就是设置git的webhook 然后push代码 服务器就会自动同步了

  • 相关阅读:
    jQuery插件实践之轮播练习(二)
    jQuery插件实践之轮播练习(一)
    AngularJS+Node.js+socket.io 开发在线聊天室
    Ubuntu上部署Ghost博客
    综合架构的简述
    进程
    路由配置
    计算机专用英语词汇1695个词汇表
    Linux打包压缩解压工具
    磁盘知识体系结构
  • 原文地址:https://www.cnblogs.com/tongchengbin/p/10364161.html
Copyright © 2011-2022 走看看