284 lines
6.2 KiB
Plaintext
Executable File
284 lines
6.2 KiB
Plaintext
Executable File
#create Unit
|
|
systemctl edit --full --force vmstatd.service
|
|
|
|
#systemd-nspawn
|
|
systemd-nspawn -D /var/lib/machine/rocky7 -b
|
|
|
|
machinectl str+altGr+9
|
|
|
|
/var/lib/machines/rocky7
|
|
|
|
[Unit]
|
|
Description=vmstat as daemon
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=/usr/bin/vmstat $VMSTAT_OPTS 3
|
|
EnvironmentFile=-/etc/default/vmstatd
|
|
StandardOutput=append:/var/log/vmstat.log
|
|
|
|
/etc/default/vmstatd
|
|
VMSTAT_OPTS=-ntw
|
|
VMSTAT_DELAY=3
|
|
VMSTAT_LOG=/var/log/vmstat.log
|
|
#########Unit aufbau
|
|
# Unit ist immer vorhanden
|
|
[Unit]
|
|
Description=Freie Beschreibung
|
|
Documentation=Bezug zu Dok Quellen
|
|
# Reihenfolge (keine Abhängigkeiten)
|
|
# systemd ist egozentrisch
|
|
After=diese Units mögen bitte vorher gestartet werden
|
|
Before=diese Unit möge bitte vor den hier genannten gestartet werden
|
|
# Abhängigkeiten
|
|
Wants=diese Units werden mit dieser Unit gestartet.
|
|
Require=diese Units werden benötigt und werden mit dieser Unit gestartet. Ausfall führt zu einem Fehler.
|
|
|
|
# targets bestehen i.d.R. nur aus der [Unit]-Sektion
|
|
|
|
#Typ des Unitfiles
|
|
#Hier stehen Anweisungen, die spezifisch für die Unit sind.\\
|
|
#Dokumentation unter ''man systemd.<unit type>''
|
|
[Service]
|
|
ExecStart=/usr/bin/daemond --param arg
|
|
|
|
# Restart-Logik. Watchdog-Funktionen
|
|
Restart=on-failure
|
|
RestartSec=5
|
|
|
|
# kann entfallen, dann ist das Unit static und kann nicht enabled/disabled werden
|
|
[Install]
|
|
# Rückwärts-Abhängigkeiten
|
|
WantedBy=multi-user.target
|
|
RequiredBy=
|
|
#####################
|
|
###############################
|
|
#oneShort beispiel
|
|
#vorbereitung
|
|
cp -a /usr/share/doc /usr/share/doc2
|
|
#Unit
|
|
systemctl edit --full --force my_oneshot
|
|
[Unit]
|
|
Description=tar/untar doc2
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
ExecStart=/usr/bin/tar -czf /usr/share/doc2.tgz /usr/share/doc2
|
|
ExecStart=/usr/bin/rm -r /usr/share/doc2
|
|
|
|
ExecStop=/usr/bin/tar -xvzf /usr/share/doc2.tgz
|
|
ExecStop=/bin/rm /usr/share/doc2.tgz
|
|
RemainAfterExit=yes
|
|
|
|
####################
|
|
#typen
|
|
#
|
|
#simple
|
|
#oneshot
|
|
#always
|
|
#
|
|
#
|
|
#Ubunut optimieren
|
|
#rm /etc/iniramfs-tools/conf.d/resume
|
|
#update-initramfs -k all -u
|
|
#
|
|
#
|
|
systemd-cgtop besser als top
|
|
|
|
###############Unit mit Multiparameter
|
|
#
|
|
#Vorbereitung
|
|
/etc/default/vmstatd
|
|
VMOPTS=-ntw
|
|
VMLOG=/var/tmp/vmstatd.log
|
|
VMDELAY=10
|
|
#VMCOUNT=
|
|
# Unit
|
|
[Unit]
|
|
Description=VMStat Daemon
|
|
StartLimitIntervalSec=2 min
|
|
StartLimitBurst=3
|
|
OnFailure=trig.service
|
|
|
|
[Service]
|
|
Restart=on-failure
|
|
RestartSec=20
|
|
RestartForceExitStatus=SIGHUP
|
|
EnvironmentFile=/etc/default/vmstatd
|
|
ExecStart=/bin/sh -c "exec /usr/bin/vmstat $VMOPTS $VMDELAY $VMCOUNT >> $VMLOG"
|
|
########################
|
|
#Namespace
|
|
# Beispiel mit ip
|
|
#Namespace erzeugen
|
|
ls -l /proc/self/ns
|
|
ip netns add ns1
|
|
ip netns exec ns1 /bin/bash
|
|
ip l
|
|
ip a
|
|
exit
|
|
ip netns pids ns1
|
|
ls -l /run/netns
|
|
ip netns del ns1
|
|
|
|
#veth (virtuelles Netzwerkkabel)
|
|
#Shell isolieren
|
|
ip link add name veth1 type veth peer name veth2
|
|
ip l
|
|
ip netns add ns1
|
|
ip link set dev veth2 netns ns1
|
|
ip l set dev veth1 up
|
|
ip addr change 172.16.0.1/16 dev veth1
|
|
ip netns exec ns1 ip l set dev veth2 up
|
|
ip netns exec ns1 ip addr change 172.16.0.2/16 dev veth2
|
|
ping 172.16.0.2
|
|
ip netns exec ns1 /bin/bash
|
|
ip a
|
|
ip r
|
|
ping 172.16.0.1
|
|
ip l del dev veth1
|
|
ip netns del ns1
|
|
|
|
#isolierter ssh-Server
|
|
#Zwei Fenster, z.B. in tmux, links=server, rechts=client
|
|
|
|
ip link add name vethsrv0 type veth peer name vethcli0
|
|
ip netns add srv
|
|
ip netns add cli
|
|
ip link set vethsrv0 netns srv
|
|
ip link set vethcli0 netns cli
|
|
ip l
|
|
|
|
#Server (links)
|
|
ip netns exec srv /bin/bash
|
|
ip link set up dev vethsrv0
|
|
ip addr change 10.9.8.7/24 dev vethsrv0
|
|
|
|
#SSH Server starten
|
|
/sbin/sshd -dD
|
|
|
|
#Client (rechts)
|
|
ip netns exec cli /bin/bash
|
|
ip link set up dev vethcli0
|
|
ip addr change 10.9.8.6/24 dev vethcli0
|
|
|
|
#Connect
|
|
ip a
|
|
ssh 10.9.8.7
|
|
ip a
|
|
exit
|
|
####################################
|
|
#Capipilitäts
|
|
# cat /bin/ping > /usr/local/bin/PING
|
|
# chmod +x /usr/local/bin/PING
|
|
$ PING 9.9.9.9 # geht nicht
|
|
# setcap cap_net_raw=p /usr/local/bin/PING
|
|
$ PING 9.9.9.9 # geht
|
|
|
|
$ getpcap <pid>
|
|
$ grep ^Cap /proc/<pid>/status
|
|
$ /usr/sbin/capsh --decode=0x00003f
|
|
|
|
#Auf einer anderen Shell
|
|
$ strace -e trace=%creds -ff -p <pid der Shell>
|
|
|
|
#Auf der ping Shell
|
|
$ PING -c 3 9.9.9.9
|
|
#BoundingSet
|
|
capsh --drop=cap_chown,cap_net_raw --
|
|
chown nutzer /tmp
|
|
cd /proc/self
|
|
grep ^Cap status
|
|
exit
|
|
cd /proc/self
|
|
grep ^Cap status
|
|
##CPU set property
|
|
systemctl set-property cups.service CPUWeight=33
|
|
##show
|
|
systemctl show cups.service -p CPUWeight
|
|
# Geht auch mit Quota=100 CPUQuota=100%
|
|
# Run Unit mit cgroups
|
|
systemd-run --unit <name> -p CPUQuota=40% <process-name beispiel stress-ng --cpu 8>
|
|
# mit cat kann auch schnell ein template generieren
|
|
systemctl cat <name>
|
|
# mit angaben --unit kann ich die bestehende steueren
|
|
# [Unit] mit abhängigkeiten
|
|
# Requires muss in der HauptUnit angeben werden
|
|
# PartOf muss in der ReqUnit angeben werden (Kind lässt sich alleine Starten)
|
|
####Anders
|
|
#in der Main Unit mit Wants
|
|
#
|
|
|
|
[Unit]
|
|
Description=CPU Stress
|
|
#Requires=vmstress.service
|
|
#Wants=vmstress.service
|
|
#After=vmstress.service
|
|
Befor=vmstress.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
CPUQuota=4%
|
|
ExecStart=/usr/bin/stress-ng --cpu 4
|
|
|
|
[Install]
|
|
WantedBy=my.target
|
|
##################################
|
|
#Templating wird mit @ gespeichert
|
|
[Unit]
|
|
Description=%i Stress as a Service
|
|
|
|
[Service]
|
|
Type=simple
|
|
CPUQuota=4%
|
|
KillMode=mixed
|
|
ExecStart=/usr/bin/stress-ng --%i 4
|
|
|
|
[Install]
|
|
WantedBy=my.target
|
|
##Aufruf für cpu
|
|
#
|
|
|
|
systemctl start stress@vm.service
|
|
systemctl start stress@cpu.service
|
|
|
|
#um es ins Filesystem zubekommen muss es enabled werden
|
|
##Unit Baum anzeigen
|
|
systemctl list-dependencies sshd
|
|
###systemctl edit --full pyhttp@.service
|
|
[Unit]
|
|
Description=Start Server in %I
|
|
|
|
[Service]
|
|
Type=simple
|
|
Restart=on-failure
|
|
ExecStart=/usr/bin/python3 -m http.server
|
|
WorkingDirectory=%I
|
|
|
|
ReadOnlyPaths=/var /usr
|
|
InaccessiblePaths=/sys /proc
|
|
##Run systemctl start pyhttp@-var-log.service
|
|
#- wird escaped
|
|
|
|
Liste :
|
|
|
|
Specifier Meaning
|
|
%n %N Full unit name
|
|
%p %P Prefix name (before @ character)
|
|
%i %I Instance name (after @ character)
|
|
%f Unescaped filename
|
|
%c Control group path of the unit (without /sys/fs/cgroup/systemd/)
|
|
%r Control group path of the slice (parent cgroup)
|
|
%R Root control group path (for system instances /)
|
|
%t Runtime directory (/run [system] or „$XDG_RUNTIME_DIR“ [user]
|
|
%u User name
|
|
%U User UID
|
|
%h User home directory
|
|
%s User shell
|
|
%m Machine ID
|
|
%b Boot ID
|
|
%H Host name
|
|
%v Kernel release (uname -r output
|
|
%% Single percent sign
|
|
|
|
für Unit
|