Last active
January 12, 2020 18:34
-
-
Save lbrame/877ca9ac2a8508a336da7d89855cc566 to your computer and use it in GitHub Desktop.
Simple wrapper for basic LXC operations. Does not add any functionality, it just makes it faster to manage LXC containers by providing shorter commands and bundling commonly used combination of commands.
This file contains 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
#!/bin/bash | |
container='ubuntu' | |
cmd="${1:-run}" | |
bold=$(tput bold) | |
normal=$(tput sgr0) | |
if (( $EUID != 0 )); then | |
sudo "$(realpath $0)" "$@" | |
exit $? | |
fi | |
case $cmd in | |
run ) | |
lxc-start -n $container | |
lxc-console -n $container -t 0 ;; | |
start ) | |
lxc-start -n $container ;; | |
stop ) | |
lxc-stop $container ;; | |
console ) | |
lxc-console -n $container -t 0 ;; | |
attach ) | |
lxc-attach $container ;; | |
help ) | |
printf '%b\n' \ | |
"${bold}LXC quick operation wrapper${normal}" \ | |
"${bold}$container run${normal} = start a container and connect to the console" \ | |
"${bold}$container start${normal} = start a container" \ | |
"${bold}$container stop${normal} = stop a container" \ | |
"${bold}$container console${normal} = reconnect to the console of a running container" \ | |
"${bold}$container attach${normal} = attach to a running container" \ | |
"${bold}help${normal} = display this help page | |
you can change the container variable in the script to match the name of your desired container." ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment