daemon | systemd | all others (Apache, MySQL, ) |
---|---|---|
its configuration is made of | unit files | /etc/daemonName/daemonName.conf |
to reload its configuration | systemctl daemon-reload | systemctl reload daemonName.service |
to restart it | this is not necessary 😉 | systemctl restart daemonName.service |
less -p "daemon-reload$"
' systemctl● myApplication.service - myApplication Java application Loaded: loaded (/etc/systemd/system/myApplication.service_4.1-RELEASE; bad) Active: failed (Result: start-limit-hit) since Wed 2020-03-04 10:19:40 UTC; 7s ago Process: 103744 ExecStop=/bin/kill -15 $(systemctl status myApplication.service | awk /Main PID/ {print $3}) (code=exited, status=1/FAILURE) Process: 103742 ExecStart=/usr/bin/java -jar myApplication.jar --spring.config.location=classpath:/,file:application.yaml (code=exited, status=1/FAILURE) Main PID: 103742 (code=exited, status=1/FAILURE)
[Unit] Description=myApplication Java application [Service] WorkingDirectory=/path/to/myApplication ExecStart=/usr/bin/java -jar myApplication.jar --spring.config.location=classpath:/,file:application.yaml ExecStop=/bin/kill -15 $(systemctl status myApplication.service | awk '/Main PID/ {print $3}') User=kevin Group=robots Restart=on-failure [Install] WantedBy=multi-user.target
Mar 04 10:34:21 myServer systemd[1]: Started myApplication Java application. Mar 04 10:34:21 myServer systemd[1]: myApplication.service: Main process exited, code=exited, status=1/FAILURE the startup fails Mar 04 10:34:21 myServer kill[104802]: kill: failed to parse argument: 'status' the ExecStop command fails too (but this is "normal" here) Mar 04 10:34:21 myServer systemd[1]: myApplication.service: Control process exited, code=exited status=1 Mar 04 10:34:21 myServer systemd[1]: myApplication.service: Unit entered failed state. Mar 04 10:34:21 myServer systemd[1]: myApplication.service: Failed with result 'exit-code'. Mar 04 10:34:21 myServer systemd[1]: myApplication.service: Service hold-off time over, scheduling restart. Mar 04 10:34:21 myServer systemd[1]: Stopped myApplication Java application. Mar 04 10:34:21 myServer systemd[1]: Started myApplication Java application. (looping 4 more times)
Flag | Usage |
---|---|
-l --full | Do not ellipsize unit names, process tree entries, journal output, or truncate unit descriptions in the output of status, list-units, list-jobs, and list-timers |
--now | |
daemon-reload | Reload systemd's configuration, see dedicated article
not be confused with reload
|
disable unit | do NOT start unit at boot time.
|
enable unit | start unit at boot time. This actually :
Possible causes of :
systemctl enable unit
Failed to execute operation: Invalid argument
|
list-dependencies [options] | Recursively show dependencies of the specified unit. Example : systemctl list-dependencies graphical.target
|
list-unit-files [options] | List unit files installed on the system and their enablement state : enabled / disabled / masked / static / generated / .... Example : systemctl list-unit-files --type=service
|
reload pattern | Asks all units listed on the command line to reload their configuration (i.e. ask daemons managed by systemd to reload their own configuration)
This will reload the service-specific configuration, not the unit configuration file of systemd. If you want systemd to reload the configuration file of a unit, use daemon-reload. In other words: for the example case of Apache, this will reload Apache's httpd.conf in the web server, not the apache.service systemd unit file.
not be confused with daemon-reload
|
restart pattern | Stop then start matching units. Any unit not already running will be started |
show |
|
status unit | Show terse runtime status information about unit, followed by most recent log data from the journal.
For a different output format :
systemctl status --output=json-pretty nginx
|
While debugging, it may be useful to prefix systemctl invocation with date :
systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-11-29 15:10:38 UTC; 2 days ago Process: 1111 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exited, status=0/SUCCESS) Process: 1050 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 1110 (mysqld) ps -o etime= 1110 2-17:50:46 ========================================== systemctl show mysql --property=MainPID | cut -d '=' -f 2 ps -o etime= $(systemctl show mysql --property=MainPID | cut -d '=' -f 2) 2-18:44:12 ========================================== systemctl show mysql --property=ActiveEnterTimestamp ActiveEnterTimestamp=Fri 2019-11-29 15:10:38 UTC ========================================== ps -o lstart= $(systemctl show mysql --property=MainPID | cut -d '=' -f 2) Fri Nov 29 15:10:36 2019 echo $(($(date -d"now" +%s) - $(date -d"Fri Nov 29 15:10:36 2019" +%s))) ==> uptime in seconds