Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-02-14 Thread Radosław Korzeniewski
Hello,

śr., 6 lut 2019 o 23:58 Dimitri Maziuk via Bacula-users <
bacula-users@lists.sourceforge.net> napisał(a):

> On 2/6/19 4:14 PM, David Brodbeck wrote:
>
> I would look at using pmset to disable sleep in Before and re-enable in
> AfterJob -- though it's probably a PITA if you have custom power
> settings and want to restore them after.
>

There is a patch which disable sleep mode on macOS during backup/restore
job. The patch will be available on next major Bacula release or when Kern
will accept it in the current 9.4.x.

best regards
-- 
Radosław Korzeniewski
rados...@korzeniewski.net
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-02-06 Thread David Brodbeck
Thanks, pmset was the missing piece. I put together a pair of shell
one-liners that saves the current setting in Before, and restores it in
After. The real test will be when it runs overnight, but so far it looks
promising.

On Wed, Feb 6, 2019 at 2:57 PM Dimitri Maziuk via Bacula-users <
bacula-users@lists.sourceforge.net> wrote:

> On 2/6/19 4:14 PM, David Brodbeck wrote:
>
> > I think I'm barking up the wrong tree and the ClientBeforeJob
> functionality
> > just isn't meant for this sort of thing. I gather from earlier
> conversation
> > that it was only working for me in 7.4.x because of a bug.
>
> From a brief look at google it seems you're barking up the wrong tree in
> that it is caffeinate that won't detach from the terminal because it
> must catch its Ctrl+C to decaf.
>
> I would look at using pmset to disable sleep in Before and re-enable in
> AfterJob -- though it's probably a PITA if you have custom power
> settings and want to restore them after.
>
> --
> Dimitri Maziuk
> Programmer/sysadmin
> BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu
>
> ___
> Bacula-users mailing list
> Bacula-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bacula-users
>


-- 
David Brodbeck
System Administrator, Department of Mathematics
University of California, Santa Barbara
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-02-06 Thread Dimitri Maziuk via Bacula-users
On 2/6/19 4:14 PM, David Brodbeck wrote:

> I think I'm barking up the wrong tree and the ClientBeforeJob functionality
> just isn't meant for this sort of thing. I gather from earlier conversation
> that it was only working for me in 7.4.x because of a bug.

From a brief look at google it seems you're barking up the wrong tree in
that it is caffeinate that won't detach from the terminal because it
must catch its Ctrl+C to decaf.

I would look at using pmset to disable sleep in Before and re-enable in
AfterJob -- though it's probably a PITA if you have custom power
settings and want to restore them after.

-- 
Dimitri Maziuk
Programmer/sysadmin
BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu



signature.asc
Description: OpenPGP digital signature
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-02-06 Thread David Brodbeck
I used "at" on High Sierra, but on Mojave it no longer works.
Disappointing, but not terribly surprising since it's been deprecated for
years. It might be possible to make it work on Mojave if I disabled system
protection, but I'm trying to avoid that if at all possible.

Your disown suggestion was a good one, but it doesn't work either. I tried
with:

#!/bin/bash

PATH=/bin:/usr/bin:/usr/local/bin
caffeinate -s bacula-idle-watch.sh >/dev/null 2>&1  wrote:

>
> On 1/31/2019 9:37 PM, David Brodbeck wrote:
>
> Belatedly, I should note that the 'screen' solution doesn't work either.
> It works if you launched bacula from a terminal, but if the launchdaemon
> has launched it screen will abort because of not having a tty.
>
> I keep having a nagging feeling that this can't possibly be this
> difficult, that I must be being stupid and overlooking something simple. I
> just can't figure out how to get bacula-fd to let a ClientBeforeJob script
> go into the background instead of waiting for it to exit. It worked in
> bacula-fd 7.x, but in 9.x it appears to be impossible to detach the process
> thoroughly enough for bacula to continue. Maybe the only solution is to
> downgrade my clients?
>
>
> Well, at would be my preference, since it would allow the RunBefore script
> to exit likely even before at started the background script, but since at
> is for some reason disallowed, try the bash built-in 'disown'.
>
> #!/bin/bash
> # ~/background-test.sh
> sleep 120 &
> disown
> exit 0
>
> $ ~/background-test.sh
> $ jobs
> $ ps xa | grep sleep
> 28562 pts/1S  0:00 sleep 120
> 28565 pts/1S+ 0:00 grep --color=auto sleep
> $
>
>
>
>
> On Tue, Jan 15, 2019 at 12:41 PM David Brodbeck 
> wrote:
>
>> New solution: Instead of abusing at, abuse screen.
>>
>> screen -d -m caffeinate -s bacula-idle-watch.sh
>>
>>
>> On Tue, Jan 15, 2019 at 11:51 AM David Brodbeck 
>> wrote:
>>
>>> Hmm. Unfortunately the solution below does not work on Mojave. Scripts
>>> no longer have permission to run 'at' because they can't create
>>> /usr/lib/cron/jobs/.lockfile.
>>>
>>> Adding bacula-fd to the list of apps with full disk access doesn't do
>>> anything, unfortunately, I guess because it's not a full-fledged app?
>>> Running 'at' manually from the command line works, but only if Terminal is
>>> added to the list, so it seems you need an "official" app somewhere in the
>>> process tree. (This is also a problem for backing up certain files in user
>>> home directories, but that's another issue.)
>>>
>>>
>>> On Mon, Jan 7, 2019 at 11:53 AM David Brodbeck 
>>> wrote:
>>>
 Forgot to CC this to the list, but it's the best solution I've gotten
 so far. It works, but on macOS you have to turn the 'at' service on
 first. I ended up with this:

 #!/bin/bash

 PATH=/bin:/usr/bin:/usr/local/bin

 # Script to prevent system sleep while bacula is working.
 # see bacula-idle-watch.sh for details.

 # We need to launch with 'at' to avoid bacula-fd hanging waiting for
 script
 # completion. First we make sure atrun is enabled.
 launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist

 echo '/usr/bin/caffeinate -s /usr/local/bin/bacula-idle-watch.sh' | at
 now

 ---

 Note that by nature 'at' is not immediate. It may take a minute or so
 for the script to launch, so plan accordingly.

 On Sat, Jan 5, 2019 at 8:18 AM Josh Fisher  wrote:

> In the ClinetBeforeJob script, use the at command to schedule the
> launch of the caffeinate job with a runtime of 'now'. For example,
>
> at -f caffeinate-script.sh now
>
>
> On 1/4/2019 2:36 PM, David Brodbeck wrote:
>
> This is driving me nuts because I feel like it should be
> straightforward and I must be missing something basic.
>
> I want to launch the caffeinate command on OS X before starting a job.
> Caffeinate takes a command as an argument, then goes into the background
> and keeps the machine awake until the command exits. I use this after
> waking machines up using a WOL script.
>
> When tested from the command line, caffeinate immediately backgrounds
> itself. However, when I try to run it as a Bacula ClientBeforeJob script,
> bacula-fd waits around forever for caffeiniate to exit.
>
> Here's what I've tried so far:
> - Having bacula run a script that then runs caffeinate.
> - Having bacula run a script that then runs caffeinate using nohup.
> - Having the script redirect stdin, stdout, and stderr of caffeinate
> to /dev/null
> - Adding an ampersand after the script in the bacula ClientBeforeJob
> specification.
>
> What invariably happens is the bash process created by bacula becomes
> a zombie and waits for caffeinate to exit. Inspecting the caffeinate
> process with lsof shows all of the file handles are redirected to 
> /dev/null
> as expected, so I 

Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-02-01 Thread Josh Fisher


On 1/31/2019 9:37 PM, David Brodbeck wrote:
Belatedly, I should note that the 'screen' solution doesn't work 
either. It works if you launched bacula from a terminal, but if the 
launchdaemon has launched it screen will abort because of not having a 
tty.


I keep having a nagging feeling that this can't possibly be this 
difficult, that I must be being stupid and overlooking something 
simple. I just can't figure out how to get bacula-fd to let a 
ClientBeforeJob script go into the background instead of waiting for 
it to exit. It worked in bacula-fd 7.x, but in 9.x it appears to be 
impossible to detach the process thoroughly enough for bacula to 
continue. Maybe the only solution is to downgrade my clients?



Well, at would be my preference, since it would allow the RunBefore 
script to exit likely even before at started the background script, but 
since at is for some reason disallowed, try the bash built-in 'disown'.


#!/bin/bash
# ~/background-test.sh
sleep 120 &
disown
exit 0

$ ~/background-test.sh
$ jobs
$ ps xa | grep sleep
28562 pts/1    S  0:00 sleep 120
28565 pts/1    S+ 0:00 grep --color=auto sleep
$





On Tue, Jan 15, 2019 at 12:41 PM David Brodbeck 
mailto:brodb...@math.ucsb.edu>> wrote:


New solution: Instead of abusing at, abuse screen.

screen -d -m caffeinate -s bacula-idle-watch.sh


On Tue, Jan 15, 2019 at 11:51 AM David Brodbeck
mailto:brodb...@math.ucsb.edu>> wrote:

Hmm. Unfortunately the solution below does not work on Mojave.
Scripts no longer have permission to run 'at' because they
can't create /usr/lib/cron/jobs/.lockfile.

Adding bacula-fd to the list of apps with full disk access
doesn't do anything, unfortunately, I guess because it's not a
full-fledged app? Running 'at' manually from the command line
works, but only if Terminal is added to the list, so it seems
you need an "official" app somewhere in the process tree.
(This is also a problem for backing up certain files in user
home directories, but that's another issue.)


On Mon, Jan 7, 2019 at 11:53 AM David Brodbeck
mailto:brodb...@math.ucsb.edu>> wrote:

Forgot to CC this to the list, but it's the best solution
I've gotten so far. It works, but on macOS you have to
turn the 'at' service on first. I ended up with this:

#!/bin/bash

PATH=/bin:/usr/bin:/usr/local/bin

# Script to prevent system sleep while bacula is working.
# see bacula-idle-watch.sh for details.

# We need to launch with 'at' to avoid bacula-fd hanging
waiting for script
# completion. First we make sure atrun is enabled.
launchctl load -w
/System/Library/LaunchDaemons/com.apple.atrun.plist

echo '/usr/bin/caffeinate -s
/usr/local/bin/bacula-idle-watch.sh' | at now

---

Note that by nature 'at' is not immediate. It may take a
minute or so for the script to launch, so plan accordingly.

On Sat, Jan 5, 2019 at 8:18 AM Josh Fisher
mailto:jfis...@pvct.com>> wrote:

In the ClinetBeforeJob script, use the at command to
schedule the launch of the caffeinate job with a
runtime of 'now'. For example,

at -f caffeinate-script.sh now


On 1/4/2019 2:36 PM, David Brodbeck wrote:

This is driving me nuts because I feel like it should
be straightforward and I must be missing something
basic.

I want to launch the caffeinate command on OS X
before starting a job. Caffeinate takes a command as
an argument, then goes into the background and keeps
the machine awake until the command exits. I use this
after waking machines up using a WOL script.

When tested from the command line, caffeinate
immediately backgrounds itself. However, when I try
to run it as a Bacula ClientBeforeJob script,
bacula-fd waits around forever for caffeiniate to exit.

Here's what I've tried so far:
- Having bacula run a script that then runs caffeinate.
- Having bacula run a script that then runs
caffeinate using nohup.
- Having the script redirect stdin, stdout, and
stderr of caffeinate to /dev/null
- Adding an ampersand after the script in the bacula
ClientBeforeJob specification.

What invariably happens is the bash process created
by bacula becomes a zombie and waits for caffeinate
to exit. Inspecting the caffeinate process with lsof
shows all of the file handles are redirected to
  

Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-31 Thread David Brodbeck
Belatedly, I should note that the 'screen' solution doesn't work either. It
works if you launched bacula from a terminal, but if the launchdaemon has
launched it screen will abort because of not having a tty.

I keep having a nagging feeling that this can't possibly be this difficult,
that I must be being stupid and overlooking something simple. I just can't
figure out how to get bacula-fd to let a ClientBeforeJob script go into the
background instead of waiting for it to exit. It worked in bacula-fd 7.x,
but in 9.x it appears to be impossible to detach the process thoroughly
enough for bacula to continue. Maybe the only solution is to downgrade my
clients?


On Tue, Jan 15, 2019 at 12:41 PM David Brodbeck 
wrote:

> New solution: Instead of abusing at, abuse screen.
>
> screen -d -m caffeinate -s bacula-idle-watch.sh
>
>
> On Tue, Jan 15, 2019 at 11:51 AM David Brodbeck 
> wrote:
>
>> Hmm. Unfortunately the solution below does not work on Mojave. Scripts no
>> longer have permission to run 'at' because they can't create
>> /usr/lib/cron/jobs/.lockfile.
>>
>> Adding bacula-fd to the list of apps with full disk access doesn't do
>> anything, unfortunately, I guess because it's not a full-fledged app?
>> Running 'at' manually from the command line works, but only if Terminal is
>> added to the list, so it seems you need an "official" app somewhere in the
>> process tree. (This is also a problem for backing up certain files in user
>> home directories, but that's another issue.)
>>
>>
>> On Mon, Jan 7, 2019 at 11:53 AM David Brodbeck 
>> wrote:
>>
>>> Forgot to CC this to the list, but it's the best solution I've gotten so
>>> far. It works, but on macOS you have to turn the 'at' service on first.
>>> I ended up with this:
>>>
>>> #!/bin/bash
>>>
>>> PATH=/bin:/usr/bin:/usr/local/bin
>>>
>>> # Script to prevent system sleep while bacula is working.
>>> # see bacula-idle-watch.sh for details.
>>>
>>> # We need to launch with 'at' to avoid bacula-fd hanging waiting for
>>> script
>>> # completion. First we make sure atrun is enabled.
>>> launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
>>>
>>> echo '/usr/bin/caffeinate -s /usr/local/bin/bacula-idle-watch.sh' | at
>>> now
>>>
>>> ---
>>>
>>> Note that by nature 'at' is not immediate. It may take a minute or so
>>> for the script to launch, so plan accordingly.
>>>
>>> On Sat, Jan 5, 2019 at 8:18 AM Josh Fisher  wrote:
>>>
 In the ClinetBeforeJob script, use the at command to schedule the
 launch of the caffeinate job with a runtime of 'now'. For example,

 at -f caffeinate-script.sh now


 On 1/4/2019 2:36 PM, David Brodbeck wrote:

 This is driving me nuts because I feel like it should be
 straightforward and I must be missing something basic.

 I want to launch the caffeinate command on OS X before starting a job.
 Caffeinate takes a command as an argument, then goes into the background
 and keeps the machine awake until the command exits. I use this after
 waking machines up using a WOL script.

 When tested from the command line, caffeinate immediately backgrounds
 itself. However, when I try to run it as a Bacula ClientBeforeJob script,
 bacula-fd waits around forever for caffeiniate to exit.

 Here's what I've tried so far:
 - Having bacula run a script that then runs caffeinate.
 - Having bacula run a script that then runs caffeinate using nohup.
 - Having the script redirect stdin, stdout, and stderr of caffeinate to
 /dev/null
 - Adding an ampersand after the script in the bacula ClientBeforeJob
 specification.

 What invariably happens is the bash process created by bacula becomes a
 zombie and waits for caffeinate to exit. Inspecting the caffeinate process
 with lsof shows all of the file handles are redirected to /dev/null as
 expected, so I don't think this is a case of stdin or stdout causing
 problems. In all cases the only way to get bacula to finish the backup is
 to kill the script that caffeinate is running.

 I can't figure out why I can't get bacula-fd to move on after the
 script goes into the background. When I run the script manually from the
 command line it backgrounds immediately.

 The oddest thing is this worked fine on clients using bacula-fd version
 7.4.x, but fails on a client using 9.2.0.

 Here's the script bacula-fd runs, as it currently stands:

 --
 #!/bin/bash

 PATH=/bin:/usr/bin:/usr/local/bin

 # Script to prevent system sleep while bacula is working.
 # see bacula-idle-watch.sh for details.

 nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null >>> --

 Here's the contents of bacula-idle-watch.sh; it just waits to exit
 until there's no bacula network connection anymore. caffeinate will
 terminate once the script exits.

 --
 #!/bin/sh

 # This script 

Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-15 Thread David Brodbeck
New solution: Instead of abusing at, abuse screen.

screen -d -m caffeinate -s bacula-idle-watch.sh


On Tue, Jan 15, 2019 at 11:51 AM David Brodbeck 
wrote:

> Hmm. Unfortunately the solution below does not work on Mojave. Scripts no
> longer have permission to run 'at' because they can't create
> /usr/lib/cron/jobs/.lockfile.
>
> Adding bacula-fd to the list of apps with full disk access doesn't do
> anything, unfortunately, I guess because it's not a full-fledged app?
> Running 'at' manually from the command line works, but only if Terminal is
> added to the list, so it seems you need an "official" app somewhere in the
> process tree. (This is also a problem for backing up certain files in user
> home directories, but that's another issue.)
>
>
> On Mon, Jan 7, 2019 at 11:53 AM David Brodbeck 
> wrote:
>
>> Forgot to CC this to the list, but it's the best solution I've gotten so
>> far. It works, but on macOS you have to turn the 'at' service on first.
>> I ended up with this:
>>
>> #!/bin/bash
>>
>> PATH=/bin:/usr/bin:/usr/local/bin
>>
>> # Script to prevent system sleep while bacula is working.
>> # see bacula-idle-watch.sh for details.
>>
>> # We need to launch with 'at' to avoid bacula-fd hanging waiting for
>> script
>> # completion. First we make sure atrun is enabled.
>> launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
>>
>> echo '/usr/bin/caffeinate -s /usr/local/bin/bacula-idle-watch.sh' | at now
>>
>> ---
>>
>> Note that by nature 'at' is not immediate. It may take a minute or so for
>> the script to launch, so plan accordingly.
>>
>> On Sat, Jan 5, 2019 at 8:18 AM Josh Fisher  wrote:
>>
>>> In the ClinetBeforeJob script, use the at command to schedule the launch
>>> of the caffeinate job with a runtime of 'now'. For example,
>>>
>>> at -f caffeinate-script.sh now
>>>
>>>
>>> On 1/4/2019 2:36 PM, David Brodbeck wrote:
>>>
>>> This is driving me nuts because I feel like it should be straightforward
>>> and I must be missing something basic.
>>>
>>> I want to launch the caffeinate command on OS X before starting a job.
>>> Caffeinate takes a command as an argument, then goes into the background
>>> and keeps the machine awake until the command exits. I use this after
>>> waking machines up using a WOL script.
>>>
>>> When tested from the command line, caffeinate immediately backgrounds
>>> itself. However, when I try to run it as a Bacula ClientBeforeJob script,
>>> bacula-fd waits around forever for caffeiniate to exit.
>>>
>>> Here's what I've tried so far:
>>> - Having bacula run a script that then runs caffeinate.
>>> - Having bacula run a script that then runs caffeinate using nohup.
>>> - Having the script redirect stdin, stdout, and stderr of caffeinate to
>>> /dev/null
>>> - Adding an ampersand after the script in the bacula ClientBeforeJob
>>> specification.
>>>
>>> What invariably happens is the bash process created by bacula becomes a
>>> zombie and waits for caffeinate to exit. Inspecting the caffeinate process
>>> with lsof shows all of the file handles are redirected to /dev/null as
>>> expected, so I don't think this is a case of stdin or stdout causing
>>> problems. In all cases the only way to get bacula to finish the backup is
>>> to kill the script that caffeinate is running.
>>>
>>> I can't figure out why I can't get bacula-fd to move on after the script
>>> goes into the background. When I run the script manually from the command
>>> line it backgrounds immediately.
>>>
>>> The oddest thing is this worked fine on clients using bacula-fd version
>>> 7.4.x, but fails on a client using 9.2.0.
>>>
>>> Here's the script bacula-fd runs, as it currently stands:
>>>
>>> --
>>> #!/bin/bash
>>>
>>> PATH=/bin:/usr/bin:/usr/local/bin
>>>
>>> # Script to prevent system sleep while bacula is working.
>>> # see bacula-idle-watch.sh for details.
>>>
>>> nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null >> --
>>>
>>> Here's the contents of bacula-idle-watch.sh; it just waits to exit until
>>> there's no bacula network connection anymore. caffeinate will terminate
>>> once the script exits.
>>>
>>> --
>>> #!/bin/sh
>>>
>>> # This script delays a few minutes, then loops, checking for bacula-fd
>>> # connections. When there are none, it exits.
>>> # This is meant to be run with caffeinate in a bacula before-job script,
>>> # e.g. "caffeinate -s bacula-idle-watch.sh"
>>> # This will prevent the machine from idle-sleeping until bacula finishes.
>>>
>>> PATH=/bin:/usr/bin:/usr/sbin
>>>
>>> # We put a long delay here in case it takes bacula a while to get going.
>>> sleep 300
>>>
>>> # Now loop while looking at the network connection.
>>> # We limit checks to once every five minutes because worst-case the
>>> machine
>>> # just waits an extra five minutes to sleep.
>>> while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
>>> sleep 300
>>> done
>>>
>>> # Once the script exits, the wake-lock is released.
>>> exit 0
>>> --
>>>
>>>
>>> --
>>> David 

Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-15 Thread David Brodbeck
Hmm. Unfortunately the solution below does not work on Mojave. Scripts no
longer have permission to run 'at' because they can't create
/usr/lib/cron/jobs/.lockfile.

Adding bacula-fd to the list of apps with full disk access doesn't do
anything, unfortunately, I guess because it's not a full-fledged app?
Running 'at' manually from the command line works, but only if Terminal is
added to the list, so it seems you need an "official" app somewhere in the
process tree. (This is also a problem for backing up certain files in user
home directories, but that's another issue.)


On Mon, Jan 7, 2019 at 11:53 AM David Brodbeck 
wrote:

> Forgot to CC this to the list, but it's the best solution I've gotten so
> far. It works, but on macOS you have to turn the 'at' service on first. I
> ended up with this:
>
> #!/bin/bash
>
> PATH=/bin:/usr/bin:/usr/local/bin
>
> # Script to prevent system sleep while bacula is working.
> # see bacula-idle-watch.sh for details.
>
> # We need to launch with 'at' to avoid bacula-fd hanging waiting for script
> # completion. First we make sure atrun is enabled.
> launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
>
> echo '/usr/bin/caffeinate -s /usr/local/bin/bacula-idle-watch.sh' | at now
>
> ---
>
> Note that by nature 'at' is not immediate. It may take a minute or so for
> the script to launch, so plan accordingly.
>
> On Sat, Jan 5, 2019 at 8:18 AM Josh Fisher  wrote:
>
>> In the ClinetBeforeJob script, use the at command to schedule the launch
>> of the caffeinate job with a runtime of 'now'. For example,
>>
>> at -f caffeinate-script.sh now
>>
>>
>> On 1/4/2019 2:36 PM, David Brodbeck wrote:
>>
>> This is driving me nuts because I feel like it should be straightforward
>> and I must be missing something basic.
>>
>> I want to launch the caffeinate command on OS X before starting a job.
>> Caffeinate takes a command as an argument, then goes into the background
>> and keeps the machine awake until the command exits. I use this after
>> waking machines up using a WOL script.
>>
>> When tested from the command line, caffeinate immediately backgrounds
>> itself. However, when I try to run it as a Bacula ClientBeforeJob script,
>> bacula-fd waits around forever for caffeiniate to exit.
>>
>> Here's what I've tried so far:
>> - Having bacula run a script that then runs caffeinate.
>> - Having bacula run a script that then runs caffeinate using nohup.
>> - Having the script redirect stdin, stdout, and stderr of caffeinate to
>> /dev/null
>> - Adding an ampersand after the script in the bacula ClientBeforeJob
>> specification.
>>
>> What invariably happens is the bash process created by bacula becomes a
>> zombie and waits for caffeinate to exit. Inspecting the caffeinate process
>> with lsof shows all of the file handles are redirected to /dev/null as
>> expected, so I don't think this is a case of stdin or stdout causing
>> problems. In all cases the only way to get bacula to finish the backup is
>> to kill the script that caffeinate is running.
>>
>> I can't figure out why I can't get bacula-fd to move on after the script
>> goes into the background. When I run the script manually from the command
>> line it backgrounds immediately.
>>
>> The oddest thing is this worked fine on clients using bacula-fd version
>> 7.4.x, but fails on a client using 9.2.0.
>>
>> Here's the script bacula-fd runs, as it currently stands:
>>
>> --
>> #!/bin/bash
>>
>> PATH=/bin:/usr/bin:/usr/local/bin
>>
>> # Script to prevent system sleep while bacula is working.
>> # see bacula-idle-watch.sh for details.
>>
>> nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null > --
>>
>> Here's the contents of bacula-idle-watch.sh; it just waits to exit until
>> there's no bacula network connection anymore. caffeinate will terminate
>> once the script exits.
>>
>> --
>> #!/bin/sh
>>
>> # This script delays a few minutes, then loops, checking for bacula-fd
>> # connections. When there are none, it exits.
>> # This is meant to be run with caffeinate in a bacula before-job script,
>> # e.g. "caffeinate -s bacula-idle-watch.sh"
>> # This will prevent the machine from idle-sleeping until bacula finishes.
>>
>> PATH=/bin:/usr/bin:/usr/sbin
>>
>> # We put a long delay here in case it takes bacula a while to get going.
>> sleep 300
>>
>> # Now loop while looking at the network connection.
>> # We limit checks to once every five minutes because worst-case the
>> machine
>> # just waits an extra five minutes to sleep.
>> while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
>> sleep 300
>> done
>>
>> # Once the script exits, the wake-lock is released.
>> exit 0
>> --
>>
>>
>> --
>> David Brodbeck
>> System Administrator, Department of Mathematics
>> University of California, Santa Barbara
>>
>>
>>
>> ___
>> Bacula-users mailing 
>> listBacula-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/bacula-users
>>
>>
>
> --
> David 

Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-08 Thread Martin Simmons
I don't think you can tell bacula-fd to not wait.

If you are interested in debugging it, you could use lsof to see what
bacula-fd has open while it is waiting and then see which other processes are
connected to it (probably via pipes, where lsof prints some hex number
identifying the pipe).  Adding sleep after running caffeinate in
bacula-caffeinate.sh would allow you to check what is open before it becomes a
zombie.

__Martin


> On Mon, 7 Jan 2019 10:32:04 -0800, David Brodbeck said:
> 
> Hmm, good catch on the redirect, but it still doesn't work. Neither does
> adding the exec line.
> 
> Running lsof on the caffeinate process shows stdin, stdout, and stderr are
> properly connected to /dev/null; same with bacula-idle-watch.sh. I can't
> determine what the bacula-caffeinate.sh script's file handles are because
> by the time I get a chance to run lsof, it's already exited and become a
> zombie. bacula-fd continues to wait for it none the less.
> 
> Is there any way to tell bacula-fd to not wait for script output, as in the
> 7.4.x behavior? I realize I'm not really using this functionality for the
> intended purpose, but I can't be the only one with this sort of use case.
> 
> On Mon, Jan 7, 2019 at 6:26 AM Martin Simmons  wrote:
> 
> > Your script redirects stderr to the original stdout of the script.  To
> > redirect both to /dev/null, the 2>&1 must follow the >/dev/null like this:
> >
> > nohup caffeinate -s bacula-idle-watch.sh >/dev/null 2>&1  >
> > Bacula 9.2.0 collects the stderr from ClientBeforeJob commands, but Bacula
> > clients running 7.4.x would have worked because they discard it.
> >
> > If that doesn't fix it, then try redirecting the shell's stdio as well:
> >
> > exec >/dev/null 2>&1  > nohup caffeinate -s bacula-idle-watch.sh &
> >
> > __Martin
> >
> >
> > > On Fri, 4 Jan 2019 11:36:06 -0800, David Brodbeck said:
> > >
> > > This is driving me nuts because I feel like it should be straightforward
> > > and I must be missing something basic.
> > >
> > > I want to launch the caffeinate command on OS X before starting a job.
> > > Caffeinate takes a command as an argument, then goes into the background
> > > and keeps the machine awake until the command exits. I use this after
> > > waking machines up using a WOL script.
> > >
> > > When tested from the command line, caffeinate immediately backgrounds
> > > itself. However, when I try to run it as a Bacula ClientBeforeJob script,
> > > bacula-fd waits around forever for caffeiniate to exit.
> > >
> > > Here's what I've tried so far:
> > > - Having bacula run a script that then runs caffeinate.
> > > - Having bacula run a script that then runs caffeinate using nohup.
> > > - Having the script redirect stdin, stdout, and stderr of caffeinate to
> > > /dev/null
> > > - Adding an ampersand after the script in the bacula ClientBeforeJob
> > > specification.
> > >
> > > What invariably happens is the bash process created by bacula becomes a
> > > zombie and waits for caffeinate to exit. Inspecting the caffeinate
> > process
> > > with lsof shows all of the file handles are redirected to /dev/null as
> > > expected, so I don't think this is a case of stdin or stdout causing
> > > problems. In all cases the only way to get bacula to finish the backup is
> > > to kill the script that caffeinate is running.
> > >
> > > I can't figure out why I can't get bacula-fd to move on after the script
> > > goes into the background. When I run the script manually from the command
> > > line it backgrounds immediately.
> > >
> > > The oddest thing is this worked fine on clients using bacula-fd version
> > > 7.4.x, but fails on a client using 9.2.0.
> > >
> > > Here's the script bacula-fd runs, as it currently stands:
> > >
> > > --
> > > #!/bin/bash
> > >
> > > PATH=/bin:/usr/bin:/usr/local/bin
> > >
> > > # Script to prevent system sleep while bacula is working.
> > > # see bacula-idle-watch.sh for details.
> > >
> > > nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null  > > --
> > >
> > > Here's the contents of bacula-idle-watch.sh; it just waits to exit until
> > > there's no bacula network connection anymore. caffeinate will terminate
> > > once the script exits.
> > >
> > > --
> > > #!/bin/sh
> > >
> > > # This script delays a few minutes, then loops, checking for bacula-fd
> > > # connections. When there are none, it exits.
> > > # This is meant to be run with caffeinate in a bacula before-job script,
> > > # e.g. "caffeinate -s bacula-idle-watch.sh"
> > > # This will prevent the machine from idle-sleeping until bacula finishes.
> > >
> > > PATH=/bin:/usr/bin:/usr/sbin
> > >
> > > # We put a long delay here in case it takes bacula a while to get going.
> > > sleep 300
> > >
> > > # Now loop while looking at the network connection.
> > > # We limit checks to once every five minutes because worst-case the
> > machine
> > > # just waits an extra five minutes to sleep.
> > > while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
> 

Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-07 Thread Dimitri Maziuk via Bacula-users
On 1/7/19 12:32 PM, David Brodbeck wrote:
> Hmm, good catch on the redirect, but it still doesn't work. Neither does
> adding the exec line.

nohup just does what is says: no HUP. You may want to try `CMD & ;
disown` if your shell has disown, or `setsid CMD`. You'd still ned the
redirects.

Or rewrite your script in something that lets you do a proper double-fork.
-- 
Dimitri Maziuk
Programmer/sysadmin
BioMagResBank, UW-Madison -- http://www.bmrb.wisc.edu



signature.asc
Description: OpenPGP digital signature
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-07 Thread David Brodbeck
Forgot to CC this to the list, but it's the best solution I've gotten so
far. It works, but on macOS you have to turn the 'at' service on first. I
ended up with this:

#!/bin/bash

PATH=/bin:/usr/bin:/usr/local/bin

# Script to prevent system sleep while bacula is working.
# see bacula-idle-watch.sh for details.

# We need to launch with 'at' to avoid bacula-fd hanging waiting for script
# completion. First we make sure atrun is enabled.
launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist

echo '/usr/bin/caffeinate -s /usr/local/bin/bacula-idle-watch.sh' | at now

---

Note that by nature 'at' is not immediate. It may take a minute or so for
the script to launch, so plan accordingly.

On Sat, Jan 5, 2019 at 8:18 AM Josh Fisher  wrote:

> In the ClinetBeforeJob script, use the at command to schedule the launch
> of the caffeinate job with a runtime of 'now'. For example,
>
> at -f caffeinate-script.sh now
>
>
> On 1/4/2019 2:36 PM, David Brodbeck wrote:
>
> This is driving me nuts because I feel like it should be straightforward
> and I must be missing something basic.
>
> I want to launch the caffeinate command on OS X before starting a job.
> Caffeinate takes a command as an argument, then goes into the background
> and keeps the machine awake until the command exits. I use this after
> waking machines up using a WOL script.
>
> When tested from the command line, caffeinate immediately backgrounds
> itself. However, when I try to run it as a Bacula ClientBeforeJob script,
> bacula-fd waits around forever for caffeiniate to exit.
>
> Here's what I've tried so far:
> - Having bacula run a script that then runs caffeinate.
> - Having bacula run a script that then runs caffeinate using nohup.
> - Having the script redirect stdin, stdout, and stderr of caffeinate to
> /dev/null
> - Adding an ampersand after the script in the bacula ClientBeforeJob
> specification.
>
> What invariably happens is the bash process created by bacula becomes a
> zombie and waits for caffeinate to exit. Inspecting the caffeinate process
> with lsof shows all of the file handles are redirected to /dev/null as
> expected, so I don't think this is a case of stdin or stdout causing
> problems. In all cases the only way to get bacula to finish the backup is
> to kill the script that caffeinate is running.
>
> I can't figure out why I can't get bacula-fd to move on after the script
> goes into the background. When I run the script manually from the command
> line it backgrounds immediately.
>
> The oddest thing is this worked fine on clients using bacula-fd version
> 7.4.x, but fails on a client using 9.2.0.
>
> Here's the script bacula-fd runs, as it currently stands:
>
> --
> #!/bin/bash
>
> PATH=/bin:/usr/bin:/usr/local/bin
>
> # Script to prevent system sleep while bacula is working.
> # see bacula-idle-watch.sh for details.
>
> nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null  --
>
> Here's the contents of bacula-idle-watch.sh; it just waits to exit until
> there's no bacula network connection anymore. caffeinate will terminate
> once the script exits.
>
> --
> #!/bin/sh
>
> # This script delays a few minutes, then loops, checking for bacula-fd
> # connections. When there are none, it exits.
> # This is meant to be run with caffeinate in a bacula before-job script,
> # e.g. "caffeinate -s bacula-idle-watch.sh"
> # This will prevent the machine from idle-sleeping until bacula finishes.
>
> PATH=/bin:/usr/bin:/usr/sbin
>
> # We put a long delay here in case it takes bacula a while to get going.
> sleep 300
>
> # Now loop while looking at the network connection.
> # We limit checks to once every five minutes because worst-case the machine
> # just waits an extra five minutes to sleep.
> while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
> sleep 300
> done
>
> # Once the script exits, the wake-lock is released.
> exit 0
> --
>
>
> --
> David Brodbeck
> System Administrator, Department of Mathematics
> University of California, Santa Barbara
>
>
>
> ___
> Bacula-users mailing 
> listBacula-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/bacula-users
>
>

-- 
David Brodbeck
System Administrator, Department of Mathematics
University of California, Santa Barbara
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-07 Thread Wanderlei Huttel
Hello David
I know that is not an elegant way, but you could try to execute a script
calling another one
I don't know if will works, but you can try.

#!/bin/bash
nohup caffeinate -s bacula-idle-watch.sh >/dev/null 2>&1 http://www.bacula.com.br


Em seg, 7 de jan de 2019 às 17:06, David Brodbeck 
escreveu:

> Hmm, good catch on the redirect, but it still doesn't work. Neither does
> adding the exec line.
>
> Running lsof on the caffeinate process shows stdin, stdout, and stderr are
> properly connected to /dev/null; same with bacula-idle-watch.sh. I can't
> determine what the bacula-caffeinate.sh script's file handles are because
> by the time I get a chance to run lsof, it's already exited and become a
> zombie. bacula-fd continues to wait for it none the less.
>
> Is there any way to tell bacula-fd to not wait for script output, as in
> the 7.4.x behavior? I realize I'm not really using this functionality for
> the intended purpose, but I can't be the only one with this sort of use
> case.
>
> On Mon, Jan 7, 2019 at 6:26 AM Martin Simmons 
> wrote:
>
>> Your script redirects stderr to the original stdout of the script.  To
>> redirect both to /dev/null, the 2>&1 must follow the >/dev/null like this:
>>
>> nohup caffeinate -s bacula-idle-watch.sh >/dev/null 2>&1 >
>> Bacula 9.2.0 collects the stderr from ClientBeforeJob commands, but Bacula
>> clients running 7.4.x would have worked because they discard it.
>>
>> If that doesn't fix it, then try redirecting the shell's stdio as well:
>>
>> exec >/dev/null 2>&1 > nohup caffeinate -s bacula-idle-watch.sh &
>>
>> __Martin
>>
>>
>> > On Fri, 4 Jan 2019 11:36:06 -0800, David Brodbeck said:
>> >
>> > This is driving me nuts because I feel like it should be straightforward
>> > and I must be missing something basic.
>> >
>> > I want to launch the caffeinate command on OS X before starting a job.
>> > Caffeinate takes a command as an argument, then goes into the background
>> > and keeps the machine awake until the command exits. I use this after
>> > waking machines up using a WOL script.
>> >
>> > When tested from the command line, caffeinate immediately backgrounds
>> > itself. However, when I try to run it as a Bacula ClientBeforeJob
>> script,
>> > bacula-fd waits around forever for caffeiniate to exit.
>> >
>> > Here's what I've tried so far:
>> > - Having bacula run a script that then runs caffeinate.
>> > - Having bacula run a script that then runs caffeinate using nohup.
>> > - Having the script redirect stdin, stdout, and stderr of caffeinate to
>> > /dev/null
>> > - Adding an ampersand after the script in the bacula ClientBeforeJob
>> > specification.
>> >
>> > What invariably happens is the bash process created by bacula becomes a
>> > zombie and waits for caffeinate to exit. Inspecting the caffeinate
>> process
>> > with lsof shows all of the file handles are redirected to /dev/null as
>> > expected, so I don't think this is a case of stdin or stdout causing
>> > problems. In all cases the only way to get bacula to finish the backup
>> is
>> > to kill the script that caffeinate is running.
>> >
>> > I can't figure out why I can't get bacula-fd to move on after the script
>> > goes into the background. When I run the script manually from the
>> command
>> > line it backgrounds immediately.
>> >
>> > The oddest thing is this worked fine on clients using bacula-fd version
>> > 7.4.x, but fails on a client using 9.2.0.
>> >
>> > Here's the script bacula-fd runs, as it currently stands:
>> >
>> > --
>> > #!/bin/bash
>> >
>> > PATH=/bin:/usr/bin:/usr/local/bin
>> >
>> > # Script to prevent system sleep while bacula is working.
>> > # see bacula-idle-watch.sh for details.
>> >
>> > nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null > > --
>> >
>> > Here's the contents of bacula-idle-watch.sh; it just waits to exit until
>> > there's no bacula network connection anymore. caffeinate will terminate
>> > once the script exits.
>> >
>> > --
>> > #!/bin/sh
>> >
>> > # This script delays a few minutes, then loops, checking for bacula-fd
>> > # connections. When there are none, it exits.
>> > # This is meant to be run with caffeinate in a bacula before-job script,
>> > # e.g. "caffeinate -s bacula-idle-watch.sh"
>> > # This will prevent the machine from idle-sleeping until bacula
>> finishes.
>> >
>> > PATH=/bin:/usr/bin:/usr/sbin
>> >
>> > # We put a long delay here in case it takes bacula a while to get going.
>> > sleep 300
>> >
>> > # Now loop while looking at the network connection.
>> > # We limit checks to once every five minutes because worst-case the
>> machine
>> > # just waits an extra five minutes to sleep.
>> > while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
>> > sleep 300
>> > done
>> >
>> > # Once the script exits, the wake-lock is released.
>> > exit 0
>> > --
>> >
>> >
>> > --
>> > David Brodbeck
>> > System Administrator, Department of Mathematics
>> > University of California, Santa Barbara
>> >
>>
>
>
> --
> 

Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-07 Thread David Brodbeck
Hmm, good catch on the redirect, but it still doesn't work. Neither does
adding the exec line.

Running lsof on the caffeinate process shows stdin, stdout, and stderr are
properly connected to /dev/null; same with bacula-idle-watch.sh. I can't
determine what the bacula-caffeinate.sh script's file handles are because
by the time I get a chance to run lsof, it's already exited and become a
zombie. bacula-fd continues to wait for it none the less.

Is there any way to tell bacula-fd to not wait for script output, as in the
7.4.x behavior? I realize I'm not really using this functionality for the
intended purpose, but I can't be the only one with this sort of use case.

On Mon, Jan 7, 2019 at 6:26 AM Martin Simmons  wrote:

> Your script redirects stderr to the original stdout of the script.  To
> redirect both to /dev/null, the 2>&1 must follow the >/dev/null like this:
>
> nohup caffeinate -s bacula-idle-watch.sh >/dev/null 2>&1 
> Bacula 9.2.0 collects the stderr from ClientBeforeJob commands, but Bacula
> clients running 7.4.x would have worked because they discard it.
>
> If that doesn't fix it, then try redirecting the shell's stdio as well:
>
> exec >/dev/null 2>&1  nohup caffeinate -s bacula-idle-watch.sh &
>
> __Martin
>
>
> > On Fri, 4 Jan 2019 11:36:06 -0800, David Brodbeck said:
> >
> > This is driving me nuts because I feel like it should be straightforward
> > and I must be missing something basic.
> >
> > I want to launch the caffeinate command on OS X before starting a job.
> > Caffeinate takes a command as an argument, then goes into the background
> > and keeps the machine awake until the command exits. I use this after
> > waking machines up using a WOL script.
> >
> > When tested from the command line, caffeinate immediately backgrounds
> > itself. However, when I try to run it as a Bacula ClientBeforeJob script,
> > bacula-fd waits around forever for caffeiniate to exit.
> >
> > Here's what I've tried so far:
> > - Having bacula run a script that then runs caffeinate.
> > - Having bacula run a script that then runs caffeinate using nohup.
> > - Having the script redirect stdin, stdout, and stderr of caffeinate to
> > /dev/null
> > - Adding an ampersand after the script in the bacula ClientBeforeJob
> > specification.
> >
> > What invariably happens is the bash process created by bacula becomes a
> > zombie and waits for caffeinate to exit. Inspecting the caffeinate
> process
> > with lsof shows all of the file handles are redirected to /dev/null as
> > expected, so I don't think this is a case of stdin or stdout causing
> > problems. In all cases the only way to get bacula to finish the backup is
> > to kill the script that caffeinate is running.
> >
> > I can't figure out why I can't get bacula-fd to move on after the script
> > goes into the background. When I run the script manually from the command
> > line it backgrounds immediately.
> >
> > The oddest thing is this worked fine on clients using bacula-fd version
> > 7.4.x, but fails on a client using 9.2.0.
> >
> > Here's the script bacula-fd runs, as it currently stands:
> >
> > --
> > #!/bin/bash
> >
> > PATH=/bin:/usr/bin:/usr/local/bin
> >
> > # Script to prevent system sleep while bacula is working.
> > # see bacula-idle-watch.sh for details.
> >
> > nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null  > --
> >
> > Here's the contents of bacula-idle-watch.sh; it just waits to exit until
> > there's no bacula network connection anymore. caffeinate will terminate
> > once the script exits.
> >
> > --
> > #!/bin/sh
> >
> > # This script delays a few minutes, then loops, checking for bacula-fd
> > # connections. When there are none, it exits.
> > # This is meant to be run with caffeinate in a bacula before-job script,
> > # e.g. "caffeinate -s bacula-idle-watch.sh"
> > # This will prevent the machine from idle-sleeping until bacula finishes.
> >
> > PATH=/bin:/usr/bin:/usr/sbin
> >
> > # We put a long delay here in case it takes bacula a while to get going.
> > sleep 300
> >
> > # Now loop while looking at the network connection.
> > # We limit checks to once every five minutes because worst-case the
> machine
> > # just waits an extra five minutes to sleep.
> > while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
> > sleep 300
> > done
> >
> > # Once the script exits, the wake-lock is released.
> > exit 0
> > --
> >
> >
> > --
> > David Brodbeck
> > System Administrator, Department of Mathematics
> > University of California, Santa Barbara
> >
>


-- 
David Brodbeck
System Administrator, Department of Mathematics
University of California, Santa Barbara
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-07 Thread Martin Simmons
Your script redirects stderr to the original stdout of the script.  To
redirect both to /dev/null, the 2>&1 must follow the >/dev/null like this:

nohup caffeinate -s bacula-idle-watch.sh >/dev/null 2>&1 /dev/null 2>&1  On Fri, 4 Jan 2019 11:36:06 -0800, David Brodbeck said:
> 
> This is driving me nuts because I feel like it should be straightforward
> and I must be missing something basic.
> 
> I want to launch the caffeinate command on OS X before starting a job.
> Caffeinate takes a command as an argument, then goes into the background
> and keeps the machine awake until the command exits. I use this after
> waking machines up using a WOL script.
> 
> When tested from the command line, caffeinate immediately backgrounds
> itself. However, when I try to run it as a Bacula ClientBeforeJob script,
> bacula-fd waits around forever for caffeiniate to exit.
> 
> Here's what I've tried so far:
> - Having bacula run a script that then runs caffeinate.
> - Having bacula run a script that then runs caffeinate using nohup.
> - Having the script redirect stdin, stdout, and stderr of caffeinate to
> /dev/null
> - Adding an ampersand after the script in the bacula ClientBeforeJob
> specification.
> 
> What invariably happens is the bash process created by bacula becomes a
> zombie and waits for caffeinate to exit. Inspecting the caffeinate process
> with lsof shows all of the file handles are redirected to /dev/null as
> expected, so I don't think this is a case of stdin or stdout causing
> problems. In all cases the only way to get bacula to finish the backup is
> to kill the script that caffeinate is running.
> 
> I can't figure out why I can't get bacula-fd to move on after the script
> goes into the background. When I run the script manually from the command
> line it backgrounds immediately.
> 
> The oddest thing is this worked fine on clients using bacula-fd version
> 7.4.x, but fails on a client using 9.2.0.
> 
> Here's the script bacula-fd runs, as it currently stands:
> 
> --
> #!/bin/bash
> 
> PATH=/bin:/usr/bin:/usr/local/bin
> 
> # Script to prevent system sleep while bacula is working.
> # see bacula-idle-watch.sh for details.
> 
> nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null  --
> 
> Here's the contents of bacula-idle-watch.sh; it just waits to exit until
> there's no bacula network connection anymore. caffeinate will terminate
> once the script exits.
> 
> --
> #!/bin/sh
> 
> # This script delays a few minutes, then loops, checking for bacula-fd
> # connections. When there are none, it exits.
> # This is meant to be run with caffeinate in a bacula before-job script,
> # e.g. "caffeinate -s bacula-idle-watch.sh"
> # This will prevent the machine from idle-sleeping until bacula finishes.
> 
> PATH=/bin:/usr/bin:/usr/sbin
> 
> # We put a long delay here in case it takes bacula a while to get going.
> sleep 300
> 
> # Now loop while looking at the network connection.
> # We limit checks to once every five minutes because worst-case the machine
> # just waits an extra five minutes to sleep.
> while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
> sleep 300
> done
> 
> # Once the script exits, the wake-lock is released.
> exit 0
> --
> 
> 
> -- 
> David Brodbeck
> System Administrator, Department of Mathematics
> University of California, Santa Barbara
> 


___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


Re: [Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-05 Thread Josh Fisher
In the ClinetBeforeJob script, use the at command to schedule the launch 
of the caffeinate job with a runtime of 'now'. For example,


at -f caffeinate-script.sh now


On 1/4/2019 2:36 PM, David Brodbeck wrote:
This is driving me nuts because I feel like it should be 
straightforward and I must be missing something basic.


I want to launch the caffeinate command on OS X before starting a job. 
Caffeinate takes a command as an argument, then goes into the 
background and keeps the machine awake until the command exits. I use 
this after waking machines up using a WOL script.


When tested from the command line, caffeinate immediately backgrounds 
itself. However, when I try to run it as a Bacula ClientBeforeJob 
script, bacula-fd waits around forever for caffeiniate to exit.


Here's what I've tried so far:
- Having bacula run a script that then runs caffeinate.
- Having bacula run a script that then runs caffeinate using nohup.
- Having the script redirect stdin, stdout, and stderr of caffeinate 
to /dev/null
- Adding an ampersand after the script in the bacula ClientBeforeJob 
specification.


What invariably happens is the bash process created by bacula becomes 
a zombie and waits for caffeinate to exit. Inspecting the caffeinate 
process with lsof shows all of the file handles are redirected to 
/dev/null as expected, so I don't think this is a case of stdin or 
stdout causing problems. In all cases the only way to get bacula to 
finish the backup is to kill the script that caffeinate is running.


I can't figure out why I can't get bacula-fd to move on after the 
script goes into the background. When I run the script manually from 
the command line it backgrounds immediately.


The oddest thing is this worked fine on clients using bacula-fd 
version 7.4.x, but fails on a client using 9.2.0.


Here's the script bacula-fd runs, as it currently stands:

--
#!/bin/bash

PATH=/bin:/usr/bin:/usr/local/bin

# Script to prevent system sleep while bacula is working.
# see bacula-idle-watch.sh for details.

nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null Here's the contents of bacula-idle-watch.sh; it just waits to exit 
until there's no bacula network connection anymore. caffeinate will 
terminate once the script exits.


--
#!/bin/sh

# This script delays a few minutes, then loops, checking for bacula-fd
# connections. When there are none, it exits.
# This is meant to be run with caffeinate in a bacula before-job script,
# e.g. "caffeinate -s bacula-idle-watch.sh"
# This will prevent the machine from idle-sleeping until bacula finishes.

PATH=/bin:/usr/bin:/usr/sbin

# We put a long delay here in case it takes bacula a while to get going.
sleep 300

# Now loop while looking at the network connection.
# We limit checks to once every five minutes because worst-case the 
machine

# just waits an extra five minutes to sleep.
while ( netstat -an | grep '\.9102.*ESTABLISHED' >/dev/null ) ; do
    sleep 300
done

# Once the script exits, the wake-lock is released.
exit 0
--


--
David Brodbeck
System Administrator, Department of Mathematics
University of California, Santa Barbara



___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users


[Bacula-users] Run ClientBeforeJob script in background instead of waiting for it.

2019-01-04 Thread David Brodbeck
This is driving me nuts because I feel like it should be straightforward
and I must be missing something basic.

I want to launch the caffeinate command on OS X before starting a job.
Caffeinate takes a command as an argument, then goes into the background
and keeps the machine awake until the command exits. I use this after
waking machines up using a WOL script.

When tested from the command line, caffeinate immediately backgrounds
itself. However, when I try to run it as a Bacula ClientBeforeJob script,
bacula-fd waits around forever for caffeiniate to exit.

Here's what I've tried so far:
- Having bacula run a script that then runs caffeinate.
- Having bacula run a script that then runs caffeinate using nohup.
- Having the script redirect stdin, stdout, and stderr of caffeinate to
/dev/null
- Adding an ampersand after the script in the bacula ClientBeforeJob
specification.

What invariably happens is the bash process created by bacula becomes a
zombie and waits for caffeinate to exit. Inspecting the caffeinate process
with lsof shows all of the file handles are redirected to /dev/null as
expected, so I don't think this is a case of stdin or stdout causing
problems. In all cases the only way to get bacula to finish the backup is
to kill the script that caffeinate is running.

I can't figure out why I can't get bacula-fd to move on after the script
goes into the background. When I run the script manually from the command
line it backgrounds immediately.

The oddest thing is this worked fine on clients using bacula-fd version
7.4.x, but fails on a client using 9.2.0.

Here's the script bacula-fd runs, as it currently stands:

--
#!/bin/bash

PATH=/bin:/usr/bin:/usr/local/bin

# Script to prevent system sleep while bacula is working.
# see bacula-idle-watch.sh for details.

nohup caffeinate -s bacula-idle-watch.sh 2>&1 >/dev/null /dev/null ) ; do
sleep 300
done

# Once the script exits, the wake-lock is released.
exit 0
--


-- 
David Brodbeck
System Administrator, Department of Mathematics
University of California, Santa Barbara
___
Bacula-users mailing list
Bacula-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-users