The target

Compile the code through Jenkins child node, deploy the compiled code to the specified directory, and automatically restart the Node process.

Jenkinsfile

pipeline {
  agent {
    label 'my-blog'	# Since my blog server already has the Node environment built, I will use it to build
  }
  stages {
    stage('build') {
      steps {
        sh './build.sh'
      }
    }

    stage('deploy') {
      steps {
        input message: 'Begin deployment? (Click "Proceed" to continue)'
        sh './restart.sh'}}}}Copy the code

build.sh

Mainly used to build environments

npm install
npm run build
Copy the code

restart.sh

It is used to release new versions

rsync -avzP --delete ./ /data/website/blog-page/
supervisorctl restart nuxt	My front-end service is mainly monitored by supervisor
Copy the code

The supervisor nuxt configuration

[program:nuxt]
command =npm run start
autostart=true; Startsecs =10 when it is launched in the container; If the process does not exit unexpectedly after 10 seconds, the process is started normally. The default value is 1 second autorestart=true; Unexpected, which means that the process is restarted after it is killed unexpectedly. The default value is 3. User =roki; The default user name is root directory=/data/website/blog-page priority=999. Redirect_stderr = Specifies the process start priority. The default value is 999true; Redirect stderr to stdout, defaultfalsestdout_logfile_maxbytes=200MB ; Stdout logfile size. Default value: 50MB stdout_logfile_backups = 20; Stdout Number of backup log files. The default value is 10. Stdout_logfile =/var/log/blog-nuxt.log
stderr_logfile=/var/log/blog-nuxt-err.log
stopasgroup=true; The default isfalse, whether to send the stop signal to the process group when the process is killed, including the subprocess killasGroup =true; The default isfalseTo the process groupkillSignals, including child processesCopy the code

The stopasGroup and killasGroup in the container container are designed to be true or it will not be able to restart the container through the container container because the node is monitoring the port in a small process when the container is running. Therefore, restarting the parent process after killing it will fail due to a port conflict.

The results of

To build such a long time every time is a real headache -_ – | |