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

Supervisord is considered as "systemd" in grains #37187

Closed
ben-ballot opened this issue Oct 24, 2016 · 5 comments
Closed

Supervisord is considered as "systemd" in grains #37187

ben-ballot opened this issue Oct 24, 2016 · 5 comments
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Grains P4 Priority 4 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@ben-ballot
Copy link
Contributor

ben-ballot commented Oct 24, 2016

Description of Issue/Question

Using supervisord as pid 1 in a docker container fill grains['init'] with "systemd" value

root@b9e49580d089:/# salt-call --local -l quiet grains.item init local: ---------- init: systemd

Setup

Use a Dockerfile as this

FROM ubuntu:trusty

RUN apt-get update \
 && apt-get install -y apt-transport-https ca-certificates curl supervisor

RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D \
 && curl -L https://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -

CMD ["/usr/bin/supervisord","-c","/etc/supervisor/supervisord.conf"]
RUN mkdir -p /etc/supervisor
ADD dockerfiles/trusty/supervisord.conf /etc/supervisor/supervisord.conf
ADD tools/supervisord_minion.conf /etc/supervisor/conf.d/salt-minion.conf
RUN apt-get -y install \
 python-apt \
 python-git \
 python-pip \
 salt-minion \
 virt-what

Here is the supervisord.conf files
/etc/supervisor/supervisord.conf

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10          ; (num of main logfile rotation backups;default 10)
loglevel=info               ; (logging level;default info; others: debug,warn)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true              ; (start in foreground if true;default false)
minfds=1024                 ; (min. avail startup file descriptors;default 1024)
minprocs=200                ; (min. avail process descriptors;default 200)

[unix_http_server]
file=/var/tmp/supervisor.sock
username=setup
password=setup

[supervisorctl]
serverurl=unix:///var/tmp/supervisor.sock ; use a unix:// URL  for a unix socket
username=setup
password=setup

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[include]
files = /etc/supervisor/conf.d/*.conf

/etc/supervisor/conf.d/salt-minion.conf

[program:salt-minion]
command=/usr/bin/salt-minion -l debug

Then start the docker.

Steps to Reproduce Issue

By extracting the relevant code in grains.core.py as following I can see that systemd comes out

import salt.utils
import os
import salt.ext.six as six
import salt.config
import salt.loader
__opts__ = salt.config.minion_config('/etc/salt/minion')

grains = {
    'num_gpus': 0,
    'gpus': [],
}


try:
    os.stat('/run/systemd/system')
    grains['init'] = 'systemd'
except (OSError, IOError):
    if os.path.exists('/proc/1/cmdline'):
        with salt.utils.fopen('/proc/1/cmdline') as fhr:
            init_cmdline = fhr.read().replace('\x00', ' ').split()
            init_bin = salt.utils.which(init_cmdline[0])
            if init_bin is not None:
                supported_inits = (six.b('upstart'), six.b('sysvinit'), six.b('systemd'))
                edge_len = max(len(x) for x in supported_inits) - 1
                try:
                    buf_size = __opts__['file_buffer_size']
                except KeyError:
                    # Default to the value of file_buffer_size for the minion
                    buf_size = 262144
                try:
                    with salt.utils.fopen(init_bin, 'rb') as fp_:
                        buf = True
                        edge = six.b('')
                        buf = fp_.read(buf_size).lower()
                        while buf:
                            buf = edge + buf
                            for item in supported_inits:
                                if item in buf:
                                    if six.PY3:
                                        item = item.decode('utf-8')
                                    grains['init'] = item
                                    buf = six.b('')
                                    break
                            edge = buf[-edge_len:]
                            buf = fp_.read(buf_size).lower()
                except (IOError, OSError) as exc:
                    log.error(
                        'Unable to read from init_bin ({0}): {1}'
                        .format(init_bin, exc)
                    )
            else:
                log.error(
                    'Could not determine init location from command line: ({0})'
                    .format(' '.join(init_cmdline))
                )

You can see that the condition "if item in buf:" is triggered with the result being systemd

/proc/1/cmdline looks like this :

root@b9e49580d089:/# cat /proc/1/cmdline 
/usr/bin/python/usr/bin/supervisord-c/etc/supervisor/supervisord.conf

Versions Report

root@b9e49580d089:/# salt-call --local -l quiet --versions-report
Salt Version:
           Salt: 2016.3.3

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 0.9.1
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.0.1
           RAET: Not Installed
          smmap: 0.8.2
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 4.2.0-42-generic
         system: Linux
        version: Ubuntu 14.04 trusty
@Ch3LL
Copy link
Contributor

Ch3LL commented Oct 24, 2016

@darkalia looks like i'm able to replicate this behavior. I did have to edit the docker file a bit to install 2016.3.3:

FROM ubuntu:trusty

RUN apt-get update \
 && apt-get install -y apt-transport-https ca-certificates curl supervisor

RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D \
 && curl -L https://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add -

RUN echo "deb http://repo.saltstack.com/apt/ubuntu/14.04/amd64/latest trusty main" >> /etc/apt/sources.list


CMD ["/usr/bin/supervisord","-c","/etc/supervisor/supervisord.conf"]
RUN mkdir -p /etc/supervisor
ADD dockerfiles/trusty/supervisord.conf /etc/supervisor/supervisord.conf
ADD tools/supervisord_minion.conf /etc/supervisor/conf.d/salt-minion.conf
RUN apt-get update
RUN apt-get -y install \
 python-apt \
 python-git \
 python-pip \
 salt-minion \
 virt-what

Looks like we need to detect for supervisord

@Ch3LL Ch3LL added Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around Core relates to code central or existential to Salt P4 Priority 4 Grains labels Oct 24, 2016
@Ch3LL Ch3LL added this to the Approved milestone Oct 24, 2016
@ben-ballot
Copy link
Contributor Author

ben-ballot commented Oct 25, 2016

Thanks.
I would suggest opening the binary for the search only if it's '*/init'.
This occurs because python interpreter is searched and happens to return 'systemd' first.
On a side node, searching for 'supervisord' in the cmdline would make sense if there is a plan to support supervisord services through the usual salt.modules.service

May I propose a patch ?

ben-ballot added a commit to ben-ballot/salt that referenced this issue Oct 25, 2016
@ben-ballot
Copy link
Contributor Author

PR proposed on 2015.5 branch (the oldest I found relevant) : #37214

@ben-ballot
Copy link
Contributor Author

New PR for 2016.3 as requested.

cachedout pushed a commit that referenced this issue Oct 26, 2016
Issue #37187 Do not parse first /proc/1/cmdline binary if it's not *b…
gitebra pushed a commit to gitebra/salt that referenced this issue Oct 26, 2016
* upstream/develop:
  Update release notes and version added
  Add ability to specify disk backing mode for VMware cloud profile
  Update bootstrap release to 2016.10.25
  fix run_cloud timeout
  change timeout for cloud tests
  modules.win_system.py: Fix flag disabling AD Computer objects
  Update configuration examples for Joyent
  Issue saltstack#37187 Do not parse first /proc/1/cmdline binary if it's not *bin/init and set supervisord
  use salt utils for file handling
  Do not prematurily raise an exception, let the main loop take care of it instead
  Do not restart the whole thing if roster is not around
  Fix PEP8
  changed the way filter is taken for get-config and changed state file to reflect change of call_rpc to rpc
  Changed the name of call_rpc to rpc and changed the way rpc call is made
  Allow junos versions older than 14.2 to run junos.call_rpc. Fix version_info in junos grains
@rallytime
Copy link
Contributor

Thank you for submitting this fix @darkalia. I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Grains P4 Priority 4 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

3 participants