When using the auto-configuration class, SystemdNotifyStatusProvider beans will also be searched in the application context and used to compose an extended status message that systemd will display when using the status
verb.
Out of the box this module will show memory (heap/non-heap), classloader information, application startup sequence state and bean creation progress.
Additionally, if running with the embedded Tomcat container, status regarding Tomcat’s connectors will also be displayed.
[root@machine ~]# systemctl status myservice.service ● myservice.service - My Spring Boot Service Loaded: loaded (/etc/systemd/system/myservice.service; disabled; vendor preset: disabled) Active: active (running) since Qui 2018-02-15 10:19:28 WET; 1h 24min ago Main PID: 11142 (java) Status: "Heap: 139.5 MiB/256 MiB, Non-heap: 62.7 MiB/64.1 MiB, Classes: 7915" CGroup: /system.slice/myservice.service └─11142 /opt/jdk1.8.0/bin/java -XX:+ExitOnOutOfMemoryError -Xms256M -Xmx512M -XX:+UseG1GC -jar /opt/myservice/myservice.jar
After creating the Systemd instance to interface with the service supervisor, register any instance of SystemdNotifyStatusProvider with addStatusProviders.
The following table lists the provided implementations:
Class | Purpose | Sample |
---|---|---|
SystemdNotifyHeapStatusProvider | Provides information regarding heap memory status | Heap: 139.5 MiB/256 MiB |
SystemdNotifyNonHeapStatusProvider | Provides information regarding non heap memory status | Non-heap: 62.7 MiB/64.1 MiB |
SystemdNotifyClassLoaderStatusProvider | Provides information regarding the number of loaded classes | Classes: 7915 |
SystemdNotifyApplicationRunStatusProvider | Provides information regarding the application startup sequence state | State: context prepared |
SystemdNotifyApplicationContextStatusProvider | Provides information regarding the bean creation status of the application context | Creating bean 94 of 472 |
SystemdNotifyTomcatStatusProvider | Provides information regarding Tomcat’s connectors | http-nio-8080: 2/10 |
See the Startup progress page for more information regarding SystemdNotifyApplicationRunStatusProvider
and SystemdNotifyApplicationContextStatusProvider
.
See the Tomcat status page for more information regarding SystemdNotifyTomcatStatusProvider
.
You can create your own status information extending SystemdNotifyStatusProvider, and provide an instance of such custom classes to systemd
@Configuration @ConditionalOnSystemD public class MyConfiguration { @Bean MyStatusProvider myStatusProvider() { return new MyStatusProvider(); } }
In the example above, the configuration class does not need to be annotated with ConditionalOnSystemd, because these beans are harmless even when not running under systemd. However, this was these extra resources do not have to be built at all. Check the Conditionals page for more information.
Under Spring Boot you can also autowire the current instance of Systemd and programmatically manage it:
@Configuration @ConditionalOnSystemD public class MyConfiguration { @Autowire MyConfiguration(Systemd systemd) { // Force update current service status systemd.updateStatus(); } }
Out of the box, Systemd sends status updates to the supervisor daemon once every five seconds.