I have an init script that does something like this in the start() function:
runuser -s /bin/bash - prog -c "nohup php /foo/bar.php 2>&1 >> /var/log/bar.log &"
When I SSH into the machine and call the init script:
server:~$ sudo /etc/init.d/foo restart
everything is fine—all output goes to bar.log
as expected and I can logout.
However, if I call the init script directly from my SSH command:
workstation:~$ ssh server sudo /etc/init.d/foo restart
then the output comes to my local terminal, not the log, and I cannot close the SSH connection without losing all of that output (which is no longer going to the log file). Surely there's a better way to formulate the init script and any suggestions would be appreciated, but what's happening with the redirection in this example?