Skip to content

Service Operations

ensure_service.sh

Service-related ensure functions, currently only for systems using systemd.

Functions

ensure_service_active

Ensure that a service is running, starting it if necessary.

Automatically performs a daemon-reload if the service unit file has changed.

Examples

  • Start nginx if not running
    ensure_service_active nginx
    
  • Enable and start docker
    ensure_service_active --enable docker
    
  • Restart a service after config changes
    ensure_service_active --restart nginx
    
Arguments
  • --enable:

    Also enable the service to start on boot.

  • --restart:

    Force restart the service even if already running. NOT IDEMPOTENT.

  • --reload:

    Reload the service configuration. NOT IDEMPOTENT.

  • --no-start:

    Only configure the service (enable/daemon-reload) without starting it.

  • {service_name...}:

    The name of the service(s) to ensure are active.


ensure_service_inactive

Ensure that a service is stopped, stopping it if necessary.

Examples

  • Stop apache2 if running
    ensure_service_inactive apache2
    
  • Disable and stop a service
    ensure_service_inactive --disable apache2
    
Arguments
  • --disable:

    Also disable the service from starting on boot.

  • --no-stop:

    Only configure the service (disable) without stopping it.

  • {service_name...}:

    The name of the service(s) to ensure are inactive.