【发布时间】:2013-08-12 03:22:41
【问题描述】:
我的本地机器上有一个 PHP 项目,具有以下文件夹结构
assets/
|- css/
|- ...
|- js/
|- ...
dynamic/
|- scripts/ *contains a bunch of .php files
计划是使用s3cmd 将assets/ 目录推送到Amazon S3(与CloudFront CDN 一起使用),并将dynamic/ 文件直接推送到Amazon EC2 实例(网络服务器)。
我在下面使用的基本脚本:
[push.sh]
#!/bin/bash
# Source our program variables
. ./_global.sh
# Setup the build directory
echo "======== Preparing the build directory =============="
node build/r.js -o build/build.js
# Start up the rsync to push the dynamic files
echo "==== Syncing dynamic files with the EC2 instance ===="
rsync -rvzh --progress --delete --exclude-from "${BUILD_DIR}exclude-list.txt" \
-e "ssh -i ${BUILD_DIR}mykey.pem" \
$WWW_BUILT_DIR ubuntu@$SERVER_IP:$SERVER_DIR
# Push the static assets up to S3
echo "========== Pushing static assets to the S3 ========="
s3cmd sync --delete-removed --exclude-from "${BUILD_DIR}exclude-list.txt" \
${WWW_DIR}${ASSETS} s3://mybucketname/${ASSETS}
echo "All done :)"
一切正常,除了推送到 EC2 Web 服务器的文件的权限全部设置为在 ssh 命令 (ubuntu) 中配置的用户。如何将其设置为使用:www-data?
【问题讨论】:
-
也许您可以设置一个以 root 身份定期在正确目录上运行
chown和chmod的 cron 作业? -
@Paul 是的,我想我可以,但这会留下一个窗口,其中文件存在的权限无效(在它们被推送的时间和 cron 作业运行的时间之间)可能是对生意不利。
-
那么您需要一个存放此类事情的区域,您指定的某个目录,然后在有效时将这些内容移动或复制到生产目录。
-
@Paul 感谢您的帮助,但
JTheRockers 下面的回答很好地解决了我的问题。
标签: bash amazon-web-services amazon-ec2 file-permissions chown