How can I do "git pull" automatically when my server starts

I am using an ec2 @ubuntu instance. I am trying to automatically execute "git pull" after I start a new instance from AMI. The repo dir is already in my AMI, all I need is updating the repo.

What am I doing now, I put the "git pull origin master" in rc.local .... but it does not work ....

+5
source share
5 answers

I got it for work.

sudo -u ubuntu -i git - git -dir = / home / ubuntu / blastoff / .git --work-tree = / home / ubuntu / blastoff / fetch origin sudo -u ubuntu -i git - git -dir = / home /ubuntu/blastoff/.git --work-tree = / home / ubuntu / blastoff / merge origin / master

+4
source

git --git-dir=some/dir/.git pull origin master must work

+2
source

/etc/rc.local/, ~/.profile. sudo su , .

0

fooobar.com/questions/12613/... , , - 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.

Verify AWS documents pass shell script instance with user data

This can be automated using ansible / saltstack , etc., but for testing you can manually load the script. In step 3, “Configure Instance” in “Preliminary Details”, select the “File” option and place the script below.

enter image description here

You can load your custom script there:

#!/bin/sh

echo "git pull or any other custom commands here"
0
source

All Articles