Jahr: 2016

Pfsense 2.2 mit Check_MK Agent

Seit Pfsense 2.2 funkioniert das Plugin für den Check_MK Agent nicht mehr, da bei FreeBSD die Bash entfernt wurde.

1. Inet Daemon erstellen

1.1. Datei /etc/rc.d/inetd erstellen

1.2. Quellecode einfügen

#!/bin/sh
#
# $FreeBSD$
#
 
# PROVIDE: inetd
# REQUIRE: DAEMON LOGIN cleanvar
# KEYWORD: shutdown
 
. /etc/rc.subr
 
name="inetd"
rcvar="inetd_enable"
command="/usr/sbin/${name}"
pidfile="/var/run/${name}.pid"
required_files="/etc/${name}.conf"
extra_commands="reload"
 
load_rc_config $name
run_rc_command "$1"

1.3. Ausführerechte ändern

chmod +x /etc/rc.d/inetd

1.4. Starten

/etc/rc.d/inetd start

2. Check_MK Agenten ersetzen

2.1 Quellcode ersetzen in Datei /usr/local/bin/check_mk_agent

2.2 Restart daemon

# service inetd restart

#!/bin/sh
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.
 
# Author: Lars Michelsen <lm@mathias-kettner.de>
#         Florian Heigl <florian.heigl@gmail.com>
#           (Added sections: df mount mem netctr ipmitool)
 
# NOTE: This agent has beed adapted from the Check_MK linux agent.
#       The most sections are commented out at the moment because
#       they have not been ported yet. We will try to adapt most
#       sections to print out the same output as the linux agent so
#       that the current checks can be used.
 
# This might be a good source as description of sysctl output:
# http://people.freebsd.org/~hmp/utilities/satbl/_sysctl.html
 
# Remove locale settings to eliminate localized outputs where possible
export LC_ALL=C
unset LANG
 
export MK_LIBDIR="/usr/lib/check_mk_agent"
export MK_CONFDIR="/etc/check_mk"
export MK_TMPDIR="/var/run/check_mk"
 
 
# Make sure, locally installed binaries are found
PATH=$PATH:/usr/local/bin
 
# All executables in PLUGINSDIR will simply be executed and their
# ouput appended to the output of the agent. Plugins define their own
# sections and must output headers with '<<<' and '>>>'
PLUGINSDIR=$MK_LIBDIR/plugins
 
# All executables in LOCALDIR will by executabled and their
# output inserted into the section <<<local>>>. Please refer
# to online documentation for details.
LOCALDIR=$MK_LIBDIR/local
 
 
# close standard input (for security reasons) and stderr
#if [ "$1" = -d ]
#then
#    set -xv
#else
#    exec </dev/null 2>/dev/null
#fi
 
# Runs a command asynchronous by use of a cache file
 
echo '<<<check_mk>>>'
echo Version: 1.2.7i1
echo AgentOS: freebsd
 
 
 
osver="$(uname -r)"
is_jailed="$(sysctl -n security.jail.jailed)"
 
 
# Partitionen (-P verhindert Zeilenumbruch bei langen Mountpunkten)
# Achtung: NFS-Mounts werden grundsaetzlich ausgeblendet, um
# Haenger zu vermeiden. Diese sollten ohnehin besser auf dem
# Server, als auf dem Client ueberwacht werden.
 
echo '<<<df>>>'
# no special zfs handling so far, the ZFS.pools plugin has been tested to
# work on FreeBSD
if df -T > /dev/null ; then
    df -kTP -t ufs | egrep -v '(Filesystem|devfs|procfs|fdescfs|basejail)'
else
    df -kP -t ufs | egrep -v '(Filesystem|devfs|procfs|fdescfs|basejail)' | awk '{ print $1,"ufs",$2,$3,$4,$5,$6 }'
fi
 
# Check NFS mounts by accessing them with stat -f (System
# call statfs()). If this lasts more then 2 seconds we
# consider it as hanging. We need waitmax.
#if type waitmax >/dev/null
#then
#    STAT_VERSION=$(stat --version | head -1 | cut -d" " -f4)
#    STAT_BROKE="5.3.0"
#
#    echo '<<<nfsmounts>>>'
#    sed -n '/ nfs /s/[^ ]* \([^ ]*\) .*/\1/p' < /proc/mounts |
#        while read MP
#  do
#   if [ $STAT_VERSION != $STAT_BROKE ]; then
#      waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" || \
#    echo "$MP hanging 0 0 0 0"
#   else
#      waitmax -s 9 2 stat -f -c "$MP ok %b %f %a %s" "$MP" && \
#      printf '\n'|| echo "$MP hanging 0 0 0 0"
#   fi
#  done
#fi
 
# Check mount options.
# FreeBSD doesn't do remount-ro on errors, but the users might consider
# security related mount options more important.
echo '<<<mounts>>>'
mount -p -t ufs
 
# processes including username, without kernel processes
echo '<<<ps>>>'
COLUMNS=10000
if [ is_jailed = 0 ]; then
    ps ax -o state,user,vsz,rss,pcpu,command | sed -e 1d  -e '/\([^ ]*J\) */d' -e 's/*\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\2,\3,\4,\5) /'
else
    ps ax -o user,vsz,rss,pcpu,command | sed -e 1d -e 's/ *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\1,\2,\3,\4) /'
fi
 
 
# Produce compatible load/cpu output to linux agent. Not so easy here.
echo '<<<cpu>>>'
echo `sysctl -n vm.loadavg | tr -d '{}'` `top -b -n 1 | grep -E '^[0-9]+ processes' | awk '{print $3"/"$1}'` `sysctl -n kern.lastpid` `sysctl -n hw.ncpu`
 
# Calculate the uptime in seconds since epoch compatible to /proc/uptime in linux
echo '<<<uptime>>>'
  up_seconds=$(( `date +%s` - `sysctl -n kern.boottime  | cut -f1 -d\, | awk '{print $4}'`))
idle_seconds=$(ps axw | grep idle | grep -v grep | awk '{print $4}' | cut -f1 -d\: )
 
# second value can be grabbed from "idle" process cpu time / num_cores
echo "$idle_seconds $up_seconds"
 
 
# Platten- und RAID-Status von LSI-Controlleren, falls vorhanden
#if which cfggen > /dev/null ; then
#   echo '<<<lsi>>>'
#   cfggen 0 DISPLAY | egrep '(Target ID|State|Volume ID|Status of volume)[[:space:]]*:' | sed -e 's/ *//g' -e 's/:/ /'
#fi
 
 
# Multipathing is supported in FreeBSD by now
# http://www.mywushublog.com/2010/06/freebsd-and-multipath/
if kldstat -v | grep g_multipath > /dev/null ; then
    echo '<<<freebsd_multipath>>>'
    gmultipath status | grep -v ^Name
fi
 
 
# Soft-RAID
echo '<<<freebsd_geom_mirrors>>>'
gmirror status | grep -v ^Name
 
# Performancecounter Kernel
echo "<<<kernel>>>"
date +%s
forks=`sysctl -n vm.stats.vm.v_forks`
vforks=`sysctl -n vm.stats.vm.v_vforks`
rforks=`sysctl -n vm.stats.vm.v_rforks`
kthreads=`sysctl -n vm.stats.vm.v_kthreads`
echo "cpu" `sysctl -n kern.cp_time | awk ' { print $1" "$2" "$3" "$5" "$4 } '`
echo "ctxt" `sysctl -n vm.stats.sys.v_swtch`
echo "processes" `expr $forks + $vforks + $rforks + $kthreads`
 
# Network device statistics (Packets, Collisions, etc)
# only the "Link/Num" interface has all counters.
echo '<<<lnx_if:sep(58)>>>'
date +%s
if [ "$(echo $osver | cut -f1 -d\. )" -gt "8" ]; then
    netstat -inb | egrep -v '(^Name|plip|enc|pfsync|pflog|ovpns)' | grep Link | awk '{print"\t"$1":\t"$8"\t"$5"\t"$6"\t"$7"\t0\t0\t0\t0\t"$11"\t"$9"\t"$10"\t0\t0\t0\t0\t0"}'
else
    # pad output for freebsd 7 and before
    netstat -inb | egrep -v '(^Name|lo|plip)' | grep Link | awk '{print $1" "$7" "$5" "$6" 0 0 0 0 0 "$10" "$8" "$9" 0 0 "$11" 0 0"}'
fi
 
 
# State of LSI MegaRAID controller via MegaCli.
# To install: pkg install megacli
if which MegaCli >/dev/null ; then
    echo '<<<megaraid_pdisks>>>'
    MegaCli -PDList -aALL -NoLog < /dev/null | egrep 'Enclosure|Raw Size|Slot Number|Device Id|Firmware state|Inquiry'
    echo '<<<megaraid_ldisks>>>'
    MegaCli -LDInfo -Lall -aALL -NoLog < /dev/null | egrep 'Size|State|Number|Adapter|Virtual'
    echo '<<<megaraid_bbu>>>'
    MegaCli -AdpBbuCmd -GetBbuStatus -aALL -NoLog < /dev/null | grep -v Exit
fi
 
 
# OpenVPN Clients. 
# Correct log location unknown, sed call might also be broken
if [ -e /var/log/openvpn/openvpn-status.log ] ; then
    echo '<<<openvpn_clients:sep(44)>>>'
    sed -n -e '/CLIENT LIST/,/ROUTING TABLE/p' < /var/log/openvpn/openvpn-status.log  | sed -e 1,3d -e '$d' 
fi
 
 
if which ntpq > /dev/null 2>&1 ; then
   echo '<<<ntp>>>'
   # remote heading, make first column space separated
   ntpq -np | sed -e 1,2d -e 's/^\(.\)/\1 /' -e 's/^ /%/'
fi
 
 
# Checks for cups monitoring
#if which lpstat > /dev/null 2>&1; then
#  echo '<<<cups_queues>>>'
#  lpstat -p
#  echo '---'
#  for i in $(lpstat -p | grep -E "^(printer|Drucker)" | awk '{print $2}' | grep -v "@"); do
#    lpstat -o "$i"
#  done
#fi
 
# Heartbeat monitoring
#if which cl_status > /dev/null 2>&1; then
#  # Different handling for heartbeat clusters with and without CRM
#  # for the resource state
#  if [ -S /var/run/heartbeat/crm/cib_ro ]; then
#    echo '<<<heartbeat_crm>>>'
#    crm_mon -1 -r | grep -v ^$ | sed 's/^\s/_/g'
#  else
#    echo '<<<heartbeat_rscstatus>>>'
#    cl_status rscstatus
#  fi
#
#  echo '<<<heartbeat_nodes>>>'
#  for NODE in $(cl_status listnodes); do
#    if [ $NODE != $HOSTNAME ]; then
#      STATUS=$(cl_status nodestatus $NODE)
#      echo -n "$NODE $STATUS"
#      for LINK in $(cl_status listhblinks $NODE 2>/dev/null); do
#        echo -n " $LINK $(cl_status hblinkstatus $NODE $LINK)"
#      done
#      echo
#    fi
#  done
#fi
 
# Number of TCP connections in the various states
echo '<<<tcp_conn_stats>>>'
netstat -na | awk ' /^tcp/ { c[$6]++; } END { for (x in c) { print x, c[x]; } }'
 
 
# Postfix mailqueue monitoring
#
# Only handle mailq when postfix user is present. The mailq command is also
# available when postfix is not installed. But it produces different outputs
# which are not handled by the check at the moment. So try to filter out the
# systems not using postfix by searching for the postfix user.
#
# Cannot take the whole outout. This could produce several MB of agent output
# on blocking queues.
# Only handle the last 6 lines (includes the summary line at the bottom and
# the last message in the queue. The last message is not used at the moment
# but it could be used to get the timestamp of the last message.
#if which mailq >/dev/null 2>&1 && getent passwd postfix >/dev/null 2>&1; then
#  echo '<<<postfix_mailq>>>'
#  mailq | tail -n 6
#fi
 
#Check status of qmail mailqueue
#if type qmail-qstat >/dev/null
#then
#   echo "<<<qmail_stats>>>"
#   qmail-qstat
#fi
 
# check zpool status
#if [ -x /sbin/zpool ]; then
#   echo "<<<zpool_status>>>"
#   /sbin/zpool status -x | grep -v "errors: No known data errors"
#fi
 
# Memory Usage
# currently we'll need sysutils/muse for this.
if [ -x /usr/local/bin/muse ]
then
echo '<<<mem>>>'
# yes, i don't know sed well.
muse -k 2>/dev/null | sed 's/Total/MemTotal/' | sed 's/Free/MemFree/'
swapinfo -k 1K | tail -n 1 | awk '{ print "SwapTotal: "$2" kB\nSwapFree: "$4" kB" }'
fi
 
 
 
# Fileinfo-Check: put patterns for files into /etc/check_mk/fileinfo.cfg
if [ -r "$MK_CONFDIR/fileinfo.cfg" ] ; then
    echo '<<<fileinfo:sep(124)>>>'
    date +%s
    stat -f "%N|%z|%m" $(cat "$MK_CONFDIR/fileinfo.cfg")
fi

Systemd – Journal beschränken

Das Journal wurde mit Systemd neu eingeführt und soll die Log-Dateien /var/log/syslog ersetzen. Die Daten werden in Form von Binärdaten gespeichert und nicht in ASCII Format.

Um den Speicherplatz zu prüfen kann man das Journal Control journalctl verwenden.

journalctl --disk-usage

Will man den Speicherplatz reduzieren, kann man den Speicherplatz angeben oder die Zeit. Alte Einträge werden dann bereinigt.

journalctl --vacuum-size=128M
journalctl --vacuum-time=4weeks

Will man den Speicherplatz dauerhaft begrenzen, so kann einen Eintrag in der Kondiguration hinzu gefügen.

sudo vim /etc/systemd/journald.conf

Storage=auto
SystemMaxUse=128M

sudo systemctl restart systemd-journald

Der Speicherort von Journal liegt im Verzeichnis /run/log/journal/[UUID]/. Die Dateien werden im Binärformat gespeichert und können nicht mit einem Editor geöffnet werden. Mit dem Befehl „strings“ ist es möglich die Daten zu lesen.

sudo apt-get install binutils
strings /run/log/journal/[UUID]/system.journal

Nach jedem Neustart wird Journal gelöscht. Will man das Journal behalten, erstellt man eine Verzeichnis.

sudo mkdir -p /var/log/journal/

Nach einem Neustart wird das Journal im Verzeichnis /var/log/journal/ gespeichert. Wenn das Verzeichnis gelöscht wird, dann wird es wieder nach jedem Neustart gelöscht.

sudo rm -r /var/log/journal/

Die Anzahl der Neustart kann man sich anzeigen lassen.

journalctl --list-boots

Schutz vor Brute-Force Angriffen

Mit dem Tool „fail2ban“ kann man Brute-Force Angriffe abwähren. Dabei wird die IP Adresse der Angreifer aus den Log-Dateien ermittelt und in der Firewall (iptable) gesperrt.

Die Installation aus dem Ubuntu Repositories erfolgt mit.

sudo apt-get install fail2ban

Nach der Installation ist der Schutz von SSH automatisch aktiviert.

sudo vim /etc/fail2ban/jail.conf

[DEFAULT]
# "ignoreip" can be an IP address, a CIDR mask or a DNS host
ignoreip = 127.0.0.1 192.168.178.0/24 office.example.de
bantime  = 1800
maxretry = 3
 
[ssh]
enabled = true
port    = ssh
filter  = sshd
logpath  = /var/log/auth.log
maxretry = 3
 
[apache]
enabled  = true
port     = http,https
filter   = apache-auth
logpath  = /var/log/apache*/*error.log
maxretry = 6

Nach Änderungen muß der Dienst neu gestartet werden.

sudo service fail2ban restart

Eine Kontrolle der Firewall (iptables) erfolgt mit diesem Kommando. Einträge werden in dem Chain „fail2ban“ hinterlegt.

sudo iptables -L

Das Tool fail2ban-client zeigt die Jails an.

sudo fail2ban-client status
sudo fail2ban-client status apache

Sperre für eine IP Adresse wieder aufheben.

sudo fail2ban-client set apache unbanip 123.123.123.123

Netzwerkübersicht von offenen Ports

Wer wissen will, welche Netzwerkanfragen auf dem System lauschen, kann den Befehl lsof verwenden.

Das Kommando kann aus dem Ubuntu Repository installiert werden.

sudo apt-get install lsof

Mit dem Parameter -i kann man sich einen Port anzeigen lassen.

sudo lsof -i [udp|tcp]:[port]
sudo lsof -i tcp:80

Der Parameter +d liste die offenen Files aus dem Verzeichnis.

sudo lsof +d /var/log/

Der Parameter -c / -p liste die offenen Files von einem Prozess.

sudo lsof -c apache2
sudo lsof -p 1234

Der Parameter -u liste die offenen Files von einem Benutzer.

sudo lsof -u otto

Eine andere Alternative ist das Tool netstat. Der Parameter „-l“ zeigt die offenen Ports an und Parameter „-a“ alle Verbindungen.

netstat -nlp

SSH Guard schütz vor Brute-Force Angriffen

Der SSH-Guard hilft Ihnen beim Schutz vor Brute-Force Angriffen auf den SSH Port. Dabei wird die Log-Datei „/var/log/auth.log“ überwacht und bei falschen Anmeldeversuchen wird die Remote IP-Adresse mit der Firewall (iptables) gesperrt.

Installation aus dem Ubuntu Repo.

sudo apt-get install sshguard

Nach der Installation werden folgende Einstellung in der Firewall iptables vorgenommen.

Erzeugen eines neuen Chain für SSH-Guard.

sudo iptables -N sshguard
sudo ip6tables -N sshguard

Jeder Netzwerkverkehr wird über diesen Chain geführt.

sudo iptables -A INPUT -j sshguard
sudo ip6tables -A INPUT -j sshguard

Der SSH-Guard wird als Dienst gestartet.

sudo service sshguard start

Ein Test mit falschen SSH Login solltem in der Firewall iptables einen neue Eintrag mit „DROP“ enthalten.

sudo iptables -L -v

Eine Whitelist wurde nach der Installation auch erstellt.

sudo vim /etc/sshguard/whitelist

10.0.0.0/8
192.168.178.0/24
office.example.de

Docker update Guacamole image

1. Update Guacamole images

sudo docker pull glyptodon/guacd:latest
sudo docker pull glyptodon/guacamole:latest

2. Remove old container

sudo docker rm some-guacd
sudo docker rm some-guacamole

3. Recreate new Guacamole container

sudo docker run --name some-guacd -d -p 4822:4822 glyptodon/guacd

sudo docker run --name some-guacamole --link some-guacd:guacd \
--link some-mysql:mysql \
-e MYSQL_DATABASE=guacamole_db \
-e MYSQL_USER=guacamole_user \
-e MYSQL_PASSWORD=some_password \
-d -p 8080:8080 glyptodon/guacamole

4. Copy the SQL update script from Guacamole container to host

docker cp some-guacamole:/opt/guacamole/mysql/schema/upgrade/upgrade-pre-0.9.8.sql .

5. Copy it into Docker MySQL container directory /tmp/

docker cp upgrade-pre-0.9.8.sql some-mysql:/tmp

6. Go into Docker MySQL container and import it into database

sudo docker exec -it some-mysql bash
mysql -u root -p guacamole_db < /tmp/upgrade-pre-0.9.8.sql

Weitere Informationen für die Installation: guac-dev.org/doc/

NTP Konfigurieren

Das Network Time Protocol (NTP) erlaubt es, das Datum und die Uhrzeit von dem System mit dem Internet zu synchronisieren. Für die Kommunikation wird UDP auf Port 123 verwendet. Der permanente Abgleich von Datum und Uhrzeit erfolgt mit einem NTP Dienst.

Die Installation erfolgt mit dem Befehl.

sudo apt-get install ntp

Der erste Abgleich kann mit dem Befehl ntpdate erfolgen. Eine Liste von NTP Servern findet man auf der Seite von www.pool.ntp.org.

ntpdate de.pool.ntp.org

Die Einstellungen für den NTP Dienst kann man so ändern.

sudo vim /etc/ntp.conf

server 0.de.pool.ntp.org
server 1.de.pool.ntp.org
server 2.de.pool.ntp.org
server 3.de.pool.ntp.org

Der NTP Dienst wird gestartet mit dem Befehl.

sudo service ntp start
sudo service ntp status

Die Serverliste kann man ausgeben mit dem Befehl.

ntpq -p

Systemd verwendet einen eigenen NTP Dienst.

timedatectl status

Sollte NTP nicht aktiviert sein, so kann man die Einstellung ändern.

sudo vim /etc/systemd/timesyncd.conf

[Time]
Servers=0.de.pool.ntp.org 1.de.pool.ntp.org

Nach der Aktivierung sollte NTP aktiv und synchronisiert sein.

sudo timedatectl set-ntp true
sudo timedatectl status

Mail von Kommandozeile versenden

Wie kann ich eine E-Mail von der Kommandozeile versenden?

Zu erst installieren wir die Mail-Util’s.

sudo apt-get install mailutils

Und jetzt kann man schon eine E-Mail versenden.

mail -s "Betreff" recipient@domain.de < nachricht.txt

echo "Nachricht" | mail -a "From: you@example.com" -s "Betreff" recipient@domain.de

Oder mit Sendmail.

sendmail recipient@domain.de
From: you@example.com
Subject: Betreff
Nachricht
.

Sollte die Email beim Empfänger nicht an kommen, muss man die Einstellung von Postfix oder Exim noch einmal prüfen.

sudo dpkg-reconfigure postfix

sudo dpkg-reconfigure exim4-config

Will man die Kommunikation von SMTP selbst mal probieren, so kann man per Telnet auch eine E-Mail senden.

telnet mail.domain.de 25

HELO <senderhostname.de>
EHLO <senderhostname.de>
MAIL FROM:<you@example.com>
RCPT TO:<recipient@domain.de>
DATA
Subject: Test email
 
Body of the email
.
QUIT

Heute sollte die Kommunikation zum SMTP Server nicht mehr unverschlüsselt statt finden. Für die Verschlüsslung werden SSL Zertifikat verwendet.

Mit OpenSSL kann man das Zertifikat von dem SMTP Server überprüfen.

openssl s_client -connect : -servername [-starttls ]

Die Umschaltung auf verschlüsselt Übertragung erfolgt per STARTTLS. Mögliche Werte sind (smtp, pop3, imap).

Hier ein Beispiel für SMTP.

openssl s_client -connect example.com:25 -servername example.com -starttls smtp

Wenn man nur das Zertifikat überprüfen will, geht es auch so.

openssl s_client -connect example.com:25 -starttls smtp -showcerts | openssl x509 -text

Hier eine Liste der Ports für E-Mail Kommunikation.

  • 25 SMTP Empfangen von E-Mails von anderen Mailservern
  • 465 SMTP SSL Client E-Mail Übertragung
  • 587 SMTP TLS Client E-Mail Übertragung
  • 143 IMAP StartTLS Client
  • 993 IMAP TLS/SSL Client
  • 110 POP3 Client
  • 995 POP3 TLS/SSL Client

Ubuntu Systemd Dienst entfernen

Diese Anweisungen müssen Sie durchführen, um einen Dienst aus Systemd zu entfernen.

sudo systemctl stop [name.service]
sudo systemctl disable [name.service]
sudo rm /etc/systemd/system/[name.service]
sudo systemctl daemon-reload
sudo systemctl reset-failed

Ubuntu Dienst Systemd

Ubuntu hat einen Wechseln von Upstart zu SystemD durchgeführt. Für Systemd gibt es einige neue Tools für die Verwaltung der Dienste.

Um eine Übersicht über alle Dienste zu erhalten können Sie diese Option verwenden.

sudo systemctl -all

Um einen Dienst zu start oder stoppen können Sie diese Befehle verwenden.

sudo systemctl start [name.service]
sudo systemctl stop [name.service]
sudo systemctl restart [name.service]
sudo systemctl reload [name.service]
sudo systemctl status [name.service]

Eine neue Funktion von Systemd ist der Timer, mit deren Hilfe kann man Aufgaben automatisieren.

sudo vim /etc/systemd/system/backup.service

[Unit]
Description=Backup
[Service]
ExecStart=/home/user/backup.sh

Der Timer startet den Dienst immer jeden Tag um 2:15 Uhr.

sudo vim /etc/systemd/system/backup.timer

[Unit]
Description=beispiel timer
[Timer]
OnCalendar=02:15
OnUnitInactiveSec=1d

Hiermit starten Sie den Timer.

sudo service systemctl start backup.timer
sudo systemctl list-timers --all
sudo systemctl enable backup.timer
sudo systemctl disable backup.timer
sudo systemctl --failed

Alle Informationen zu Diensten erhalten Sie im Journal.

journalctl --reverse
journalctl --follow
journalctl --unit backup.timer

Mit den Analyze-Tool kann man sich den Startvorgang in einer SVG-Grafikdatei ausgeben lassen.

systemd-analyze plot > /tmp/plot.svg

Copyright © 2025 Weiter.info

Theme von Anders Norén↑ ↑