introduction
In Linux systems, systemd is the core tool for managing services and processes. However, in actual operation and maintenance, we often encounter service startup failure. This article will take a specific case - the failure to start up by ad_auth.service as an example, and introduce in detail how to troubleshoot and resolve such problems. Through this article, you will master a complete set of investigation ideas and methods to help you quickly locate and solve the problem of service startup failure.
Problem description
During the operation and maintenance process, we found that the ad_auth.service service cannot start normally. Check the service status through the systemctl status ad_auth.service command to get the following log:
● ad_auth.service - ad-auth Loaded: loaded (/etc/systemd/system/ad_auth.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Fri 2025-01-10 16:18:00 CST; 4s ago Process: 143701 ExecStart=/opt/ad_auth/ start (code=exited, status=0/SUCCESS) Main PID: 143704 (code=exited, status=1/FAILURE) Jan 10 16:17:55 admin systemd[1]: Starting ad-auth... Jan 10 16:17:55 admin systemd[1]: Started ad-auth. Jan 10 16:18:00 admin systemd[1]: ad_auth.service: main process exited, code=exited, status=1/FAILURE Jan 10 16:18:00 admin systemd[1]: Unit ad_auth.service entered failed state. Jan 10 16:18:00 admin systemd[1]: ad_auth.service failed.
You can see from the logs,ad_auth.service
The service fails quickly after startup, with the status code as1/FAILURE
. Next, we will gradually check the root cause of the problem.
Troubleshooting steps
1. View detailed log
systemctl status
The log information provided is limited, we need to usejournalctl
View more detailed logs:
journalctl -u ad_auth.service -b
-u
Parameters specify the service name,-b
Parameters are limited to the current startup cycle. By viewing the detailed logs, we may find more specific error messages, such as missing files, permission issues, dependencies not started, etc.
2. Check the startup script
As you can see from the log, the script executed when the service starts is/opt/ad_auth/ start
. We need to check the content and operation of the script.
2.1 Check script permissions
Make sure the script has executable permissions:
chmod +x /opt/ad_auth/
2.2 Run the script manually
Run the script manually to see if there is any error output:
/opt/ad_auth/ start
If there is log output in the script, check the log file or standard output/error output. For example:
/opt/ad_auth/ start > /tmp/ 2>&1
Then check/tmp/
File, analyze error information.
3. Check dependencies
Services may depend on other services or resources. If the dependency is not started or configured incorrectly, the service will not function properly.
3.1 View service dependencies
Use the following command to viewad_auth.service
Dependencies:
systemctl list-dependencies ad_auth.service
Make sure all dependencies are started correctly.
3.2 Check the network and database
If the service relies on the network or database, ensure that the network connection is normal, the database service is started and configured correctly.
4. Check the configuration file
There may be problems with the service's configuration file, which causes the service to fail to start.
4.1 Check the service unit file
Check/etc/systemd/system/ad_auth.service
File, ensure correct configuration:
cat /etc/systemd/system/ad_auth.service
Focus on the following configuration items:
-
ExecStart
: Start the command. -
Environment
: Environment variables. -
WorkingDirectory
: Working directory.
4.2 Check the application configuration file
If the service depends on the application configuration file, make sure the configuration file exists and is configured correctly. For example, check /opt/ad_auth/ or similar files.
5. Check resource limitations
If the service requires a lot of memory, CPU, or other resources, it may fail due to insufficient resources.
5.1 Check system resources
Use the following command to check system resource usage:
free -h # Check memory usagetop # Check CPU and memory usage
If resources are insufficient, try to adjust the resource limits of the service.
5.2 Adjust resource restrictions
existad_auth.service
Add resource restriction configuration to the file. For example:
[Service] MemoryLimit=512M CPUShares=1024
Then reload the configuration and restart the service:
systemctl daemon-reload systemctl restart ad_auth.service
6. Check for port conflicts
If the service needs to bind a port, make sure that the port is not occupied by other processes.
6.1 Check port occupation
usenetstat
orss
Check port occupancy:
netstat -tuln | grep <Port number> ss -tuln | grep <Port number>
If the port is occupied, stop the process that occupies the port or modify the service configuration.
7. Check SELinux or Firewall
If SELinux or firewall is enabled, the service may not function properly.
7.1 Check SELinux status
Use the following command to view the SELinux status:
sestatus
If SELinux is enforcing mode, try setting it to permissive mode to test:
setenforce 0
7.2 Check the firewall rules
Make sure that the ports required for the service are open. For example:
firewall-cmd --list-ports
If you need to open the port, use the following command:
firewall-cmd --add-port=<Port number>/tcp --permanent firewall-cmd --reload
8. Debugging Service
If the above steps cannot solve the problem, you can tryad_auth.service
Add debugging options to the file.
8.1 Add debug log
exist[Service]
The following content was added in part:
StandardOutput=journal StandardError=journal
Then restart the service and view the log:
systemctl daemon-reload systemctl restart ad_auth.service journalctl -u ad_auth.service -b
9. Check the service code
ifad_auth.service
is a custom service that checks whether there is any problem with its code or logic. For example, check for uncaught exceptions, resource leaks, or other issues.
Summarize
Through the above steps, we can systematically checkad_auth.service
The problem of startup failure. The following is the complete troubleshooting process:
- View detailed logs and locate error information.
- Check the startup script to make sure the script is executable and error-free.
- Check dependencies to make sure all dependencies are started.
- Check the configuration file to ensure that the configuration is correct.
- Check resource restrictions to ensure sufficient system resources.
- Check for port conflicts to make sure that the port is not occupied.
- Check SELinux or firewall to ensure that services are not restricted.
- Add debug logs to further analyze the problem.
- Check the service code and fix the logic error.
Through this method, we can quickly locate and solve the problem of service startup failure and ensure the stable operation of the system.
The above is the detailed content of the troubleshooting and solution to the failure of systemd service startup in Linux system (taking ad_auth.service as an example). For more information about the failure of Linux systemd service startup, please pay attention to my other related articles!