Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role stops service when started by timer #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jstenvall-ducksify
Copy link

This PR fixes an issue when this role is executed and any systemd service unit is currently running (i.e. state started). When the role updates its definitions of systemd unit files, it ensures that the running state conforms to the value of unit_item.state or _default_unit_state. This is done in the task titled "Activate configured Systemd units".

Since it is started by a systemd timer and according to the role, it is not supposed to be enabled, hence the service is shutdown. This could happen to any service unit that is supposed to be in a stopped state. This "anomaly" I would like to address in this PR.

When you do not want the role to enforce the state of the service (stopped, started), simply by adding the variable unit_item.manage_state it tells the roles systemd task to either manage the state, or simple omitting the state setting.

unit_config:
  - name: "Test Service"
    manage_state: false
    Unit:
      Description: Service Test
    Service:
      User: test_user
      Group: test_user
      ExecStart: /usr/bin/ls /etc/fstab
    Install:
      WantedBy: multi-user.target
  - name: "Test Timer"
    type: timer
    enabled: true
    state: started
    Unit:
      Description: Timer Test
    Timer:
      OnCalendar: "*-*-* 4:00:00"
      Unit: "test_service.service"
    Install:
      WantedBy: timers.target

This configuration will create a unit with a state that will not be managed by this role since the manage_state is set to false.

We could name the variable enforce_state instead of manage_state.

Fixes #53

jstenvall-ducksify and others added 2 commits March 11, 2022 18:16
…_stops_itself

Systemd stops its own service when started by timer
@jstenvall-ducksify
Copy link
Author

I do not know how to test this new feature.

@jstenvall-ducksify jstenvall-ducksify changed the title Systemd stops service when started by timer Role stops service when started by timer Mar 22, 2022
@O1ahmad
Copy link
Owner

O1ahmad commented Mar 25, 2022

I do not know how to test this new feature.

Hey @jstenvall-ducksify, nice..thanks for the PR!

With regards to testing, so technically the steps listed in CONTRIBUTING.md should work for local testing. They really just require the installation of a couple of linting tools and having a ruby environment setup to be able to bundle install at repo root in order to pull in all of the ruby related dependencies (e.g. test-kitchen used as the functional/integration testing framework).

If you wouldn't mind trying those steps out locally to verify no regressions then that would be great but no worries if you encounter issues along the way. I think at the very least there may be some changes necessary to ensure the test-kitchen docker driver setup works as expected but otherwise the process should be ok. If so, we should be able to pretty easily add another test to directly verify the new functionality you added.

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.

Systemd stops Service when started by timer
2 participants