Copy files to NAS storage at container startup, based on CakePHP v2.6.4 implementation
1. At this stage, there is a new requirement, and it is necessary to do some initial data work for the product when deploying the product. Prepare the corresponding SQL file, but for the file path in the MySQL table: /upload/20200817/20203555555373.png. It is stored in NAS storage. rather than the program directory. as shown in Figure 1
2. It is planned to automatically execute a PHP command line when the container is started to determine whether the default file exists in the NAS storage, and if it exists, it will exit. If it does not exist, copy it.
3. Implement all the files under App/WebRoot/Images/20200817 into the command line in App/Webroot/Upload/20200817. New file: app/console/command/assetshell.php
copy(UP_DIR . DS . 'upload' . DS . '20200817');
$this->out('Asset sync successfully.');
}
}
4. Enter the directory: E:\wwwroot\creditshop\app, execute: console/cake asset sync, copy all files under app/webroot/images/20200817 to app/webroot/upload/20200817. as shown in Figure 2
PS E:\wwwroot\creditshop\app> Console/cake asset sync
Welcome to CakePHP v2.6.4 Console
---------------------------------------------------------------
App : app
Path: E:\wwwroot\creditshop\app\
---------------------------------------------------------------
Asset sync successfully.
5. Run the corresponding command in the container, and copy all the files under /mcloud/creditshop/app/webroot/images/20200817 to /webtv/wangjie/creditbak/upload/20200817. /webtv is the mounted NAS storage. as shown in Figure 3
[root@465e0aa491eb /]# cd /webtv/wangjie/creditbak/upload
[root@465e0aa491eb upload]# ls -l
total 44
drwxrwxrwx 2 nginx nginx 106 Dec 17 2018 20181217
drwxrwxrwx 2 nginx nginx 4096 Jan 24 2019 20190124
drwxrwxrwx 2 nginx nginx 156 Feb 21 2019 20190221
drwxrwxrwx 2 nginx nginx 4096 Feb 22 2019 20190222
drwxrwxrwx 2 nginx nginx 4096 Feb 25 2019 20190225
drwxrwxrwx 2 nginx nginx 4096 Feb 28 2019 20190228
drwxrwxrwx 2 nginx nginx 106 Apr 9 2019 20190409
drwxrwxrwx 2 nginx nginx 155 Sep 11 2019 20190911
drwxrwxrwx 2 nginx nginx 4096 Nov 11 2019 20191111
drwxrwxrwx 2 nginx nginx 130 Nov 12 2019 20191112
drwxrwxrwx 2 nginx nginx 4096 Nov 13 2019 20191113
drwxrwxrwx 2 nginx nginx 130 Nov 14 2019 20191114
drwxrwxrwx 2 nginx nginx 4096 Nov 19 2019 20191119
drwxrwxrwx 2 nginx nginx 106 Nov 27 2019 20191127
drwxrwxrwx 2 nginx nginx 4096 Nov 29 2019 20191129
drwxrwxrwx 2 nginx nginx 129 Dec 21 2019 20191221
drwxrwxrwx 2 nginx nginx 4096 Jul 16 22:33 20200716
drwxrwxrwx 2 nginx nginx 4096 Aug 3 22:34 20200803
drwxrwxrwx 2 nginx nginx 4096 Aug 18 16:04 20200818
[root@465e0aa491eb upload]# cd /mcloud/creditshop/app
[root@465e0aa491eb app]# Console/cake asset sync
bash: Console/cake: Permission denied
[root@465e0aa491eb app]# chmod +x Console/cake
[root@465e0aa491eb app]# Console/cake asset sync
Welcome to CakePHP v2.6.4 Console
---------------------------------------------------------------
App : app
Path: /mcloud/creditshop/app/
---------------------------------------------------------------
Asset sync successfully.
[root@465e0aa491eb app]# cd /webtv/wangjie/creditbak/upload
[root@465e0aa491eb upload]# ls -l
total 44
drwxrwxrwx 2 nginx nginx 106 Dec 17 2018 20181217
drwxrwxrwx 2 nginx nginx 4096 Jan 24 2019 20190124
drwxrwxrwx 2 nginx nginx 156 Feb 21 2019 20190221
drwxrwxrwx 2 nginx nginx 4096 Feb 22 2019 20190222
drwxrwxrwx 2 nginx nginx 4096 Feb 25 2019 20190225
drwxrwxrwx 2 nginx nginx 4096 Feb 28 2019 20190228
drwxrwxrwx 2 nginx nginx 106 Apr 9 2019 20190409
drwxrwxrwx 2 nginx nginx 155 Sep 11 2019 20190911
drwxrwxrwx 2 nginx nginx 4096 Nov 11 2019 20191111
drwxrwxrwx 2 nginx nginx 130 Nov 12 2019 20191112
drwxrwxrwx 2 nginx nginx 4096 Nov 13 2019 20191113
drwxrwxrwx 2 nginx nginx 130 Nov 14 2019 20191114
drwxrwxrwx 2 nginx nginx 4096 Nov 19 2019 20191119
drwxrwxrwx 2 nginx nginx 106 Nov 27 2019 20191127
drwxrwxrwx 2 nginx nginx 4096 Nov 29 2019 20191129
drwxrwxrwx 2 nginx nginx 129 Dec 21 2019 20191221
drwxrwxrwx 2 nginx nginx 4096 Jul 16 22:33 20200716
drwxrwxrwx 2 nginx nginx 4096 Aug 3 22:34 20200803
drwxr-xr-x 2 root root 126 Aug 18 19:57 20200817
drwxrwxrwx 2 nginx nginx 4096 Aug 18 16:04 20200818
[root@465e0aa491eb upload]# cd 20200817
[root@465e0aa491eb 20200817]# ls -l
total 488
-rwxr-xr-x 1 root root 183116 Aug 18 17:16 20201164114857.png
-rwxr-xr-x 1 root root 32149 Aug 18 17:16 20202146638315.png
-rwxr-xr-x 1 root root 183116 Aug 18 17:16 20202503127232.png
-rwxr-xr-x 1 root root 96546 Aug 18 17:16 20203554555373.png
[root@465e0aa491eb 20200817]#
6. When the container starts, edit the shell script and run the php command line automatically.
env | grep "CREDITSHOP_CFG_PIC_DATASTATUS" || export CREDITSHOP_CFG_PIC_DATASTATUS="off"
if [[ $CREDITSHOP_CFG_PIC_DATASTATUS == "off" ]]
then
echo "不运行命令"
elif [[ $CREDITSHOP_CFG_PIC_DATASTATUS == "on" ]]
then
cd /mcloud/creditshop/app
chmod +x Console/cake
Console/cake asset sync
echo "运行命令"
fi
7. View the log of the container, run successfully, in line with expectations. as shown in Figure 4
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_TENANT_URL=http://tenant1.xcttest.chinamcloud.cn/
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_APPNAME=creditshop
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_SECRET=02bcebf67be82fc6c596f7aaab159833090189d8
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_PIC_PORT=80
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_SERVER_PORT=80
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_MEMBERAPI_URL=http://memberapi.wjtest.chinamcloud.cn/memberapi
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_IDA_URL=http://ida.xcttest.chinamcloud.cn
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_QYWX_KEY=okqb7vqm8y2I6Q7zeyyY9K1JfTzs
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_QYWX_URL=qywx.wjtest.chinamcloud.cn
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_PIC_DIR=/webtv/wangjie/creditbak
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_FILE_DIR=/webtv/wangjie/creditbak
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_MSERVER_URL=http://mserver.wjtest.chinamcloud.cn/creditbak
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_QYHD_URL=http://morefunapi.wjtest.chinamcloud.cn
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_BMSHD_URL=http://default.bms.wjtest.chinamcloud.cn
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_ACCESS_KEY_ID=DdEBQtT801LjMuYw
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_ACCESS_KEY_SECRET=FyVST8x73D1AKlhG9brEHvgWkwdeNipz
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_CHECK_USER_LOGIN_URL=http://cmcconsole.wjtest.chinamcloud.cn/interface/get-user-auth
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_USER_LOGIN_URL=http://cmcgroup.wjtest.chinamcloud.cn/?call_back=http://creditshop.wjtest.chinamcloud.cn
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_REDIS_HOST=192.168.2.6
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_REDIS_PASSWORD=q5dHP@xCBUUJY^L
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_REDIS_DB=5
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_FILE_DIR=/webtv/wangjie/creditbak
2020/8/19 下午 3:56:30 CREDITSHOP_CFG_PIC_DATASTATUS=on
2020/8/19 下午 3:56:30
2020/8/19 下午 3:56:30 Welcome to CakePHP v2.6.4 Console
2020/8/19 下午 3:56:30 ---------------------------------------------------------------
2020/8/19 下午 3:56:30 App : app
2020/8/19 下午 3:56:30 Path: /mcloud/creditshop/app/
2020/8/19 下午 3:56:30 ---------------------------------------------------------------
2020/8/19 下午 3:56:30 Asset sync successfully.
2020/8/19 下午 3:56:30 运行命令



