Last active
December 14, 2015 10:23
-
-
Save tarruda/2aea9107f04d8b8d8dbf to your computer and use it in GitHub Desktop.
Autostart unprivileged lxc containers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/expect | |
| # Workaround to automatically start unprivileged containers on boot. This is | |
| # required because unprivileged containers only seem to work when started from | |
| # an interactive login session. Reference: https://github.com/lxc/lxc/issues/411#issuecomment-71414916) | |
| # | |
| # This script can be called from the user crontab with the @reboot | |
| # directive(runs once at startup). One way to achieve this is to save this | |
| # script to /home/USER/lxc-autostart.tcl and add the following entry to | |
| # `crontab -e`: | |
| # | |
| # @reboot /home/USER/lxc-autostart.tcl | |
| # | |
| # Requires "expect" installed(sudo apt-get install expect) | |
| # Only timeout after 5 minutes, which should be enough to start all containers. | |
| set timeout 300 | |
| # Start an interactive ssh session connected to localhost. Assumes no password | |
| # or confirmation prompts will be displayed, which can be achieved by | |
| # previously connecting with an unlocked key. | |
| set ssh_session {ssh localhost} | |
| spawn {*}$ssh_session | |
| send { | |
| # Send the lxct-autostart command, which starts all unprivileged containers | |
| # configured with lxc.start.auto = 1 | |
| lxc-autostart | |
| # Exit the ssh session | |
| exit | |
| } | |
| expect eof |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I saw your post on askubuntu.com and followed your link. However, your solution did not work for me as I have a passphrase protected private key. Even with:
I was still prompted for a passphrase! I had to create a private key pair without a passphrase to make it work:
Then with the expect script, I had this:
Thanks for your contribution.
ak.