saltstack-formulas / mongodb-formula

Home Page:http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] service not launched on install

ze42 opened this issue · comments

commented

Your setup

Formula commit hash / release tag

based on dd8a5aa

Versions reports (master & minion)

[old, but not related]

Distribution: Debian/buster

Pillar / config used

[probably not relevant]

Bug details

Describe the bug

On installation (using repository), the service is not launched.

The formula contains:

  service.running:
    - name: {{ servicename }}
    - enable: True
    - onlyif: systemctl list-units | grep {{ servicename }} >/dev/null 2>&1

Steps to reproduce the bug

Install. Have the service not launched, and state.apply

Expected behaviour

Service should be launched, to ensure it is running.

Attempts to fix the bug

Removing the onlyif would start the service.

Additional context

The following command only shows something if the service is started. Stopping the service, and the command would not show anything anymore.

systemctl list-units | grep mongod
commented

No, the command lists service files in /usr/lib/systemd and then does a grep to see if mongod service file was installed.

commented

That is not what I see.

~# service mongod start
~# systemctl list-units | grep mongod
mongod.service                                   loaded active running   MongoDB Database Server                                           
~# service mongod stop
~# systemctl list-units | grep mongod
~# service mongod start
~# systemctl list-units | grep mongod
mongod.service                                   loaded active running   MongoDB Database Server                                           
~# service mongod stop
~# systemctl list-units | grep mongod
~# cat /etc/debian_version 
10.9
~# dpkg -l | grep mongo
ii  mongodb-database-tools                        100.3.1                             amd64        mongodb-database-tools package provides tools for working with the MongoDB server: 
ii  mongodb-org                                   4.4.6                               amd64        MongoDB open source document-oriented database system (metapackage)
ii  mongodb-org-database-tools-extra              4.4.6                               amd64        Extra MongoDB database tools
ii  mongodb-org-mongos                            4.4.6                               amd64        MongoDB sharded cluster query router
ii  mongodb-org-server                            4.4.6                               amd64        MongoDB database server
ii  mongodb-org-shell                             4.4.6                               amd64        MongoDB shell client
ii  mongodb-org-tools                             4.4.6                               amd64        MongoDB tools
~# find /etc/systemd/ /usr/lib/systemd/ /lib/systemd/ -name '*mongo*'
/etc/systemd/system/multi-user.target.wants/mongod.service
/usr/lib/systemd/system/mongod.service
/lib/systemd/system/mongod.service
~# 
commented

Ahh ... it should be systemctl list-unit-files | grep mongo...

       list-unit-files [PATTERN...]
           List unit files installed on the system, in combination with
           their enablement state (as reported by is-enabled). If one or
           more PATTERNs are specified, only unit files whose name
           matches one of them are shown (patterns matching unit file
           system paths are not supported)."
   -a, --all
       When listing units with list-units, also show inactive units
       and units which are following other units. When showing
       unit/job/manager properties, show all properties regardless
       whether they are set or not.

       To list all units installed in the file system, use the
       list-unit-files command instead.
commented

Yup, guess replacing list-units by list-unit-files should do the trick.

~# systemctl list-unit-files | grep mongod
mongod.service enabled
~# service mongod start
~# systemctl list-unit-files | grep mongod
mongod.service enabled
~# 

I'm seeing the same behaviour with service not running after running the formula code.
But I don't understand why the onlyif is used in the service state. Is there any case where the package is installed but not systemd unit?