System Administration
Systemd
Systemd is a Linux system and service manager that handles the initialization and management of processes during boot and runtime. It improves boot times, supports parallelization, and offers advanced features like service management and logging, serving as a standard component in modern Linux distributions.
1. Systemd Configuration
Apart from serving as an INIT system, Systemd oversees various aspects within Linux systems. The fundamental component of systemd configuration is termed a “unit,” which is set up using a file written in the systemd configuration language. Notable among the various types of units are:
- Service Units (*.service): Represents a service or application that systemd can start, stop, and manage.
- Socket Units (*.socket): Manages socket-based activation, allowing services to be started on-demand when a socket receives a connection.
- Target Units (*.target): Represents a custom grouping of other units and is used for defining synchronization points or custom system states.
- Mount Units (*.mount): Describes a mount point for a filesystem, specifying the source device, filesystem type, and mount options.
- Path Units (*.path): Monitors files or directories and triggers specified actions when changes occur, such as starting a service.
- Timer Units (*.timer): Defines a timer that can be associated with other units, allowing scheduled or periodic activation of services.
- Device Units (*.device): Represents a device managed by systemd, allowing for dependencies and ordering with other units.
Systemd configuration files can be found in the following directories:
/lib/systemd/system/: System-provided unit files (come with installed packages)./etc/systemd/system/: System-wide unit files (provided by the system administrator)./run/systemd/system/: Temporary runtime unit files.$HOME/.config/systemd/user/: User-specific unit files (managed by users).
2. Systemd Services
Systemd Services are the most used by system administrators. They are used to run long running programs also know as daemons or servers. The services like other unit files are managed using the systemctl utility.
# Most common commands
systemctl start <app.service>
systemctl stop <app.service>
systemctl restart <app.service>
systemctl reload <app.service> # Reload the configuration
systemctl daemon-reload # reread systemd configuration
systemctl enable <app.service>
systemctl disable <app.service>
3. Other Systemd tools and capabilities
Systemd has an entire ecosystem trying to ease all the system management tasks. Amongst the systemd utilities we can find:
systemd-journald: event loggingsystemd-boot: boot loadednetworkd: configuration of the network interfacesresolved: network name resolution to local applicationstimedated: control time-related settings(system time, timezone …)logind: manages user logins and seats
4. Assignment
- Check status of the mysql service and determine the location of the service file
- Open the mysql service file and try to understand its structure.
- Change PID file for mysql process to point to another location.
- Create a script that infinitely prints something and sleeps 3 seconds. Make sure the script is executable.
- Change the apache2 service to point to your script.