2013-04-10 72 views
5

我正在使用ec2 instance @ ubuntu。我嘗試從AMI啓動新實例後自動執行「git pull」。回購目錄已經在我的AMI中,我需要的只是更新回購。當我的服務器啓動時,我該如何自動執行「git pull」

什麼我現在做的是我把「混帳拉起源大師」在rc.local中....但它不工作....

+0

這可能給你一個提示:http://askubuntu.com/questions/9853/how-can-i-make- rc-local-run-on-startup – rcomblen 2013-04-10 20:51:02

回答

2

git --git-dir=some/dir/.git pull origin master應該工作

+0

我懂了它的工作原理 – Wen 2013-04-10 21:22:08

4

我得到了它工作..

須藤-u Ubuntu的-i混帳--git-DIR = /家庭/ Ubuntu的/升空/ git的 - 共同努力樹= /家庭/ Ubuntu的/升空/取起源 須藤-u的ubuntu -i git --git-dir =/home/ubuntu/blastoff/.git --work-tree =/home/ubuntu/blastoff/merge origin/master

0

The放置代碼的地方不是/etc/rc.local/,而是~/.profile。然後,您可以以登錄用戶身份運行命令,而不需要sudosu來更改運行命令的用戶。

0

https://stackoverflow.com/a/8880633/659188記筆記和你以上工作的答案,你可以在你的rc.local文件做這樣的事情將此潛在多個文件夾(也只能拉電流分支,而不是總是被大師):

#!/bin/bash -e 
# /etc/rc.local 

# Ensure folders in array have a trailing slash! 

declare -a folders=("/var/www/html/project1/" "/var/www/html/project2/" "/some/other/location/") 

# Update to latest in all above folders 

for i in "${folders[@]}" 
do 
     sudo -u ubuntu -i git --git-dir=$i/.git --work-tree=$i fetch origin 
     sudo -u ubuntu -i git --git-dir=$i/.git --work-tree=$i pull 
done 

exit 0 
0

如果您想在創建實例(第一次啓動)時執行git pull,則可以使用cloud-init

檢查AWS文檔To pass a shell script to an instance with user data

這可以通過使用ansible/saltstack等,但進行測試,你可以手動上傳腳本自動化。在高級詳細信息的第3步「配置實例」中,選擇選項作爲文件,並將腳本放在下面。

enter image description here

你可以上傳你有自定義腳本:

#!/bin/sh 

echo "git pull or any other custom commands here" 
相關問題