J.Doe
J.Doe

Reputation: 319

flock fail in debian 7.11

I want my script run singleton,I refer to flock,the script runs well except debian 7.11.

When I runs in docker debian 7.11,it gives the following error: flock: ./single.sh Text file busy

I download the debian 9,it runs well,If this can not fixed,I have to try another way to make the script run singleton.

I wonder if there is a way to fix this.

#!/bin/bash
# singleton exec
[ "${EDR_FLOCKER}" != "$0" ] && exec env EDR_FLOCKER="$0" flock -eno "$0" "$0" "$@" || :

echo "Helloworld"
sleep 20

Upvotes: 1

Views: 95

Answers (2)

user3132194
user3132194

Reputation: 2567

To override this bug you could recall write permissions from your script chmod -w script.sh or make it immutable if it should be runned from root chattr +i script.sh.

Upvotes: 0

J.Doe
J.Doe

Reputation: 319

I found the reason why this fail,the argument of flock can not be the script self. Modify the script as below everything works fine.

#!/bin/bash
# singleton exec
[ "${EDR_FLOCKER}" != "$0" ] && exec env EDR_FLOCKER="$0" flock -eno "$0.lock" "$0" "$@" || :

echo "Helloworld"
sleep 20

Upvotes: 1

Related Questions