Skip to content

Commit

Permalink
service admin lab updates
Browse files Browse the repository at this point in the history
  • Loading branch information
myee111 committed Jun 18, 2024
1 parent 3c93b29 commit fb52129
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 42 deletions.
21 changes: 11 additions & 10 deletions service-admin/01-ps/assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ tabs:
- title: Terminal
type: terminal
hostname: rhel
cmd: tmux attach-session -t "rhel-session" > /dev/null 2>&1
- title: Terminal 2
type: terminal
hostname: rhel
cmd: tmux attach-session -t "rhel-session-2" > /dev/null 2>&1
difficulty: basic
timelimit: 3000
---
What are processes?
===

_Files_ keep track of information on a Linux system, providing a way for users to organize and store information. Sometimes, files contain information that can be run to carry out a specific operation. These kinds of files are called _programs_. When you run a program, the running instance is called a _process_. Modern Linux systems have tons of processes running at any given moment, so it is crucial to have a way to manage these processes.

## Viewing processes
Viewing processes
===

The command that lets you view processes on Linux is `ps`, short for "Process Status". This command will show you all processes running in the current shell if called without any options. However, it is frequently useful to see processes that may not have been started with your user ID. The command `ps aux` will show you all processes, including those running without a controlling terminal. This command will also give information about the users associated with these processes.

```bash
```bash,run
ps aux
```

Expand All @@ -57,13 +55,13 @@ root 4 0.0 0.0 0 0 ? I< 16:09 0:00 [rcu_par_gp]

This output is very extensive, so often when you call this command you want to pipe the output into `grep` to search for a specific phrase. To practice this, start a process, background it, and then search for it in the original terminal. The `dd` command can be used to create an indefinite process. The command below begins copying data from a file of infinite zeros into a file that discards all inputs, so the process will continue indefinitely. The `&` sends the process into the background so that we do not interact with it in the terminal.

```bash
```bash,run
dd if=/dev/zero of=/dev/null &
```

When you run this command, you will not see an output as the process will continue running in the foreground until you interrupt it. Returning to the original terminal, run a search on `ps aux` to find this indefinite `dd` process:

```bash
```bash,run
ps aux | head -n1 ; ps aux | grep '[d]d '
```

Expand All @@ -72,4 +70,7 @@ USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3790 101 0.0 7352 944 pts/1 R+ 17:38 0:01 dd if=/dev/zero of=/dev/null
</pre>

>_NOTE:_ The first command in this line will print the column headers for `ps aux` so that you can see what each entry means. The second command searches for a process called `dd `, where the single quotes ensure the trailing space is part of the search criteria. Enclosing the first "d" in square brackets prevents the `grep` search from finding itself when it looks through the process list. Take note of the second column, the Process ID. This ID is how you interact with the process, as it can be used in other commands as a unique reference to this process. Now you know how to find a process. The next step will walk you through terminating this indefinite process.
> [!NOTE]
> The first command in this line will print the column headers for `ps aux` so that you can see what each entry means. The second command searches for a process called `dd `, where the single quotes ensure the trailing space is part of the search criteria. Enclosing the first "d" in square brackets prevents the `grep` search from finding itself when it looks through the process list.
Take note of the second column, the Process ID. This ID is how you interact with the process, as it can be used in other commands as a unique reference to this process. Now you know how to find a process. The next step will walk you through terminating this indefinite process.
24 changes: 11 additions & 13 deletions service-admin/02-kill/assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,28 @@ tabs:
- title: Terminal
type: terminal
hostname: rhel
cmd: tmux attach-session -t "rhel-session" > /dev/null 2>&1
- title: Terminal 2
type: terminal
hostname: rhel
cmd: tmux attach-session -t "rhel-session-2" > /dev/null 2>&1
difficulty: basic
timelimit: 1
---
Killing processes
===
Now that you found the `dd` process on Terminal 1, terminate it using the `kill` command. You would typically just manually enter the process ID after `kill`. The process ID is the second column of the `ps aux` output from before. However, to make this command clickable for each new lab instance the `pidof` (**P**rocess **ID of**) command is used to automatically find the process ID.

Now that you found the `dd` process on Terminal 1, terminate it using the `kill` command. You would typically just manually enter the process ID after `kill`. The process ID is the second column of the `ps aux` output from before. However, to make this command clickable for each new lab instance the `pidof` (__P__rocess __ID of__) command is used to automatically find the process ID.

```bash
```bash,run
kill $(pidof dd)
```

There is no output, but switching back to Terminal 2 reveals that the `dd` process has been terminated.
Look for the `dd` process again.
```bash,run
ps aux | head -n1 ; ps aux | grep '[d]d '
```

<pre class=file>
Terminated
</pre>
There is no output because the process has been killed.

The `kill` command can send a variety of signals. Calling the command without any options will default to `-SIGTERM`. This command will inform the process that it is time for it to stop, but allow it to run any cleanup procedures that it has. This often takes the form of closing files and freeing memory. In this sense, `-SIGTERM` is the graceful option for terminating a process.

If you instead use the `kill -SIGKILL` command, this will instruct the kernel to immediately stop the process. This prevents any cleanup that may have otherwise occurred, leaving memory allocated and potentially leading to corrupted files. Therefore, only use `-SIGKILL` as a last resort.

>_NOTE:_ You will also see the `kill` signals referred to numerically. `-SIGTERM`
> [!NOTE]
> You will also see the `kill` signals referred to numerically. `-SIGTERM`
is equivalent to `-15` and `-SIGKILL` is equivalent to `-9`.
13 changes: 7 additions & 6 deletions service-admin/03-service/assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ tabs:
- title: Terminal
type: terminal
hostname: rhel
cmd: tmux attach-session -t "rhel-session" > /dev/null 2>&1
difficulty: basic
timelimit: 1
---
What is a service?
===
The process you interacted with in the previous step was a foreground process. It ran in a terminal window where you could see it. Some processes run in the background, out of view of the user. These background processes allow the system to carry out many operations in parallel. Background processes that continuously carry out a set of actions are called _services_.

_Daemons_ are even more specialized. These are services that and are specifically designed to supervise or support other processes. Typically, daemons are denoted by a __d__ at the end of their name. For example, __firewalld__ is the daemon which handles firewall functionality. These daemons lie in wait, listening for the user to issue a command to tell them to change their behavior.

## Viewing the status of a service

Viewing the status of a service
===
__firewalld__ is a service which manages what network traffic to let into the system. Check the status of the __firewalld__ service with the following command:

```bash
```bash,run
systemctl status firewalld.service --no-pager
```

Expand All @@ -37,6 +38,6 @@ systemctl status firewalld.service --no-pager

From this status message it is clear that the __firewalld__ service is installed and active. But what is managing this service? It turns out that another service, __systemd__, is in charge of managing all of the services on the system.

# __systemd__ vs. __systemctl__

systemd vs. systemctl
===
When researching service management, you will come across two very similar terms: __systemd__ and __systemctl__. These are very closely related. __systemd__, short for system daemon, manages the state of the system and any services running on it. Since __systemd__ is a daemon, it runs in the background and needs a set of commands for users to interact with it. __systemctl__ provides these commands. The `systemctl status` command above is one example of this, and the upcoming steps will walk you through starting and enabling a service with __systemctl__.
9 changes: 5 additions & 4 deletions service-admin/04-systemctl/assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ tabs:
- title: Terminal
type: terminal
hostname: rhel
cmd: tmux attach-session -t "rhel-session" > /dev/null 2>&1
difficulty: basic
timelimit: 1
---
Starting and enabling a service with systemctl
===

For this example, you will be using the Network File System (NFS) service. This service allows users on client systems to view files and directories over a network as if they were on the client's local drive. Rather than focusing on the functionality of this service, though, this lab simply uses it as an example of how to start a service and implement configuration file changes.

To begin, run the command to show the export list for the NFS server:

```bash
```bash,run
showmount -e
```

Expand All @@ -28,7 +29,7 @@ clnt_create: RPC: Program not registered

To solve this issue, you need to start the service. However, if you want the service to start each time you boot the system, you need to enable the service. You can do both of these operations in one line:

```bash
```bash,run
systemctl enable --now nfs-server
```

Expand All @@ -40,7 +41,7 @@ Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service
Now the __nfs-server__ service is started, and it will start every time the system starts as well. Run the `showmount` command again now that the service is active:

```bash
```bash,run
showmount -e
```

Expand Down
15 changes: 8 additions & 7 deletions service-admin/05-restarting-services/assignment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ tabs:
- title: Terminal
type: terminal
hostname: rhel
cmd: tmux attach-session -t "rhel-session" > /dev/null 2>&1
difficulty: basic
timelimit: 1
---

Restarting a service to apply configuration changes
===
To demonstrate how configuration changes behave when a service is already running, add an export directory to the NFS service on this system:

```bash
```bash,run
echo "/home" >> /etc/exports
```

This command adds the home directory to the export list configuration file for NFS. Changing this config file does not lead to any immediate changes in the NFS service, though. Print the export list again to confirm this:

```bash
```bash,run
showmount -e
```

Expand All @@ -30,13 +31,13 @@ Export list for rhel:

To bring configuration changes into the service, you must first use `systemctl` to restart it:

```bash
```bash,run
systemctl restart nfs-server
```

Now the configuration files have been re-read and NFS reflects the configuration change.

```bash
```bash,run
showmount -e
```

Expand All @@ -47,6 +48,6 @@ Export list for rhel:

The home directory is now listed as an exported drive that is available to all NFS clients. If you ever run into a scenario where you are unable to see configuration changes, make sure you check whether or not you have restarted the service and reloaded the config files.

# __systemd__ Cheat Sheet

systemd Cheat Sheet
===
This lab just scratches the surface of __systemd__'s capabilities. Red Hat provides a [systemd Cheat Sheet](https://access.redhat.com/articles/systemd-cheat-sheet) which has a variety of other commands that are useful for service management.
2 changes: 1 addition & 1 deletion service-admin/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
virtualmachines:
- name: rhel
image: projects/tmm-instruqt-11-26-2021/global/images/rhel-9-3-11-14-23
image: projects/tmm-instruqt-11-26-2021/global/images/rhel-9-4-05-27-24
shell: /bin/bash
environment:
TERM: xterm
Expand Down
3 changes: 2 additions & 1 deletion service-admin/track.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ lab_config:
position: right
feedback_recap_enabled: true
loadingMessages: true
checksum: "11609089271142646265"
hideStopButton: false
checksum: "1830304246294704258"

0 comments on commit fb52129

Please sign in to comment.