saltstack / saltstack/salt

[BUG] State supervisord.running attempts to start an already running process

Open
#58,526 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Confirmed Core severity-medium State-Module
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
If one or more processes running under supervisor on target system is in STOPPED state, supervisor.running state can attempt to start and add the first process even if it is already running

This interferes with a watch constraint as the process does not get restarted if watched state changes because salt thinks the service has to be added and started anyways

Setup

Supervisor version>4.0

Steps to Reproduce the behavior

  • For a target system, add some processes under supervisor
  • Stop one or more processes but not the first process in the list

E.g. - on the target system, the supervisorctl status command shows

barnyard2                        RUNNING   pid 18660, uptime 4:46:26
netsniff-ng                      RUNNING   pid 21359, uptime 13:17:11
netsniff-ng-rollover             STOPPED   Sep 23 12:00 AM
parse_stats                      RUNNING   pid 28142, uptime 19:37:34
snort                            RUNNING   pid 18655, uptime 4:46:42
  • Attempt to apply a supervisord.running state to the first process in the list

My SLS file has a state definition like so:

barnyard2_process_running:
  supervisord.running:
    - name: barnyard2
    - watch:
      - file: bconf_file
      - pkg: barnyard_pkg

The result of this is Service barnyard2 will be added and started

LOGS

[INFO    ] Running state [barnyard2] at time 13:32:00.184640
[INFO    ] Executing state supervisord.running for [barnyard2]
[INFO    ] Executing command ['/usr/local/bin/supervisorctl', 'status'] in directory '/root'
[ERROR   ] Command '['/usr/local/bin/supervisorctl', 'status']' failed with return code: 3
[ERROR   ] stdout: barnyard2                        RUNNING   pid 18660, uptime 5:01:08
netsniff-ng                      RUNNING   pid 21359, uptime 13:31:53
netsniff-ng-rollover             STOPPED   Sep 23 12:00 AM
parse_stats                      RUNNING   pid 28142, uptime 19:52:16
snort                            RUNNING   pid 18655, uptime 5:01:24
[ERROR   ] retcode: 3
[INFO    ] Service barnyard2 will be added and started
[INFO    ] Completed state [barnyard2] at time 13:32:00.414145 (duration_in_ms=229.504)

Expected behavior

As the process is already running, salt should show a comment Service ABC is already running.

For my case expected is Service barnyard2 is already running

Screenshots
NA

Versions Report

salt --versions-report Both Master and Minion are on same salt version
Salt Version:
           Salt: 3001.1
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.11.2
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: 1.1.3
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: 3.9.8
         pygit2: Not Installed
         Python: 3.6.8 (default, Apr  1 2020, 10:29:41)
   python-gnupg: Not Installed
         PyYAML: 5.3.1
          PyZMQ: 19.0.2
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.3.2
 
System Versions:
           dist: scientific 7.6 Nitrogen
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.el7.x86_64
         system: Linux
        version: Scientific Linux 7.6 Nitrogen

Additional context

The problem occurs because supervisor returns non-zero codes since version 4.0 (See #54028) if any process is STOPPED. Salt interprets it as ERROR and appends ERROR: to supervisorctl status output (source).

This messes up the process split here for first process leading to state getting wrong process names here

For example the names of processes logged by the state for my example are:

{'ERROR:': {'state': 'barnyard2', 'reason': 'RUNNING   pid 18660, uptime 5:01:08'}, 'netsniff-ng': {'state': 'RUNNING', 'reason': 'pid 21359, uptime 13:31:53'}, 'netsniff-ng-rollover': {'state': 'STOPPED', 'reason': 'Sep 23 12:00 AM'}, 'parse_stats': {'state': 'RUNNING', 'reason': 'pid 28142, uptime 19:52:16'}, 'snort': {'state': 'RUNNING', 'reason': 'pid 18655, uptime 5:01:24'}}

As can be seen barnyard2 isn't a process name (It is replaced by ERROR:) leading to this bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read salt/modules/supervisord.py around the status parsing and process split, then inspect salt/states/supervisord.py where the process name is used. Reproduce the supervisorctl status output containing a STOPPED process and verify that an already-running first process is recognized as running, with the expected comment rather than being added and started.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.