code.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // +----------------------------------------
  3. // | overlay文件系统目录分布
  4. // +----------------------------------------
  5. $lowerDir = realpath(__DIR__."/../../smartLEDZ"); // read层·原始文件
  6. $upperDir = realpath(__DIR__."/../../smartLEDZ_Upper"); // write层
  7. $mergedDir = realpath(__DIR__."/../../smartLEDZ_Merged"); // 读写·数据交互层(read层 + write层) - [ 程序运行在此 ]
  8. $app_path = $lowerDir; // 当前运行的项目主目录
  9. $targetDir = $lowerDir; //
  10. if(is_dir($mergedDir)){ // 存在overlay
  11. $app_path = $mergedDir;
  12. $targetDir = $mergedDir;
  13. }
  14. if(file_exists($app_path . "/logs/gw_back")){
  15. unlink($app_path . "/logs/gw_back");
  16. }
  17. if(!is_dir($app_path . "/restore")) mkdir($app_path . "/restore");
  18. $unCmd = sprintf("tar -xvf %s/smartLEDZ_DB_U.tar -C %s/restore", $app_path, $app_path);
  19. exec($unCmd);
  20. // 检查备份文件是什么APP版本备份的
  21. exec("tar -tf " . $app_path."/smartLEDZ_DB_U.tar", $output);
  22. if(in_array("overlay/www/smartLEDZ/db/smartLEDZ.db", $output)){
  23. // 旧overlay版备份
  24. exec(sprintf("cp -r %s/restore/overlay/www/smartLEDZ/* %s", $app_path, $targetDir));
  25. exec(sprintf("rm -rf %s/restore/overlay", $app_path));
  26. }else if(in_array("mnt/mmcblk0p1/www/smartLEDZ/db/smartLEDZ.db", $output)){
  27. // 旧版APP备份
  28. exec(sprintf("cp -r %s/restore/mnt/mmcblk0p1/www/smartLEDZ/* %s", $app_path, $targetDir));
  29. exec(sprintf("rm -rf %s/restore/mnt", $app_path));
  30. }else if(in_array("mnt/mmcblk0p1/www/smartLEDZ_Merged/db/smartLEDZ.db", $output)){
  31. // 新overlay版备份
  32. exec(sprintf("cp -r %s/restore/mnt/mmcblk0p1/www/smartLEDZ_Merged/* %s", $app_path, $targetDir));
  33. exec(sprintf("rm -rf %s/restore/mnt", $app_path));
  34. }
  35. exec(sprintf("cp -r %s/db/exec.json.bak %s/db/exec.json", $targetDir, $targetDir));
  36. // 热重载Socket
  37. file_put_contents($app_path . "/workerman/reload", "");