Matrix AI
Infrastructure Automation
systemd is system & service manager that is also the PID 1 (root process) for some Linux operating systems (Fedora, NixOS, CoreOS)
its main function is process/service supervision on a single node
fleet is distributed init system for CoreOS that abstracts over multiple systemd nodes
its main function is service supervision across a CoreOS cluster
# system control $ systemctl --v $ systemctl status [unit] $ systemd-cgls $ systemd-cgtop $ systemctl $ systemctl list-unit-files # logs $ journalctl [--user] -b 0
# setup SSH tunnel (optional) $ ssh -p port key_path user@ip $ FLEETCTL_TUNNEL=ip:port # control the fleet $ fleetctl list-machines [-l] $ fleetctl list-units $ fleetctl list-unit-files $ fleetctl status unit $ fleetctl journal unit
[Unit]
Description=ApacheService # Let's create an apache service
[Service]
Restart=always
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill apache1
ExecStartPre=-/usr/bin/docker rm apache1
# we pull in the apache docker container if it doesn't exist yet
ExecStartPre=/usr/bin/docker pull coreos/apache
ExecStart=/usr/bin/docker run -rm --name apache1 -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
ExecStop=/usr/bin/docker stop apache1
[X-Fleet]
# can only run on this machine
X-ConditionMachineID=8acfff1514a64552a1a252f7da989aec
# must only run on machines with this metadata
X-ConditionMachineMetadata="diskType=SSD"
# there are more options available, check the fleet docs and systemd docs
# systemd --system unit file locations
$ ls /usr/lib/systemd/system
$ ls /etc/systemd/system
$ ls /run/systemd/system
# systemd --user unit file locations
$ ls /usr/lib/systemd/user
$ ls /etc/systemd/user
$ ls /run/systemd/user
$ ls $HOME/.config/systemd/user
$ ls $XDG_CONFIG_HOME/systemd/user
Here are where all the unit files should be:
# add your metadata to fleet.conf
$ cat /etc/fleet/fleet.conf
metadata="diskType=SSD"
# create the file apache.service
$ cd ~
$ fleetctl submit apache.service
$ fleetctl list-units
# its going to pull the container first
$ fleetctl start apache.service
$ fleetctl status apache.service
$ fleetctl journal apache.service
# see its a docker container!
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0fcee3ab621d coreos/apache:latest /usr/sbin/apache2ctl 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp apache1
# check if it works
$ curl 127.0.0.1
<html><body><h1>It works!</h1>
<p>This is the default web page for this server.</p>
<p>The web server software is running but no content has been added, yet.</p>
</body></html>
By Matrix AI
Lightning Talk about systemd & Core OS's fleet