Skip to content

watch does not trigger service restart if the service is going to be enabled #43922

Closed

Description

@cebe

Description of Issue

from the docs https://docs.saltstack.com/en/2016.11/ref/states/all/salt.states.service.html :

By default if a service is triggered to refresh due to a watch statement the service is by default
restarted. If the desired behavior is to reload the service, then set the reload value to True:

With the following code I'd expect the service to be restarted as soon as the file /etc/neo4j/neo4j.conf changes:

/etc/neo4j/neo4j.conf:
  file.managed:
    - source: salt://neo4j/neo4j.conf
    - require:
      - pkg: neo4j

neo4j_service:
  service.running:
    - name: neo4j
    - enable: True
    - restart: True
    - watch:
        - file: /etc/neo4j/neo4j.conf

What I get however is the following:

----------
          ID: /etc/neo4j/neo4j.conf
    Function: file.managed
      Result: True
     Comment: File /etc/neo4j/neo4j.conf updated
     Started: 15:16:47.625258
    Duration: 26.058 ms
     Changes:
              ----------
              diff:
                  --- 
                  +++ 
                  @@ -51,7 +51,7 @@
                   
                   # With default configuration Neo4j only accepts local connections.
                   # To accept non-local connections, uncomment this line:
                  -#dbms.connectors.default_listen_address=0.0.0.0
                  +dbms.connectors.default_listen_address=0.0.0.0
                   
                   # You can also choose a specific network interface, and configure a non-default
                   # port for each connector, by setting their individual listen_address.
                  @@ -67,19 +67,119 @@
                   
                   # Bolt connector
                   dbms.connector.bolt.enabled=true
                  -#dbms.connector.bolt.tls_level=OPTIONAL
                  -#dbms.connector.bolt.listen_address=:7687
                  +dbms.connector.bolt.tls_level=DISABLED
                  +dbms.connector.bolt.listen_address=0.0.0.0:7687
...
----------
          ID: neo4j_service
    Function: service.running
        Name: neo4j
      Result: True
     Comment: Service neo4j has been enabled, and is in the desired state
     Started: 15:16:47.708318
    Duration: 5433.864 ms
     Changes:
              ----------
              neo4j:
                  True
----------

The service gets enabled but is not restarted. It works fine on the second run when the file has changed, i.e. when the service is already enabled and running, it is restarted.

Versions Report

I am using salt-ssh:

$ salt-ssh --versions-report
Salt Version:
           Salt: 2016.11.2
 
Dependency Versions:
           cffi: 0.8.6
       cherrypy: Not Installed
       dateutil: 2.2
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.3
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.0
   msgpack-pure: Not Installed
 msgpack-python: 0.4.2
   mysql-python: Not Installed
      pycparser: 2.10
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.9 (default, Jun 29 2016, 13:08:31)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: Not Installed
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.4.2
            ZMQ: Not Installed
 
System Versions:
           dist: debian 8.9 
        machine: x86_64
        release: 3.16.0-4-amd64
         system: Linux
        version: debian 8.9 
 

Activity

  1. gtmanfred commented on Oct 5, 2017

    @gtmanfred
    Contributor

    I am unable to replicate this behavior.

    root@eb55aa5d26f2:~# systemctl show -p ActiveEnterTimestamp nginx
    ActiveEnterTimestamp=Thu 2017-10-05 15:37:43 UTC
    root@eb55aa5d26f2:~# salt-call --local state.apply test
    local:
    ----------
              ID: nginx
        Function: pkg.installed
          Result: True
         Comment: Package nginx is already installed
         Started: 15:38:43.035267
        Duration: 912.416 ms
         Changes:
    ----------
              ID: nginx
        Function: file.touch
            Name: /tmp/touched
          Result: True
         Comment: Updated times on file /tmp/touched
         Started: 15:38:43.949969
        Duration: 0.43 ms
         Changes:
                  ----------
                  touched:
                      /tmp/touched
    ----------
              ID: nginx
        Function: service.running
          Result: True
         Comment: Service restarted
         Started: 15:38:43.988974
        Duration: 127.742 ms
         Changes:
                  ----------
                  nginx:
                      True
    
    Summary for local
    ------------
    Succeeded: 3 (changed=2)
    Failed:    0
    ------------
    Total states run:     3
    Total run time:   1.041 s
    root@eb55aa5d26f2:~# systemctl show -p ActiveEnterTimestamp nginx
    ActiveEnterTimestamp=Thu 2017-10-05 15:38:44 UTC
    root@eb55aa5d26f2:~# salt-call --versions-report
    Salt Version:
               Salt: 2016.11.2
    
    Dependency Versions:
               cffi: 0.8.6
           cherrypy: Not Installed
           dateutil: 2.2
              gitdb: Not Installed
          gitpython: Not Installed
              ioflo: Not Installed
             Jinja2: 2.9.4
            libgit2: Not Installed
            libnacl: Not Installed
           M2Crypto: Not Installed
               Mako: Not Installed
       msgpack-pure: Not Installed
     msgpack-python: 0.4.2
       mysql-python: 1.2.3
          pycparser: 2.10
           pycrypto: 2.6.1
             pygit2: Not Installed
             Python: 2.7.9 (default, Jun 29 2016, 13:08:31)
       python-gnupg: Not Installed
             PyYAML: 3.11
              PyZMQ: 14.4.0
               RAET: Not Installed
              smmap: Not Installed
            timelib: Not Installed
            Tornado: 4.2.1
                ZMQ: 4.0.5
    
    System Versions:
               dist: debian 8.9
            machine: x86_64
            release: 4.4.89-boot2docker
             system: Linux
            version: debian 8.9
    
    

    Does the neo4j service use a systemd service unit? or is it using the sysvinit compatibility layer?\

    If it uses the sysvinit compatiblity layer would you be able to provide me a full set of states to get neo4j installed like you have it so that I can test?

    Thanks,
    Daniel

  2. added
    needs-more-info
    on Oct 5, 2017
  3. added this to the Blocked milestone on Oct 5, 2017
  4. cebe commented on Oct 5, 2017

    @cebe
    ContributorAuthor

    Does the neo4j service use a systemd service unit? or is it using the sysvinit compatibility layer?\

    its is systemd on debian 9.0 (stretch)

    # systemctl status neo4j
    * neo4j.service - Neo4j Graph Database
       Loaded: loaded (/lib/systemd/system/neo4j.service; enabled; vendor preset: enabled)
       Active: active (running) since Thu 2017-10-05 09:34:57 UTC; 9h ago
    
    # cat /lib/systemd/system/neo4j.service
    [Unit]
    Description=Neo4j Graph Database
    After=network.target
    
    [Service]
    ExecStart=/usr/share/neo4j/bin/neo4j console
    Restart=on-failure
    User=neo4j
    Group=neo4j
    Environment="NEO4J_CONF=/etc/neo4j" "NEO4J_HOME=/var/lib/neo4j"
    LimitNOFILE=60000
    TimeoutSec=120
    
    [Install]
    WantedBy=multi-user.target
    

    I'll prepare the complete set of states for you.

  5. cebe commented on Oct 5, 2017

    @cebe
    ContributorAuthor

    Files are in the following gist: https://gist.github.com/cebe/cc1038a630b00d4576691fc5fa689cc3

    You can clone them via

    git clone https://gist.github.com/cebe/cc1038a630b00d4576691fc5fa689cc3 neo4j
    

    The state to apply is neo4j by default, you need to adjust the reference to the config file if you put it in another place in the state file hiearchie.

  6. gtmanfred commented on Oct 5, 2017

    @gtmanfred
    Contributor

    It looks like that this is just cosmetic, and reporting the wrong comment. The service is getting restarted, as you can see from the systemctl show -p ActiveEnterTimestamp neo4j

    root@salt:~# cat /srv/salt/neo4j.sls
    neo4j_keys:
      cmd.run:
        - name: wget -O - https://debian.neo4j.org/neotechnology.gpg.key | apt-key add -
        - unless: apt-key list |grep -i neo4j
    
    neo4j_repo:
      pkgrepo.managed:
        - humanname: Neo4j Official Debian Repository
        - name: deb https://debian.neo4j.org/repo stable/
        - file: /etc/apt/sources.list.d/neo4j.list
        - key: 26C95CF201182252
        - keyserver: keyserver.ubuntu.com
        - keyurl: https://debian.neo4j.org/neotechnology.gpg.key
        - require:
          - cmd: neo4j_keys
    
    neo4j:
      pkg.installed:
        - version: '3.2.1*'
        - require:
          - pkgrepo: neo4j_repo
    
    /etc/neo4j/neo4j.conf:
      file.managed:
        - source: salt://neo4j.conf
        - require:
          - pkg: neo4j
    
    neo4j_service:
      service.running:
        - name: neo4j
        - enable: True
        - restart: True
        - watch:
            - file: /etc/neo4j/neo4j.conf
    root@salt:~# systemctl show -p ActiveEnterTimestamp neo4j
    ActiveEnterTimestamp=Thu 2017-10-05 22:46:51 UTC
    root@salt:~# echo >> /etc/neo4j/neo4j.conf
    root@salt:~# salt-call --local state.apply neo4j
    local:
    ----------
              ID: neo4j_keys
        Function: cmd.run
            Name: wget -O - https://debian.neo4j.org/neotechnology.gpg.key | apt-key add -
          Result: True
         Comment: unless execution succeeded
         Started: 22:47:38.927271
        Duration: 118.596 ms
         Changes:
    ----------
              ID: neo4j_repo
        Function: pkgrepo.managed
            Name: deb https://debian.neo4j.org/repo stable/
          Result: True
         Comment: Package repo 'deb https://debian.neo4j.org/repo stable/' already configured
         Started: 22:47:39.058561
        Duration: 25.0 ms
         Changes:
    ----------
              ID: neo4j
        Function: pkg.installed
          Result: True
         Comment: The following packages were installed/updated: neo4j=3.2.1*
         Started: 22:47:39.469233
        Duration: 10618.404 ms
         Changes:
    ----------
              ID: /etc/neo4j/neo4j.conf
        Function: file.managed
          Result: True
         Comment: File /etc/neo4j/neo4j.conf updated
         Started: 22:47:50.089446
        Duration: 13.074 ms
         Changes:
                  ----------
                  diff:
                      ---
                      +++
                      @@ -317,4 +317,3 @@
                       # Other Neo4j system properties
                       #********************************************************************
                       dbms.jvm.additional=-Dunsupported.dbms.udc.source=debian
                      -
    ----------
              ID: neo4j_service
        Function: service.running
            Name: neo4j
          Result: True
         Comment: Service neo4j is already enabled, and is running
         Started: 22:47:50.103156
        Duration: 188.364 ms
         Changes:
                  ----------
                  neo4j:
                      True
    
    Summary for local
    ------------
    Succeeded: 5 (changed=2)
    Failed:    0
    ------------
    Total states run:     5
    Total run time:  10.963 s
    root@salt:~# systemctl show -p ActiveEnterTimestamp neo4j
    ActiveEnterTimestamp=Thu 2017-10-05 22:47:51 UTC
    root@salt:~#
    

    after the state run, with the neo4j.conf config file changing, the timestamp for when the service started has been updated.

  7. added
    bug
    Core
    severity-low
    P3
    and removed
    needs-more-info
    on Oct 5, 2017
  8. modified the milestones: Blocked, Approved on Oct 5, 2017
  9. cebe commented on Oct 6, 2017

    @cebe
    ContributorAuthor

    need to try that again, because the "restart" through salt does not have any effect regarding the config changes. i.e. neo4j is still listening on the old ports, not the ones in the new config. Only manual restart makes the config changes take effect.

  10. stale commented on Feb 7, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CoreP3bugseverity-lowstale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions