service icon indicating copy to clipboard operation
service copied to clipboard

systemd on linux - add KillMode, KillSignal and TimeoutStopSec

Open avoidik opened this issue 1 year ago • 5 comments

hello,

with this PR I would like to introduce these new [Service] scoped flags:

  • KillMode
  • KillSignal
  • TimeoutStopSec

addresses:

  • https://github.com/kardianos/service/issues/202
  • https://gitlab.com/gitlab-org/gitlab-runner/-/issues/36956 (partially)

related PRs:

  • https://github.com/kardianos/service/pull/301
  • https://github.com/kardianos/service/pull/320

avoidik avatar Dec 28 '23 14:12 avoidik

@kardianos

I believe this pull request is useful. Could you please take a look at it and consider merging it soon?

Thanks!

luoxiaohei avatar Jun 12 '24 05:06 luoxiaohei

Can you doc the new specific flags? Will changing these, such as Kill mode, etc, alter how the service, by default works? What values should it expect?

kardianos avatar Jun 13 '24 13:06 kardianos

Hi @kardianos,

Thank you for your feedback. Just to confirm, are you requesting that detailed documentation be added to the pull request, such as annotations and descriptions for the new options? Or are you expecting the definition of some global variables to declare the available values and default values for each option?


To provide some context, here are brief explanations of these flags, along with their default values and expected ranges:

  • KillMode: Determines how processes of a service should be killed when the service is stopped.

    • Default value: control-group
    • Expected values:
      • control-group: All processes in the control group are killed.
      • process: Only the main process is killed.
      • mixed: Main process is killed with KillSignal, and remaining processes are killed with SIGKILL.
      • none: No processes are killed.
  • KillSignal: Specifies which signal should be sent to the service's main process when it is being stopped.

    • Default value: SIGTERM
    • Expected values: Any valid Unix signal, such as SIGTERM, SIGKILL, SIGINT, SIGHUP, etc.
  • TimeoutStopSec: Sets the time to wait for a service to stop after sending the termination signal before forcibly killing it.

    • Default value: 90 seconds
    • Expected values: Any valid time duration, such as 30s (30 seconds), 5min (5 minutes), 1h (1 hour), etc.

luoxiaohei avatar Jun 13 '24 14:06 luoxiaohei

On on the fence on Timeout Stop Sec.

The Kill signal, that would probably interfere with the current implementation of func (s *systemd) Run() (err error) {

The KillMode, I'm not sure when you wouldn't want to have control-group, for a multi-platform service system.

Where is this need coming from? More broadly, I would be inclined to make separate system packages that have many options, such as systemd, then have service package be a generic package, with perhaps a system specific use cases. If you know you are going to use systemd, maybe just use it directly.

kardianos avatar Jun 15 '24 12:06 kardianos

@kardianos it's quite good summary, I understand your desire to keep this package simple and as generic as possible, without implementing edge-case logic specific to downstream solutions, alternatively, you have left an option to be able to render our own custom template for units, in case of systemd it's called "SystemdScript", if we absolutely sure we'd want to use systemd this option is what we need, however this part hasn't been described in details

avoidik avatar Jun 15 '24 18:06 avoidik