在Ubuntu服务器上启动GitHub repo

我有一个自动调节的EC2组,我有一个使用服务器之间的Git的中央configuration。 他们用钥匙设置,所以他们不需要密码。

我想确保何时从AMI开始创build(使用可能过时的configuration),使用普通的git pull命令来拉取configuration。 该命令必须作为某个用户来执行,因为只有该用户可以通过它的主目录中的RSA密钥进行混帐。

所以本质上在服务器上启动某个用户需要运行git pull在某个存储库。

您可以在/etc/rc.local中设置该命令。 修改图像中的rc.local,使其包含以下几行内容:

#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. pushd /certain/repository su -s /bin/bash -c "git pull" <username> popd exit 0 

只需replace你想要运行的'git pull'权限。 另外,为了以防万一,请不要忘记运行:

 chmod +x /etc/rc.local 

这是来自rc.local的相关RedHat文档的一部分,但在所有发行版本上基本相同:

/etc/rc.d/rc.local脚本在启动时或在更改运行级别时由init命令执行。 在这个脚本的底部添加命令是一个简单的方法来执行必要的任务,如启动特殊服务或初始化设备,而无需在/etc/rc.d/init.d/目录中编写复杂的初始化脚本并创build符号链接。