Trying to use LXC EXEC to start up a script (simple ncat webserver) that I want to run in the background. The script just listens on a certain port and pipes some text to the user connecting to the listening server.
what happens is that when I type the lxc exec – bash -c /root/script.sh & the prompt will not come back. I have tried lxc exec – bash -c ‘/root/script.sh &’ and a number of other variants. Nothing seems to work.
If I get onto the container I can run that script just fine.
stgraber@castiana:~$ time lxc exec keybase -- bash -c "/root/test.sh"
real 0m5.128s
user 0m0.013s
sys 0m0.015s
stgraber@castiana:~$ time lxc exec keybase -- bash -c "/root/test.sh &"
real 0m0.123s
user 0m0.013s
sys 0m0.012s
Note that it may be because your scripts uses stdin which would keep the connection active. In such case, try running it through “nohup” which should avoid that particular behavior (lxc exec test – bash -c “nohup /root/test.sh &”).