I have a simple hook script and on post-start I need to run a shell script in the background (which will take a while to run).
The core of the issue is that the VM is locked until the hook script exits. Since I don't care about any return from my shell script, i'd like to just have it run in the background and have the hook script return so the the vm can unlock.
I would expect something like this to work and it does from a shell but it doesn't when run by the hook script:
I tried messing with using fork and exec, it didn't seem to help but I don't have enough of a grasp on perl to know.
I also tried attaching a shell script directly to the vm and then tried using ./background.sh & again with no luck. It seemed like this example would have worked but this time it doesn't run at all when executed by the hook script:
The interesting part about that example is it led me to discover that redirecting stderr could be a clue as redirecting it seems to be what causes the subshell commands to not run at all... not redirecting stderr causes the the hook script to wait for the subshell commands to complete just like before.
I must have a fundamental misunderstanding of something going on here and I can't help but wonder if it has something to do with the way perl executes system commands, it would be really nice to be pointed in the right direction.
The core of the issue is that the VM is locked until the hook script exits. Since I don't care about any return from my shell script, i'd like to just have it run in the background and have the hook script return so the the vm can unlock.
I would expect something like this to work and it does from a shell but it doesn't when run by the hook script:
Code:
system("./background.sh &");
I tried messing with using fork and exec, it didn't seem to help but I don't have enough of a grasp on perl to know.
I also tried attaching a shell script directly to the vm and then tried using ./background.sh & again with no luck. It seemed like this example would have worked but this time it doesn't run at all when executed by the hook script:
Code:
(sleep 5s; echo test >> /root/test.log) > /dev/null 2>&1 &
The interesting part about that example is it led me to discover that redirecting stderr could be a clue as redirecting it seems to be what causes the subshell commands to not run at all... not redirecting stderr causes the the hook script to wait for the subshell commands to complete just like before.
I must have a fundamental misunderstanding of something going on here and I can't help but wonder if it has something to do with the way perl executes system commands, it would be really nice to be pointed in the right direction.