Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 12, 2025

This PR adds the ability to configure systemd Restart and RestartSec directives for the Elasticsearch service, addressing situations where automatic restart on failure (such as OOMs) is desired.

Changes

New Properties

Added two new properties to the elasticsearch_service resource:

  • restart_policy: Controls when systemd restarts the service

    • Valid values: no, always, on-success, on-failure, on-abnormal, on-abort, on-watchdog
    • Defaults to empty string (no restart) for backward compatibility
    • Includes regex validation to ensure only valid systemd values are accepted
  • restart_sec: Controls restart delay

    • Accepts integer (seconds) or systemd time span strings (e.g., "5min", "30s", "1m 30s")
    • Optional property - only adds RestartSec directive when specified

Implementation

The implementation conditionally adds the Restart and RestartSec directives to the systemd unit configuration only when explicitly configured, ensuring:

  • Backward compatibility: Existing cookbooks continue to work without changes
  • No impact on current deployments: Default behavior remains unchanged (no automatic restart)
  • Flexible configuration: Supports all standard systemd restart policies

Usage Examples

# Restart on failure with 30 second delay (addresses OOM scenario)
elasticsearch_service 'elasticsearch' do
  restart_policy 'on-failure'
  restart_sec 30
end

# Always restart with 5 minute delay
elasticsearch_service 'elasticsearch' do
  restart_policy 'always'
  restart_sec '5min'
end

# Just restart policy without delay
elasticsearch_service 'elasticsearch' do
  restart_policy 'on-failure'
end

Testing

  • Added ChefSpec tests to validate property behavior and systemd unit generation
  • Created integration test controls to verify actual systemd unit file content
  • Added test fixtures demonstrating restart policy configuration
  • Comprehensive validation of all restart policy values and edge cases

This provides a clean, flexible solution that allows users to configure systemd restart behavior as needed while maintaining full backward compatibility with existing deployments.

Fixes #786.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Allow configuration of systemd service Restart directive Allow configuration of systemd service Restart directive Sep 12, 2025
@Copilot Copilot AI requested a review from damacus September 12, 2025 22:09
Copilot finished work on behalf of damacus September 12, 2025 22:09
Copy link

😰 RSpec failure

37 examples, 1 failure
Example Description Message
spec/service_spec.rb:51 elasticsearch_service with default configuration creates systemd unit without restart policy undefined method `converge_dsl' for #ChefSpec::ServerRunner options: {:cookbook_root="/home/runner/work/elasticsearch/elasticsearch", :cookbook_path=>"/tmp/d20250912-2202-kx8qaf/cookbooks", :role_pa...

Copy link

Slowest examples

Top 10 slowest examples (12.15 seconds, 65.15% of total time)
Example Description Time in seconds
spec/service_spec.rb:16 elasticsearch_service on Ubuntu 18.04 creates systemd unit with restart policy 2.27295
spec/user_spec.rb:19 test::user on Centos 8 deletes user deleteme 1.20368
spec/service_spec.rb:27 elasticsearch_service on Ubuntu 18.04 enables and starts the elasticsearch service 1.12768
spec/service_spec.rb:16 elasticsearch_service on Ubuntu 20.04 creates systemd unit with restart policy 1.0863
spec/service_spec.rb:27 elasticsearch_service on Ubuntu 20.04 enables and starts the elasticsearch service 1.08274
spec/user_spec.rb:19 test::user on Ubuntu 18.04 deletes user deleteme 1.07839
spec/user_spec.rb:15 test::user on Centos 8 creates elasticsearch user deleteme in group foo 1.0774
spec/user_spec.rb:15 test::user on Ubuntu 20.04 creates elasticsearch user deleteme in group foo 1.07571
spec/service_spec.rb:16 elasticsearch_service on Centos 8 creates systemd unit with restart policy 1.0745
spec/service_spec.rb:27 elasticsearch_service on Centos 8 enables and starts the elasticsearch service 1.07365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow configuration of systemd service Restart directive
2 participants