Skip to content

Latest commit

 

History

History
175 lines (139 loc) · 2.49 KB

05.md

File metadata and controls

175 lines (139 loc) · 2.49 KB

5 EXERCISE

17.10.2017

System D & System V

exercise #1

  1. Create unit file which will write "Hello!" into file located at /tmp/hello after executing.

Create a script.

touch /tmp/hello-script

Write this to the script.

#!/usr/bin/bash
echo "HELLO" >> /tmp/hello

Change file mode bits.

chmod +x /tmp/hello-script

Create a unit file.

touch /etc/systemd/system/hello.service

Write this to the unit file.

[Unit]
Description=Baz Service

[Service]
Type=simple
ExecStart=/tmp/hello-script
StandardError=journal
TimeoutStopSec=5

Start the service.

systemctl start hello.socket
systemctl status hello.socket

Verify it.

cat /tmp/hello
  1. We would like to run a service on port 9999 using socket and when somebody is connected on this port we write current time of the connection into file.

Create a unit file1.

touch /etc/systemd/system/baz.socket

Write this to the unit file1.

[Unit]
Description=Baz Socket

[Socket]
ListenStream=127.0.0.1:9999
Accept=yes

[Install]
WantedBy=sockets.target

Create a unit file2.

touch /etc/systemd/system/baz@.service

Write this to the unit file2.

[Unit]
Description=Baz Service
Requires=baz.socket

[Service]
Type=simple
ExecStart=/tmp/myscript
StandardInput=socket
StandardError=journal
TimeoutStopSec=5

[Install]
WantedBy=multi-user.target

Create a script.

touch /tmp/myscript

Write this to the script.

#!/usr/bin/bash
date >> /tmp/datenow.txt

Start the service.

systemctl start baz.socket
systemctl status baz.socket

Verify it.

cat /tmp/hello
  1. Create templates as abc@hello which will do the 1 tast, and abc@ ...
# ...
  1. Create three loopback devices and RAID-5 on these devices.
fallocate -l 100M file0
fallocate -l 100M file1
fallocate -l 100M file2

losetup -f file0
losetup -f file1
losetup -f file2

mdadm --create --verbose /dev/md0 -l 5 -n 3 /dev/loop0 /dev/loop1 /dev/loop2

mkfs.ext4 /dev/md0

Create a unit file.

touch /etc/systemd/system/raid.service

Write this to the unit file.

[Unit]
Description=Baz Service

[Service]
Type=simple
ExecStart=/tmp/raid
StandardError=journal
TimeoutStopSec=5

Create a script.

touch /tmp/raid

Write this to the script.

#!/usr/bin/bash
fallocate -f file0
fallocate -f file1
fallocate -f file2

Start the service.

systemctl start baz.socket
systemctl status baz.socket

HELP: