如何从符号链接更新之前访问原始文件,这些文件已被移至另一个目录

我们有一个网站,我们的部署过程有些像下面这样(不包括大量不相关的步骤)

echo "Remove previous, if it exists, we don't need that anymore" rm -rf /home/[XXX]/php_code/previous echo "Create the current dir if it doesn't exist (just in case this is the first deploy to this server)" mkdir -p /home/[XXX]/php_code/current echo "Create the var_www dir if it doesn't exist (just in case this is the first deploy to this server)" mkdir -p /home/[XXX]/var_www echo "Copy current to previous so we can use temporarily" cp -R /home/[XXX]/php_code/current/* /home/[XXX]/php_code/previous/ echo "Atomically swap the symbolic link to use previous instead of current" ln -s /home/[XXX]/php_code/previous /home/[XXX]/var_www/live_tmp && mv -Tf /home/[XXX]/var_www/live_tmp /home/[XXX]/var_www/live # Rsync latest code into the current dir, code not shown here echo "Atomically swap the symbolic link to use current instead of previous" ln -s /home/[XXX]/php_code/current /home/[XXX]/var_www/live_tmp && mv -Tf /home/[XXX]/var_www/live_tmp /home/[XXX]/var_www/live 

我们现在遇到的问题是,网页加载的第一件事是编写应用程序的基本目录,并将其定义为一个常量(我们使用PHP)。 如果在页面加载期间发生部署,则系统尝试使用原始完整pathinclude()文件,并将获得该文件的新版本。 我们需要它从旧的目标中得到旧的目标,

  1. 系统启动页面加载并确定SYSTEM_ROOT_PATH常量为/home/[XXX]/var_www/live或者使用PHP的realpath()它可能是/home/[XXX]/php_code/current

  2. /home/[XXX]/var_www/live获取更新指向/home/[XXX]/php_code/previous而不是/home/[XXX]/php_code/current原来的位置。

  3. 系统尝试加载/home/[XXX]/var_www/live/something.php并获取/home/[XXX]/php_code/current/something.php而不是/home/[XXX]/php_code/previous/something.php

如果不能很好地解释,我很抱歉。 我真的很感激有关如何解决这个问题的一些想法,如果有人可以。 谢谢。

current不应该是包含您的文件的实际目录,而是一个符号链接。 这是卡皮斯特拉诺这样做的方式:

  1. 创build一个以当前date命名的目录。
  2. 将新文件部署到该目录。
  3. 改变current符号链接指向新的目录。
  4. 删除任何旧的不需要的目录。