1halockrun(1)                       HA-Tools                       halockrun(1)
2
3
4

NAME

6       halockrun - Run command while hold exclusive lock on file.
7

SYNOPSIS

9       halockrun  [-ancf] [-e exitcode] [-E nexitcode] lockfile command [args]
10       halockrun -t [-c] [-e exitcode] [-E nexitcode] lockfile
11

DESCRIPTION

13       Executes the given command with the given args while holding an  exclu‐
14       sive  lock  on the file lockfile halockrun will wait until the lock was
15       released and execute the command afterwards.
16
17       This is useful to serialize command execution from a shell script.
18
19       halockrun is implemented using locks from the  operating  system  which
20       makes it very reliable and not vulnerable to dead locks.
21
22       halockrun  can  also  be  used to implement start/stop script's without
23       having pid-files.
24
25
26       -a     Async mode. Starts the command in the background. The  hatimerun
27              program  exits  immediately. The returncode of the executed com‐
28              mand is lost.
29
30       -c     Create mode. Creates the  lockfile  if  it  doesn't  exist.  The
31              default behavior is to exit with exitcode if the specified lock‐
32              file doesn't exist.
33
34       -e exitcode
35              Changes the exitcode returned by halockrun on fail to exitcode
36
37              The default value for this option is 99
38
39
40       -E nexitcode
41              Changes the exitcode returned by  halockrun  in  nonblocking  or
42              testing mode if the lock can't be obtained to nexitcode
43
44              The  default  value  for  this option is exitcode in nonblocking
45              mode and 1 in testing mode.
46
47
48       -n     Nonblocking mode. Exits with nexitcode if the lockfile is locked
49              by another Process.
50
51       -f     Fork  mode.  The normal behavior of halockrun is to get the lock
52              and call execvp(2) to execute the  command  specified.  If  this
53              option  is  specified,  halockrun  will do a fork(2) and run the
54              command in its own process. In this case the parent (  halockrun
55              )  itself  holds  the lock on the lockfile.  This may cause some
56              troubles if the halockrun process dies and the child is not fin‐
57              ished  yet,  in  that  case the child would not be protected. To
58              minimize this  risk  the  halockrun  process  holding  the  lock
59              ignores  the following signals: TERM, HUP, INT, PIPE, QUIT, USR1
60              and USR2.
61
62              This option is only useful to make sure that  the  command  does
63              not  see any difference when running under protection of halock‐
64              run.  The only thing which is  different  (currently)  when  not
65              running  with  the -f option is that there is another open file‐
66              handle which is connected to the lockfile and holds the lock.
67
68              This option is new to  version  V0.99.08,  before  this  version
69              halockrun  has  always  made  a  fork.  The  default has changed
70              because it is much more important to make sure to not  lose  the
71              lock by accident then to make halockrun 100% transparent.
72
73              If you are in doubt about this option: don't use it.
74
75       -t     Test  mode.   Can  be used to check if the lockfile is currently
76              locked. If you specify this option halockrun will check  if  the
77              file  is locked and return 0 if it is not locked or nexitcode if
78              it is locked and will print the pid of the process  which  holds
79              the  lock  to  stdout.   Regardless of the lockstatus, halockrun
80              will not run any command.
81
82              If an error occurs (e.g. because the  lockfile  doesn't  exists)
83              exitcode will be returned.
84
85              Please  note  that  if another halockrun is currently holing the
86              lock, you will receive the pid of the  halockrun  process  which
87              holds  the lock. This is usually the program which you run under
88              protection of halockrun  but  might  be  the  halockrun  process
89              itself if you have specified the -f flag.
90
91              When the -t flags is specified the flags -a, -n and -f are mean‐
92              ingless and will be ignored if the are specified.
93
94

RETURN VALUE

96       On success (if the command was executed) halockrun returns the  return‐
97       value of the given command
98
99       On  fail  (e.g.  if  the lockfile doesn't exist or the command can't be
100       executed) halockrun returns the value specified by the -e option.
101
102       On failure to obtain the lock in testing mode or  in  nonblocking  mode
103       halockrun returns the values specified by the -E option.
104
105

AUTHOR

107       Copyright (c) 2001,2003,2005-2007 by Markus Winand <mws@fatalmind.com>
108

SEE ALSO

110       hatimerun(1)
111
112
113
114V2.00                    $Date: 2007/08/18 15:38:13 $             halockrun(1)
Impressum