Chapter 4. Using the command-line assistant to debug or troubleshoot system issues
You can use the command-line assistant powered by RHEL Lightspeed to request information on how to troubleshoot the issues that you face on your system.
The following are examples of questions that you can ask to troubleshoot your system. Ask a question by using the following syntax: c + "question". For example:
-
$ c “how to troubleshoot network errors”
-
$ c “I cannot access my server with SSH. Can you give me a list of things to troubleshoot?”
-
$ c "I am failing to start sssd process"
-
$ c “I need to boot into a different kernel”
-
$ c “how to troubleshoot SSHD failing to start”
-
$ c “how do I find all the files in the /etc that have been modified in the last hour”
-
$ c "I am failing to start sssd process"
4.1. Using the command-line assistant to troubleshoot SSHD service failing to start
The following example shows how to troubleshoot an SSHD service failing to start by using the following command-line assistant features:
- Optional terminal capture feature in the command-line assistant to reference the output of previous commands when interacting with the command-line assistant.
- Piping data into the command-line assistant.
Prerequisites
- You have enabled the command-line assistant.
- You have root access to your system.
Procedure
Check the SSHD status and restart it.
sudo systemctl status ssh sudo systemctl restart ssh
$ sudo systemctl status ssh $ sudo systemctl restart ssh
Copy to Clipboard Copied! Enable the optional command-line assistant terminal capture feature:
c shell --enable-capture
$ c shell --enable-capture
Copy to Clipboard Copied! Use the
-w 1 "your-question"
option to specify to include the output from the last command that was run.c -w 1 "what_is_this"
$ c -w 1 "what_is_this"
Copy to Clipboard Copied! - If you specify the number 2, that references the output from the second previous 2 commands. This is also true for the additional numbers.
You can also specify a prompt to run with the command and ask “help me understand the output”, and reference the output with the error, so that the command my assistant understands that you are asking for more details on what is the error.
The command-line assistant takes some time to process the request, and provide several possible solutions. In the example, you can use the suggestion to run the
journalctl -xeu
command, so that you can usesshd.service
to check the log files.
Run that
journalctl
command. Add the tail command to get the last 30 lines, pipe that output into the command-line assistant, and add a query to understand the error.journalctl -xeu sshd.service | tail -n 30 | c “here are the logs, please help me understand this”
$ journalctl -xeu sshd.service | tail -n 30 | c “here are the logs, please help me understand this”
Copy to Clipboard Copied! The command-line assistant checks the log files and indicates some potential issues. typing error in the
config
file.Ask the command-line assistant to generate a command on how to fix this typing error.
c “what is the command that I can use to change “Porrt ”to “Port” in the /etc/ssh/sshd_config file?”
$ c “what is the command that I can use to change “Porrt ”to “Port” in the /etc/ssh/sshd_config file?”
Copy to Clipboard Copied! Use the command suggested by the command-line assistant.
Run the command suggested by the command-line assistant. For example:
sed -i s/Porrt/Port/g /etc/ssh/sshd_config
$ sed -i s/Porrt/Port/g /etc/ssh/sshd_config
Copy to Clipboard Copied! The output found a permission denied error to edit that file. Rerun the previous command as a sudo user.
sudo sed -i s/Porrt/Port/g /etc/ssh/sshd_config
$ sudo sed -i s/Porrt/Port/g /etc/ssh/sshd_config
Copy to Clipboard Copied! Restart the SSHD service and check the status of the SSHD.
sudo systemctl restart sshd sudo systemctl status sshd
$ sudo systemctl restart sshd $ sudo systemctl status sshd
Copy to Clipboard Copied!
4.2. Using the command-line assistant to troubleshoot SELinux issues
The following example provides steps to troubleshoot an SELinux problem with the command-line assistant.
Prerequisites
- You have enabled the command-line assistant.
- You have root access to your system.
Procedure
On your terminal, enter the following command to list the
httpd
package version that you have installed in your system:sudo rpm -qa httpd
$ sudo rpm -qa httpd httpd-2.4.62-2.fc40.x86_64
Copy to Clipboard Copied! Show the
httpd.conf
file content.sudo cat /etc/httpd/conf/httpd.conf This is the main Apache HTTP server configuration file. It contains the configuration directives that give the server its instructions. See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. In particular, see<URL:http://httpd.apache.org/docs/2.4/mod/directives.html> for a discussion of each configuration directive.
$ sudo cat /etc/httpd/conf/httpd.conf # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see<URL:http://httpd.apache.org/docs/2.4/mod/directives.html> # for a discussion of each configuration directive.
Copy to Clipboard Copied! Query all
httpdq
packages:sudo rpm -qa httpdq
$ sudo rpm -qa httpdq
Copy to Clipboard Copied! Identify the ports on which the web server accepts incoming requests:
cat /etc/httpd/conf/httpd.conf | grep Listen Listen: Allows you to bind Apache to specific IP addresses and/or Change this to Listen on a specific IP address, but note that if #Listen 12.34.56.78:80 Listen 80
$ cat /etc/httpd/conf/httpd.conf | grep Listen # Listen: Allows you to bind Apache to specific IP addresses and/or # Change this to Listen on a specific IP address, but note that if #Listen 12.34.56.78:80 Listen 80
Copy to Clipboard Copied! Restart the
httpd
service:systemctl restart httpd
$ systemctl restart httpd Job for httpd. Service failed because the control process exited with error code. See “systemctl status httpd.service" and “journalctl -xeu httpd.service” for details.
Copy to Clipboard Copied! Run the
journalctl
command for more details on the failed service:sudo journalctl -xeu httpd.service
$ sudo journalctl -xeu httpd.service
Copy to Clipboard Copied!
Use the command-line assistant to troubleshoot the issue and ask why the service is failing:
sudo c “why did httpd fail to start”
$ sudo c “why did httpd fail to start”
Copy to Clipboard Copied! One of the suggestions from the assistant is to query audit logs by using the
ausearch
tool, and use theAVC
andUSER_AVC
values for the message type parameter. For that, run the following command:sudo ausearch -m AVC,USER_AVC -ts recent
$ sudo ausearch -m AVC,USER_AVC -ts recent
Copy to Clipboard Copied! Ask the command-line assistant about the
selinux httpd
port:c “selinux httpd port”
$ c “selinux httpd port”
Copy to Clipboard Copied! The assistant advises to use the
sestatus
command to check the current SELinux status and the content of the httpd services with the following command:sudo sestatus
$ sudo sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: enforcing Policy MLS status: enabled Policy deny_unknown status: allowed Memory protection checking: actual (secure) Max kernel policy version: 33
Copy to Clipboard Copied! View the specific SELinux policy for the httpd services by running the following command:
sudo cat /usr/share/selinux/targeted/contexts/httpd_var_run_t No such file or directory
$ sudo cat /usr/share/selinux/targeted/contexts/httpd_var_run_t No such file or directory
Copy to Clipboard Copied! Ask the command-line assistant about contexts.
c “i don't have a httpd_var_run_t contexts”
$ c “i don't have a httpd_var_run_t contexts”
Copy to Clipboard Copied! The command-line assistant takes some time to process the request, then provides several possible suggestions.
The assistant says that you might not have context and need to set it with the following command:
sudo chcon -R -t httpd_var_run_t
$ sudo chcon -R -t httpd_var_run_t
Copy to Clipboard Copied! Ask the CLA about the port:
c “selinux won't let httpd listen on port 12345”
$ c “selinux won't let httpd listen on port 12345”
Copy to Clipboard Copied! Try the following suggestion, run the command:
sudo semage port -a -t httpd_port_t -p tcp 12345
$ sudo semage port -a -t httpd_port_t -p tcp 12345 ValueError: Type httpd_port_t is invalid, must be a port type
Copy to Clipboard Copied! Ask the CLA about the error you see in the output:
c “how do I fix ValueError: Type httpd_port_t is invalid, must be a port type”
$ c “how do I fix ValueError: Type httpd_port_t is invalid, must be a port type”
Copy to Clipboard Copied!
Run the steps provided by the CLA:
sudo getenforce setenforce 0 sudo systemctl restart httpd sudo systemctl status httpd sudo ls -Z /usr/sbin/httpd chcon -t httpd_exec_t /usr/sbin/httpd sudo setenforce 1
$ sudo getenforce Enforcing $ setenforce 0 $ sudo systemctl restart httpd $ sudo systemctl status httpd $ sudo ls -Z /usr/sbin/httpd system_u:object_r:httpd_exec_t:s0 /usr/sbin/httpd $ chcon -t httpd_exec_t /usr/sbin/httpd $ sudo setenforce 1
Copy to Clipboard Copied! Restart the
httpd
service and check the status ofhttpd.service
:sudo systemctl restart httpd sudo systemctl status httpd.service
$ sudo systemctl restart httpd Job failed $ sudo systemctl status httpd.service Failed to start the Apache Server
Copy to Clipboard Copied!
Ask the CLA how to enable
httpd
to listen onport
12345:c “how do I enable httpd to listen on port 12345 selinux”
$ c “how do I enable httpd to listen on port 12345 selinux”
Copy to Clipboard Copied! Run the command advised by the CLA:
sudo setsebool -P httpd_can_network_connect=1
$ sudo setsebool -P httpd_can_network_connect=1
Copy to Clipboard Copied!
Restart the
httpd
service and check the status ofhttpd.service
again:sudo systemctl status htppd sudo systemctl restart httpd
$ sudo systemctl status htppd $ sudo systemctl restart httpd Job failed, see journalctl
Copy to Clipboard Copied! Check the
journalctl
service:journalctl -xeu httpd
$ journalctl -xeu httpd Output: An ExecStart= process belonging to unit httpd.service has exited.
Copy to Clipboard Copied! Use the output to ask the CLA to troubleshoot:
c “An ExecStart= process belonging to unit httpd.service has exited.”
$ c “An ExecStart= process belonging to unit httpd.service has exited.”
Copy to Clipboard Copied! Run the command that the CLA responds with:
sudo ausearch -m AVC,USER_AVC -ts recent
$ sudo ausearch -m AVC,USER_AVC -ts recent Output: “avc: denied {name_bind} for pid=7184 comm=”httpd” src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0"
Copy to Clipboard Copied! Copy the output of the previous command:
sudo c ““avc: denied {name_bind} for pid=7184 comm=”httpd” src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0”
$ sudo c ““avc: denied {name_bind} for pid=7184 comm=”httpd” src=12345 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r: unreserved_port_t:s0 tclas=tcp_socket permissive=0”
Copy to Clipboard Copied! Run the following command to resolve the error “SELinux is preventing Apache Server (httpd) from binding to port 12345”.
sudo semage port -a -t http_port_t -p tcp 12345
$ sudo semage port -a -t http_port_t -p tcp 12345
Copy to Clipboard Copied!
Restart the httpd service and check the status of
httpd.service
:sudo systemctl restart httpd sudo systemctl status httpd.service
$ sudo systemctl restart httpd No error $ sudo systemctl status httpd.service
Copy to Clipboard Copied! The server is configured, up and running, and listening on
port 443
,port 12345
.