在网上搜了一堆没用找到太仔细的教程,于是花费2天时间,自己研究了下。现在分享如下:

思路:利用crontab定时去去执行git pull脚本

首先,用git clone命令将中央库的代码下载到阿里云

git clone https://username:psw@git.oschina.net/xapp/xserver.git  xm

第二步、在项目目录  /opt/lampp/htdocs/xm  下创建一个脚本 xm-pull.sh ,内容如下:

#!/bin/bash
cd /opt/lampp/htdocs/xm
/usr/bin/git pull https://username:psw@git.oschina.net/xapp/xserver.git  master:master

第三步、cd ~ 进入到个人目录,创建CRONTAB定时器文件 xm-cron

[root@iZ254lfyd6nZ xm]# cd ~
[root@iZ254lfyd6nZ ~]# ls
hello.txt  test-conf  xm-cron
[root@iZ254lfyd6nZ ~]# vi xm-cron
* * * * * /bin/bash  /opt/lampp/htdocs/xm/xm-pull.sh

注:定时每隔一分钟去执行git pull脚本

第四步、开启执行CRONTAB定时器,并查看当前运行的crontab状态或日志

[root@iZ254lfyd6nZ ~]# crontab -l
* * * * * /bin/bash  /opt/lampp/htdocs/xm/xm-pull.sh
[root@iZ254lfyd6nZ ~]# tail -f /var/log/cron
Jun  3 11:24:01 iZ254lfyd6nZ CROND[10636]: (root) CMD (/bin/bash  /opt/lampp/htdocs/xm/xm-pull.sh)
Jun  3 11:25:01 iZ254lfyd6nZ CROND[10689]: (root) CMD (/bin/bash  /opt/lampp/htdocs/xm/xm-pull.sh)
Jun  3 11:26:01 iZ254lfyd6nZ CROND[10742]: (root) CMD (/bin/bash  /opt/lampp/htdocs/xm/xm-pull.sh)


如果发现crontab在执行,但是没有去Pull代码过来,可以重启下crontab服务:
启动、停止、重启crond服务:
#/sbin/service crond start
#/sbin/service crond stop
#/sbin/service crond restart


相关文章:

  • 2021-06-20
  • 2021-05-09
  • 2021-10-21
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2021-10-30
猜你喜欢
  • 2021-10-26
  • 2021-12-27
  • 2022-01-04
  • 2021-09-19
  • 2021-08-02
  • 2021-06-24
  • 2022-12-23
相关资源
相似解决方案