Class Systemd

java.lang.Object
com.github.jpmsilva.jsystemd.Systemd
All Implemented Interfaces:
AutoCloseable

public class Systemd extends Object implements AutoCloseable
The main systemd integration class.

Implements and exposes most of the sd_notify protocol, as well as some convenience methods.

Since this object sets up some timers for periodic communication with systemd, client code is expected to call close() then they no longer need Systemd instances. The implementation also implements AutoCloseable to ease implementation in DI containers that support the semantic.

Author:
Joao Silva
  • Method Details

    • builder

      @NotNull public static @NotNull Systemd.Builder builder()
      Provides a dedicated builder instance that knows how to create Systemd instances.
      Returns:
      a builder instance
    • addStatusProviders

      public void addStatusProviders(int index, SystemdStatusProvider... providers)
      Adds the status providers to the list of providers in the specified position.
      Parameters:
      index - position to add the providers
      providers - the providers to add
    • addStatusProviders

      public void addStatusProviders(SystemdStatusProvider... providers)
      Adds the status providers to the end of the list of providers.
      Parameters:
      providers - the providers to add
    • addStatusProviders

      public void addStatusProviders(int index, List<SystemdStatusProvider> providers)
      Adds the status providers to the list of providers in the specified position.
      Parameters:
      index - position to add the providers
      providers - the providers to add
    • getStatusProviders

      @NotNull public @NotNull List<SystemdStatusProvider> getStatusProviders()
      Returns a read only view of the current providers.
      Returns:
      the current list of providers
    • setStatusProviders

      public void setStatusProviders(@NotNull @NotNull List<SystemdStatusProvider> providers)
      Sets the current providers, unregistering any other previously added.
      Parameters:
      providers - the providers to set
    • getHealthProvider

      public Optional<HealthProvider> getHealthProvider()
      Returns the current health provider.
      Returns:
      the current provider
    • setHealthProvider

      public void setHealthProvider(@Nullable @Nullable HealthProvider provider)
      Sets the current health provider, overrides any other previously set.
      Parameters:
      provider - the provider to set, or null to disable the watchdog health integration
    • enablePeriodicExtendTimeout

      public void enablePeriodicExtendTimeout()
      Enables the periodic extension of the timeout.
      See Also:
    • disablePeriodicExtendTimeout

      public void disablePeriodicExtendTimeout()
      Disables the periodic extension of the timeout.
      See Also:
    • updateStatus

      public void updateStatus()
      Forces the current status to be calculated and sent to systemd. The method enableStatusUpdate(long, TimeUnit) can be used to enable periodic status updates.
    • extendTimeout

      public void extendTimeout()
      Forces the timeout to be extended. The amount of time to extend is specified when the Systemd instance is build with Systemd.Builder.extendTimeout(long, TimeUnit, long), or 29 seconds if otherwise. Timeout extensions can only be sent during startup.
      See Also:
    • watchdog

      public void watchdog()
      Forces the watchdog timestamp to be updated. The method enableWatchdog(long, TimeUnit) can be used to enable periodic watchdog updates.

      If health provider is set and returns unhealthy the watchdog timestamp is not updated.

    • ready

      public void ready()
      Notifies systemd that the application is ready.
    • isReady

      public boolean isReady()
      Returns if the application as completed startup.
      Returns:
      true if and only if ready has been called.
    • stopping

      public void stopping()
      Signals that the application is stopping.
    • logStatus

      public void logStatus()
      Logs information regarding the status of the integration with systemd. Meant to be used once the application has done sufficient work to initialize logging.
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception