Said in the previous
We usually develop in the local environment when we are developing. After the development and test is completed, we often need to upload files to the server after local packaging. Such operations are very tedious, and sometimes they may not be timely, so it is impossible to ensure real-time update of the server code. Hence the idea of writing this periodic auto-update code and packaging the project script.
Train of thought
- 1. Create a folder on the server to place the Git repository code and configure the Git environment
- 2. Write automatic update scripts
- 3. Set a scheduled task
Script code
#! /bin/bash -ilex
## author:jyeontuEcho "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --" echo "-- -- -- -- -- -- -- -- -- -- begin to execute a script -- -- -- -- -- -- -- -- -- --" the date the PWD. Echo "git directory"#Switch to the absolute path of the git code directorycd /www/wwwroot/ip/myGiteeCode/myProject; pwd; Git pull; Echo "prepare project" NPM run build; Echo "Delete old files"#Switch to the project directory that needs to be updated
cd /www/wwwroot/ip/myProject
pwd
#Delete old filesrm -rf * ls; Echo "Move new file"#Copy the latest code package file to the project directorycp -r /www/wwwroot/ip/myGiteeCode/myProject/dist/{index.html,js,css,favicon.ico,fonts,img} ./; Echo "Update successful" ls; Date echo "---------- End Script execution ----------"Copy the code
Setting a Scheduled Task
Students who use the pagoda panel can set directly in the panel. Those of you who use a terminal can keep going
#Switch to the spool directory where the scheduled task configuration file is stored
vi /var/spool/cron/root
Copy the code
#Add to this file
#This command is automatically executed every 5 minutes*/5 * * * * Script address. ShCopy the code
- The first oneIndicates every xx(1-59) minutes, used per minuteOr * / 1 said
- The second * represents every xx(0-23) hours
- The third * indicates dates, 1-31
- The fourth * is the month, 1-12
- The fifth * represents the week x(0-6, where 0 is Sunday)
Said in the back
After the setup is complete, you only need to push the local code to git repository, and the service will automatically pull the latest code and package, to achieve the effect of real-time code update.