# Lab8 Solution Amirlan Sharipov (BS21-CS-01)

## Table of Contents

- 1. Question 1
- 2. Question 2
  - 2.1. Information taken from man pages:
    - 2.1.1. basic.target
    - 2.1.2. graphical.target
    - 2.1.3. multi-user.target
    - 2.1.4. sysinit.target
  - 2.2. Wants for sysinit.target
- 3. Question 3
- 4. Question 4

## 1. Question 1

    systemd-analyze
    systemd-analyze plot > systemd.svg

    Startup finished in 5.093s (firmware) + 122ms (loader) + 7.459s (kernel) + 4.545s (userspace) = 17.221s
    graphical.target reached after 4.544s in userspace.

## 2. Question 2

graphical.target -> multi-user.target -> basic.target -> sysinit.target

    cat /usr/lib/systemd/system/graphical.target
    cat /usr/lib/systemd/system/multi-user.target
    cat /usr/lib/systemd/system/basic.target
    cat /usr/lib/systemd/system/sysinit.target

    #  SPDX-License-Identifier: LGPL-2.1-or-later
    #
    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.

    [Unit]
    Description=Graphical Interface
    Documentation=man:systemd.special(7)
    Requires=multi-user.target
    Wants=display-manager.service
    Conflicts=rescue.service rescue.target
    After=multi-user.target rescue.service rescue.target display-manager.service
    AllowIsolate=yes
    #  SPDX-License-Identifier: LGPL-2.1-or-later
    #
    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.

    [Unit]
    Description=Multi-User System
    Documentation=man:systemd.special(7)
    Requires=basic.target
    Conflicts=rescue.service rescue.target
    After=basic.target rescue.service rescue.target
    AllowIsolate=yes
    #  SPDX-License-Identifier: LGPL-2.1-or-later
    #
    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.

    [Unit]
    Description=Basic System
    Documentation=man:systemd.special(7)
    Requires=sysinit.target
    Wants=sockets.target timers.target paths.target slices.target
    After=sysinit.target sockets.target paths.target slices.target tmp.mount

    # We support /var, /tmp, /var/tmp, being on NFS, but we don't pull in
    # remote-fs.target by default, hence pull them in explicitly here. Note that we
    # require /var and /var/tmp, but only add a Wants= type dependency on /tmp, as
    # we support that unit being masked, and this should not be considered an error.
    RequiresMountsFor=/var /var/tmp
    Wants=tmp.mount
    #  SPDX-License-Identifier: LGPL-2.1-or-later
    #
    #  This file is part of systemd.
    #
    #  systemd is free software; you can redistribute it and/or modify it
    #  under the terms of the GNU Lesser General Public License as published by
    #  the Free Software Foundation; either version 2.1 of the License, or
    #  (at your option) any later version.

    [Unit]
    Description=System Initialization
    Documentation=man:systemd.special(7)

    Wants=local-fs.target swap.target
    After=local-fs.target swap.target
    Conflicts=emergency.service emergency.target
    Before=emergency.service emergency.target

### 2.1. Information taken from man pages:

#### 2.1.1. basic.target

A special target unit covering basic boot-up.

#### 2.1.2. graphical.target

A special target unit for setting up a graphical login screen. This pulls in multi-user.target.

#### 2.1.3. multi-user.target

A special target unit for setting up a multi-user system (non-graphical). This is pulled in by graphical.target.

#### 2.1.4. sysinit.target

This target pulls in the services required for system initialization.

### 2.2. Wants for sysinit.target

Wants=local-fs.target swap.target Wants is used like Requires, but it’s less strict, meaning that it can start if the “wanted” service doesn’t exist or failed to start. In this case, it wants local filesystems and swap to start.

## 3. Question 3

    cat webserver.sh

    #!/bin/bash

    while true ; do
        STATS="<h1>Uptime</h1>$(uptime)\n<h1>Inode and disk usage</h1>$(df -ih)\n<h1>Mem usage</h1>$(free -h)\n<h1>Syslog</h1>$(tail -n 15 /var/log/syslog)\r\n\r\n"
        LEN=$(printf "%s" "$STATS" | wc -c)
        RES="HTTP/1.1 200OK\r\nContent-Length: $LEN\r\n\r\n"
        echo -e "$RES$STATS"| nc -l -p 1500;
    done

[Unit] Description=stats web server

[Service] User=root ExecStart=/home/rinri/edu/sna/webserver.sh Restart=always CPUQuota=15% MemoryMax=256000000

[Install] WantedBy=multi-user.target

## 4. Question 4

    cat update.sh

    #!/bin/bash

    pacman -Sy

[Unit] Description=update package sources list

[Service] User=root ExecStart=/home/rinri/edu/sna/update.sh

[Install] WantedBy=multi-user.target

Author: Amirlan Sharipov (BS21-CS-01)

Created: 2023-03-23 Thu 23:57