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

Systemd stops its own service when started by timer #1

Merged
merged 1 commit into from
Mar 22, 2022

Conversation

jstenvall-ducksify
Copy link
Collaborator

@jstenvall-ducksify jstenvall-ducksify commented Mar 22, 2022

This PR fixes an issue when this role is executed and any systemd service unit is currently running (i.e. 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 O1ahmad#53

@jstenvall-ducksify jstenvall-ducksify merged commit e003fab into master Mar 22, 2022
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
1 participant