Today, when deployed in Jenkins, because developers frequently submitted code, resulting in Jenkins shell script in that frequent deployment, in order to prevent such problems, a special search to prevent the recurrence of code. Here's a look at the code:
#!/bin/bash
Lock_name= "/tmp/my.lock"
if (Set-o noclobber echo "$$" > "$LOCK _name") 2>/dev/null;
Then
Trap ' rm-f ' $LOCK _name '; Exit $? ' INT TERM EXIT
### Start normal process
### Normal Process End
### removing lock
Rm-f $LOCK _name
Trap-int TERM EXIT
Else
echo "Failed to acquire Lockfile: $LOCK _name."
echo "Held by $ (cat $LOCK _name)"
Exit 1
Fi
echo "Done."
This ensures that My.lock can only be created by one process. Much more reliable than the touch.
A trap captures a variety of signals and then processes it:
INT is used to handle CTRL + C canceling script execution.
TERM is used to handle kill-term PID cases.
EXIT not clear
In addition, it is not valid for kill-9.