All Projects → random-python → nspawn

random-python / nspawn

Licence: Apache-2.0 license
Containers with systemd-nspawn

Programming Languages

python
139335 projects - #7 most used programming language
PHP
23972 projects - #3 most used programming language
shell
77523 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nspawn

Asus Fan Control
🌀 Fan control for ASUS devices running Linux.
Stars: ✭ 120 (+531.58%)
Mutual labels:  systemd
Ansible Role Hardening
Ansible role to apply a security baseline. Systemd edition.
Stars: ✭ 188 (+889.47%)
Mutual labels:  systemd
daemons.el
An Emacs UI for managing init system services
Stars: ✭ 87 (+357.89%)
Mutual labels:  systemd
Fluent Plugin Systemd
This is a fluentd input plugin. It reads logs from the systemd journal.
Stars: ✭ 124 (+552.63%)
Mutual labels:  systemd
Systemd Service Hardening
Basic guide to harden systemd services
Stars: ✭ 165 (+768.42%)
Mutual labels:  systemd
Chkservice
Systemd units manager with ncurses, terminal interface
Stars: ✭ 219 (+1052.63%)
Mutual labels:  systemd
Freenom Dns Updater
A tool to update freenom's dns records
Stars: ✭ 117 (+515.79%)
Mutual labels:  systemd
sicherboot
Unmaintained systemd-boot integration with secure boot support; consider https://github.com/Foxboron/sbctl instead.
Stars: ✭ 31 (+63.16%)
Mutual labels:  systemd
Procsd
Manage your application processes in production hassle-free like Heroku CLI with Procfile and Systemd
Stars: ✭ 181 (+852.63%)
Mutual labels:  systemd
journald
Go implementation of systemd Journal's native API for logging
Stars: ✭ 34 (+78.95%)
Mutual labels:  systemd
Graceful
graceful reload golang http server, zero downtime, compatible with systemd, supervisor
Stars: ✭ 129 (+578.95%)
Mutual labels:  systemd
Netctl
Profile based systemd network management
Stars: ✭ 163 (+757.89%)
Mutual labels:  systemd
Systemd Ngrok
Automatically start ngrok by systemd
Stars: ✭ 241 (+1168.42%)
Mutual labels:  systemd
Go Systemd
Go bindings to systemd socket activation, journal, D-Bus, and unit files
Stars: ✭ 1,756 (+9142.11%)
Mutual labels:  systemd
fresh-coffee-listener
Using a raspberry pi, we listen to the coffee machine and count the number of coffee consumption
Stars: ✭ 52 (+173.68%)
Mutual labels:  systemd
Capistrano Mb
[unmaintained] Capistrano tasks for deploying Rails from scratch to Ubuntu 16.04 and 18.04
Stars: ✭ 117 (+515.79%)
Mutual labels:  systemd
Container Linux Update Operator
A Kubernetes operator to manage updates of Container Linux by CoreOS
Stars: ✭ 208 (+994.74%)
Mutual labels:  systemd
ansible-role-systemd-service
No description or website provided.
Stars: ✭ 37 (+94.74%)
Mutual labels:  systemd
squashmount
Init and management script for mounting rewritable squashfs-compressed data
Stars: ✭ 40 (+110.53%)
Mutual labels:  systemd
Dplatform Shell
Deploy self-hosted apps easily: simple, bloat-free, independent installation
Stars: ✭ 245 (+1189.47%)
Mutual labels:  systemd

nspawn

Travis Status Appvey Status Package Version Python Versions

Containers with systemd-nspawn

Features:

Install

To install python package:

sudo pip install nspawn

Build Script

To build an image, provide and invoke executable build.py script, for example:

For available build options run ./build.py --help

Setup Script

To setup a machine, provide and invoke executable setup.py script, for example:

For available setup options run ./setup.py --help

Machine Service

To review provisioned, generated and running machine service, run:

machinectl
systemctl status <machine>
cat /etc/systemd/system/<machine>.service

for example, demo generated services:

Machine Resources

Location of machine files and folders:

/etc/systemd/system/<machine>.service
/var/lib/machines/<machine>
/var/lib/nspawn/runtime/<machine>

Machine Management

To interact with live machine:

  • for machines registered with machinectl
  • for machines with systemd init, such as archlinux
# start interactive shell:
sudo machinectl shell <machine> 
# invoke command with args:
sudo machinectl shell <machine> /bin/command arg1 arg2 ... 
  • for machines not registered with machinectl
  • for machines without systemd init, such as alpine linux
# start interactive shell:
./setup.py --action=nsenter 
  • alternatively, use package-provided nspawn-enter command:
# start interactive shell:
nspawn-enter <machine> 
# invoke command with args:
nspawn-enter <machine> "command arg1 arg2 ..." 

Configuration

Available configuration options are described in config.ini file.

Use config/path_list option to control configuration override file list.

Image Server

Package comes with provisioning command nspawn-hatch which can build and setup local http/https image server.

# review available services:
nspawn-hatch list
# provision image server service:
nspawn-hatch update image-server
# verify image server machine status:
machinectl

Image server settings:

Image syncer settings (replicate to Amazon AWS S3):

Build DSL

Build DSL is used in build.py, is activated by from nspawn.build import * and provides keywords:

    'TOOL',
    'IMAGE',
    'PULL',
    'EXEC',
    'WITH',
    'FETCH',
    'COPY',
    'CAST',
    'RUN',
    'SH',
    'PUSH',

Setup DSL

Setup DSL is used in setup.py, is activated by from nspawn.setup import * and provides keywords:

    'TOOL',
    'IMAGE',
    'MACHINE',
    'WITH',
    'EXEC',
    'COPY',
    'CAST',
    'RUN',
    'SH',

DSL Syntax

TOOL

Expose build/setup utility functions:

TOOL.<function>(...)

IMAGE()

Declare image identity:

IMAGE("http://host/path/package.tar.gz")
IMAGE(url="http://host/path/package.tar.gz")

PULL()

Provision dependency image:

PULL("http://host/path/package.tar.gz")
PULL(url="http://host/path/package.tar.gz")

EXEC()

Declare image entry point executable i.e. COMMAND [ARGS...]:

EXEC(['/usr/bin/env', 'sh', '-c', 'echo "hello-kitty"'])
EXEC(command=['/usr/bin/env', 'sh', '-c', 'echo "hello-kitty"'])

WITH()

Customize machine features using nspawn container settings:

WITH(
    SettingName1='setting 1 value a',
    SettingName2='setting 2 value b',
    ...,
)

COPY()

Copy local resources:

  • when used in build.py: target is in the image
  • when used in setup.py: target is on the host
COPY("/etc")
COPY(path="/etc")
COPY(source="/root/input.md", target="/root/output.md")

CAST()

Template local resources:

  • when used in build.py: target is in the image
  • when used in setup.py: target is on the host
CAST("/root/readme.md", variable="template varialbe", ...)
CAST(path="/root/readme.md", variable="template varialbe", ...)
CAST(source="/root/input.md", target="/root/output.md", variable="template varialbe", ...)

Template uses python/jinja format, i.e:

this template variable will be substituted: {{variable}}

FETCH()

Download and extract remote resource:

FETCH( # use when source and target are the same
   url="http://server/package.tar.gz", # url for remote resource
   path="/common-path", # path inside the package source and image target
)
FETCH( # use when source and target are different
   url="http://server/package.tar.gz", # url for remote resource
   source="/package-path", # path inside the package extract
   target="/opt/resource", # path inside the build image target
)

RUN()

Invoke command, with target depending on the context:

  • when used in build.py: invoke inside the image
  • when used in setup.py: invoke on the host
RUN(['/usr/bin/env', 'ls', '-las'])
RUN(command=['/usr/bin/env', 'ls', '-las'])

SH()

Invoke shell script, with target depending on the context:

  • when used in build.py: invoke inside the image
  • when used in setup.py: invoke on the host
SH("ls -las")
SH(script="ls -las")

Note:

  • SH(script) is equivalent to RUN(command=['/usr/bin/env', 'sh', '-c', script])

PUSH()

Publish image result to the declared url:

PUSH()

MACHINE()

Declare machine service:

MACHINE('machine-name')
MACHINE(name='machine-name')
MACHINE(name='machine-name', template='/path/to/service/template/machine.service')

Provide inline service unit changes:

MACHINE(
    name='machine-name',
    # extra entries for [Unit] section
    unit_conf=[
        "Description=hello-world",  # override description
    ],
    # extra entries for [Service] section
    service_conf=[
        "CPUQuota=10%",  # throttle processor usage
    ],
    # extra entries for [Install] section
    install_conf=[
        "WantedBy=machines.target",  # inject unit dependency
    ],
)

Design custom service templates based on package-provided defaults, for example:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].