Compare commits

..

No commits in common. "c24dbcdabb6ee96d0a46d454167d189058284c43" and "c094078f4ee709b264fa7945027358d2a4919259" have entirely different histories.

2 changed files with 48 additions and 32 deletions

View file

@ -4,28 +4,40 @@
## How does it work ## How does it work
`qemush` allows to run commands as Unix user `qemu` to manage virtual machines and their disks associated. `qemush` allows to run commands as Unix user `qemu` to manage virtual
machines and their disks associated.
## Why ## Why
`qemush` is **daemonless**: no bloaty long running process is needed for `qemush` to work. `qemush` is **daemonless**: no bloaty long running process is needed for
`qemush` to work.
`qemush` is **lightweight**: it only consists in a shell script to automate repeated tasks and force good practices. `qemush` is **lightweight**: it only consists in a shell script to
automate repeated tasks and force good practices.
`qemush` needs **few dependencies**: see section [Dependencies](#dependencies) for details. `qemush` needs **few dependencies**: see section
[Dependencies](#dependencies) for details.
`qemush` is **hackable**: you can [write your own launching scripts](#writing-a-launching-script) to make it work as intended. `qemush` is **hackable**: you can [write your own launching
scripts](#writing-a-launching-script) to make it work as intended.
`qemush` is **easy to setup**: you can make it work in a few steps, see section [Installation instructions](#installation-instructions). `qemush` is **easy to setup**: you can make it work in a few steps, see
section [Installation instructions](#installation-instructions).
## Good practices? ## Good practices?
Here is a list of good practices forced by `qemush`. Here is a list of good practices forced by `qemush`.
- **Processes running as user `qemu`**: members of group `qemu` can manage the same virtual machines - **Processes running as user `qemu`**: members of group `qemu` can manage
- **Modularization**: `qemush` launching scripts are intended to be stackable to reuse common `qemu` parameters in all virtual machines needing them keep track of them the same virtual machines
- **Copy-on-write**: images are formatted using `qcow2` to use less space on disk - **Modularization**: `qemush` launching scripts are intended to be
- **Process detachment**: you can log out and have your virtual machines still running, control them via Unix sockets stackable to reuse common `qemu` parameters in all virtual machines
needing them
keep track of them
- **Copy-on-write**: images are formatted using `qcow2` to use less space
on disk
- **Process detachment**: you can log out and have your virtual machines
still running, control them via Unix sockets
## Is it better than `libvirt` ? ## Is it better than `libvirt` ?
@ -35,9 +47,11 @@ No. `qemush` and `libvirt` are for different use cases. `qemush` will allow you
From version 0.9.0, `qemush` is written in pure POSIX shell! The previous dependency on `bash` was removed in consequence. From version 0.9.0, `qemush` is written in pure POSIX shell! The previous dependency on `bash` was removed in consequence.
All dependencies are common packages for a distribution, you'll be able to grab them from your favorite packages sources. All dependencies are common packages for a distribution, you'll be able to
grab them from your favorite packages sources.
- `qemu` - this is literally a QEMU wrapper so there's a chance you'll need it - `qemu` - this is literally a QEMU wrapper so there's a chance you'll
need it
- A POSIX compliant shell - `bash` (POSIX mode), `*ash`, `*ksh` are POSIX shells - A POSIX compliant shell - `bash` (POSIX mode), `*ash`, `*ksh` are POSIX shells
- `coreutils` - used for basic OS operations - `coreutils` - used for basic OS operations
- `sudo` - execute commands as `qemu` - `sudo` - execute commands as `qemu`
@ -48,7 +62,9 @@ All dependencies are common packages for a distribution, you'll be able to grab
### QEMU user and group ### QEMU user and group
`qemush` acts as Unix user `qemu` to manage virtual machines. You need to create a system user `qemu` that cannot login, with any home directory, in an Unix group of the same name. Example: `qemush` acts as Unix user `qemu` to manage virtual machines. You need to
create a system user `qemu` that cannot login, with any home directory,
in an Unix group of the same name. Example:
```sh ```sh
# Example if the qemu user doesn't exist # Example if the qemu user doesn't exist
@ -56,11 +72,14 @@ All dependencies are common packages for a distribution, you'll be able to grab
useradd -r -s /bin/nologin qemu useradd -r -s /bin/nologin qemu
``` ```
For ease of use, you need to grant every user in the `qemu` group via `sudo` the right to execute commands as `qemu`. You can find an example `sudoers` rule in this repo's `etc/sudoers.d` folder. For ease of use, you need to grant every user in the `qemu` group via
`sudo` the right to execute commands as `qemu`. You can find an example
`sudoers` rule in this repo's `etc/sudoers.d` folder.
### Via `Makefile` (recommended) ### Via `Makefile` (recommended)
Just run the following command at the root of this repository to install `qemush` (previous step is **mandatory**) : Just run the following command at the root of this repository to install
`qemush` (previous step is **mandatory**) :
```sh ```sh
make make
@ -68,23 +87,27 @@ make
> And what if I don't want to bindly run this obscure `Makefile` ??? > And what if I don't want to bindly run this obscure `Makefile` ???
You'd be right. The next section is the exhaustive list of steps handled by the `Makefile` for the installation process. You'd be right. The next section is the exhaustive list of steps handled
by the `Makefile` for the installation process.
### Manual installation (what does the `Makefile` do) ### Manual installation (what does the `Makefile` do)
- Create `disks`, `launchers`, `shared`, `sockets/monitors`, `socket/spice` and `bin` directories in `~qemu` - Create `disks`, `launchers` and `bin` directories in `~qemu`
- Copy `qemush` scripts parts from `qemu/bin` in `~qemu/bin` with mode `740` - Copy `qemush` scripts parts from `qemu/bin` in `~qemu/bin` with mode
`740`
- Compile C programs from `src` in `~qemu/bin` with mode `740` - Compile C programs from `src` in `~qemu/bin` with mode `740`
- Copy the default launching scripts to `~qemu/launchers` with mode `740` ; this is optional but the one called `kvm` is the reference `qemush` launching script! - Copy the default launching scripts to `~qemu/launchers` with mode `740`
- Copy `bin/qemush` to `/usr/local/bin/qemush` with mode `755` - Copy `bin/qemush` to `/usr/local/bin/qemush` with mode `755`
## Usage ## Usage
### Writing a launching script ### Writing a launching script
The default text editor used by `qemush` is `vi`, but it can be overriden by the `EDITOR` environment variable. The default text editor used by `qemush` is `nvim`, but it can be
overriden by the `EDITOR` environment variable.
Run the following command to start editing a launching script by the name of your choice: Run the following command to start editing a launching script by the name
of your choice:
```sh ```sh
qemush edit "$name" qemush edit "$name"
@ -94,7 +117,8 @@ Example scripts are available in this repo's `qemu/launchers` folder.
### Launching a virtual machine ### Launching a virtual machine
Virtual machines are identified by the name of their launching scripts. You can launch any machine with the following command: Virtual machines are identified by the name of their launching scripts.
You can launch any machine with the following command:
```sh ```sh
qemush start "$name" qemush start "$name"

View file

@ -23,7 +23,7 @@ perror() {
public_help() { public_help() {
name=$(basename "$0") name=$(basename "$0")
cat << EOF exec cat << EOF
${name}: usage: ${name}: usage:
${name} running - (default behaviour) list running VMs ${name} running - (default behaviour) list running VMs
${name} ls - list available VMs ${name} ls - list available VMs
@ -53,20 +53,12 @@ error_usage() {
# Function to start a virtual machine # Function to start a virtual machine
public_start() { public_start() {
if [ "$1" = -f ] || [ "$1" = --foreground ]; then
daemonize=
else
daemonize=-daemonize
fi
while echo "$1" | grep -q '^-'; do shift; done;
export QEMUSH_NAME="$1" export QEMUSH_NAME="$1"
set -- "$@" \ set -- "$@" \
-name "$QEMUSH_NAME" \ -name "$QEMUSH_NAME" \
-monitor "unix:$(pathof socket),server,nowait" \ -monitor "unix:$(pathof socket),server,nowait" \
$daemonize -daemonize
if ! "$@"; then if ! "$@"; then
perror "error launching virtual machine \"${QEMUSH_NAME}\"" perror "error launching virtual machine \"${QEMUSH_NAME}\""