Calling shell Jenkins does not automatically end the workaround

Note: Jenkins started the JAR file when executing the shell script, which directly caused the build to not end automatically, can use the nohup command to solve the problem

The solution is to use nohup to call the start JAR command and add & to the end of the command, so that the command is executed in the background.

Nohup Java jar/root /. Jenkins/jobs/maventest/workspace/executor/target/executor - 0.0.1 - the SNAPSHOT. Jar &Copy the code

Reference: blog.csdn.net/chao_1990/a…

Description of the nohup command

nohup command args
Copy the code
  1. Commands run with nohup and ignore any SIGHUP signals. Run the program in the background using the nohup command after logout. You need to run the nohup command in the background and add “&” (the symbol for “and”) to the end of the command.
  2. Nohup is a contraction of “no hang up”, which means not to hang up.
  3. If you are running a process that will not end when the account exits, use the nohup command. This command will continue running the process after you exit the account or close the terminal.

case

  1. Command a
nohup command > myout.file 2>&1 & 
Copy the code

In the above example, 0 — stdin (standard input), 1 — stdout (standard output), 2 — stderr (standard error); 2>&1 redirects standard error (2) to standard output (&1), which is then redirected to the myout.file file. 2. The second command

0 22 * * * /usr/bin/python /home/pu/download_pdf/download_dfcf_pdf_to_oss.py > /home/pu/download_pdf/download_dfcf_pdf_to_oss.log 2>&1
Copy the code

This is a scheduled task placed in crontab. At 22pm to avoid this task, start the Python script and write the log to the download_dfcf_PDF_to_oss.log file

Nohup and &

The difference between a

& : indicates running in the background. Nohup: indicates running without hanging up. The command can be executed permanently with nohup, which has nothing to do with the user terminal. For example, if we disconnect the SSH connection, it will not affect the operation of nohup. & is the background run

The difference between the two

The & is used to run in the background, but when the user exits (suspends), the command automatically exits

nohup COMMAND &

This allows commands to be executed permanently in the background. For example:

sh test.sh &

Sh task in the background, even if xshell is closed, the current session will continue to run, but the standard output and standard error messages will be lost (the output of missing logs). Sh task in the background, close Xshell, the corresponding task will also stop.

nohup sh test.sh

The sh test.sh task is put in the background, the standard input is closed, the terminal can no longer receive any input (standard input), the standard output and standard error are redirected to the nohip. out file in the current directory, and the current session continues to run even after xshell is closed and the current session exits.

nohup sh test.sh &

The sh test.sh task is put in the background, but standard input can still be used. The terminal can accept any input, redirect standard output and standard error to the nohip. out file in the current directory, and continue running even if xshell is closed and the current session exits.