What we would like to do:
We have short living virtual machines for running scripts. The virtual machines are used through SSH to perform "builds" (sequence of scripts) and discarded once all the scripts finish. Every script runs through a new SSH connection/session.
This works really well for almost all of the scenarios we have, except two major use cases:
- when the script have to control the iOS Simulator installed on the virtual machine (this is the primary use case we want to solve at the moment) - technical note: the iOS Simulator can only be properly controlled from a GUI context, right now we use a special Go based mini server (https://github.com/bitrise-io/xcodebuild-unittest-miniserver) which is started as a Launch Agent when the user signs in and so it has the user's GUI context
- to maintain access to OS X keychain (through SSH the OS X keychains can be opened and managed but the keychain locks once the SSH session is closed)
Both of these issues could be solved if we could somehow start an agent inside the virtual machine and later we could connect to that specific daemon/agent, send the commands we want to run to the daemon/agent, and have the daemon/agent perform it. A requirement is to have a stream of the output of the actual scripts/commands which run inside the virtual machine.
What we do right now is to perform the scripts/commands through a simple SSH command like ssh ssh-params 'bash -l -c "echo \"hello world\""'
. Of course this is a seriously simplified example but it's close to what we have right now, and with this we can get the output of the command as a stream to fulfill the logging requirement and additionally we can get the command's exit code.
So what we would like to do is something similar in terms that the command is specified "from outside" of the virtual machine but executed inside the virtual machine and the output of the command is available for the "outside" (caller) process as a stream, not just after the script finishes, as well as the command's exit code can be retrieved easily by the "outside" process.
In terms of tools we're quite open (we don't have to depend on SSH, that's just how it works at the moment) but the tool should be available for OS X and if possible for Linux (although in this case OS X is the priority, as both of the problematic use cases are related to OS X).
TL;DR; we would like a tool which can be used similarly to the above mentioned SSH command but it can connect to an agent/daemon which is already running at the remote (virtual machine) end, and the output generated by the specified "remote command" should be available for the caller process as a stream, not just at the end of the command. In addition to collecting the remote command's outputs we also have to be able to get it's exit code.
Final words: we ultimately decided to create our own solution because we couldn't figure out an easier way. You can find it on GitHub: https://github.com/bitrise-io/cmd-bridge - it supports all the required things I described and additionally it has command environment variable handling support (to define environment variables just for that remote command).
tmux
orscreen
if you're wanting to connect to an already-running console session.tmux
. As long as you're not tellingtmux
to run the script itself, it should survive the end of the script's execution. You might try feeding your script tobash
using the--rcfile
option. You may have to alter the script so that it sources the user's~/.bashrc
as the first thing if need be.