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 <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 <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 <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 /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 &
>>> --
>>>
>>> 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
>>
>>
>
> --
> 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

Reply via email to