Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-28035

Debian Jessie systemd service not handled correctly

    • Server Development Platform
    • ALL
    • Hide

      Installation :
      Fresh install of Debian jessie

      sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
      echo "deb http://repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
      sudo apt-get install -y mongodb-org
      mongo
      

      See attachment file install.txt.

      Deinstallation : (whith mongo manualluy enabled) :

      sudo systctl enable mongod.service
      sudo systemctl enable mongod.service
      sudo systemctl start mongod.service
      mongo
      sudo apt-get remove --purge mongodb-org-server
      mongo
      

      See attachement file deinstall.txt

      Show
      Installation : Fresh install of Debian jessie sudo apt-key adv --keyserver hkp: //keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 echo "deb http: //repo.mongodb.org/apt/debian jessie/mongodb-org/3.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list sudo apt-get install -y mongodb-org mongo See attachment file install.txt. Deinstallation : (whith mongo manualluy enabled) : sudo systctl enable mongod.service sudo systemctl enable mongod.service sudo systemctl start mongod.service mongo sudo apt-get remove --purge mongodb-org-server mongo See attachement file deinstall.txt

      Hi,

      On a Debian Jessie fresh install, mongodb service is not enabled with systemd, thus it does not start after installation or boot time.

      user@sandbox:~$ systemctl list-unit-files --type=service |grep mongo
      mongod.service                         disabled
      

      The package mongodb-org-server comes with the mongod.service file :

      dpkg -L mongodb-org-server
      /.
      ------8<----------------
      /lib
      /lib/systemd
      /lib/systemd/system
      /lib/systemd/system/mongod.service
      

      But the postinst script of the package does not call for systemctl to enable this service :

      #!/bin/sh
      # postinst script for mongodb
      #
      # see: dh_installdeb(1)
      
      set -e
      
      # summary of how this script can be called:
      #        * <postinst> `configure' <most-recently-configured-version>
      #        * <old-postinst> `abort-upgrade' <new version>
      #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
      #          <new-version>
      #        * <postinst> `abort-remove'
      #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
      #          <failed-install-package> <version> `removing'
      #          <conflicting-package> <version>
      # for details, see http://www.debian.org/doc/debian-policy/ or
      # the debian-policy package
      
      
      case "$1" in
          configure)
      	# create a mongodb group and user
              if ! getent passwd mongodb >/dev/null 2>&1; then
      		adduser --system --no-create-home mongodb
      		addgroup --system mongodb
      		adduser mongodb mongodb
              fi
      
      	# create db -- note: this should agree with dbpath in mongod.conf
      	mkdir -p /var/lib/mongodb
      	chown -R mongodb:mongodb /var/lib/mongodb
      
      	# create logdir -- note: this should agree with logpath in mongod.conf
      	mkdir -p /var/log/mongodb
      	chown -R mongodb:mongodb /var/log/mongodb
          ;;
      
          abort-upgrade|abort-remove|abort-deconfigure)
          ;;
      
          *)
              echo "postinst called with unknown argument \`$1'" >&2
              exit 1
          ;;
      esac
      
      # dh_installdeb will replace this with shell code automatically
      # generated by other debhelper scripts.
      
      # Automatically added by dh_installinit
      if [ -x "/etc/init.d/mongod" ]; then
      	update-rc.d mongod defaults >/dev/null
      	invoke-rc.d mongod start || exit $?
      fi
      # End automatically added section
      
      
      exit 0
      

      It only tests for the existence of sysvinit script, not for the systemd one.
      This lead to mongod not running after installation or system reboot on Debian Jessie and perhaps on other systems.

      You might consider adding the same thing for systemd in the postinst script, like :

      +if [ -f "/lib/systemd/system/mongod.service" ]; then
      +        systemctl --system daemon-reload >/dev/null || true
      +	systemctl enable mongod.service >/dev/null
      +	systemctl start mongod.service|| exit $?
      +fi
      

      Things are getting worse while removing mongodb-org-server package, the mongod service is not stopped while it is removed :

      user@sandbox:~$ sudo apt-get remove --purge mongodb-org-server
      Reading package lists... Done
      Building dependency tree
      Reading state information... Done
      The following packages were automatically installed and are no longer required:
        mongodb-org-mongos mongodb-org-shell mongodb-org-tools
      Use 'apt-get autoremove' to remove them.
      The following packages will be REMOVED:
        mongodb-org* mongodb-org-server*
      0 upgraded, 0 newly installed, 2 to remove and 22 not upgraded.
      After this operation, 54.5 MB disk space will be freed.
      Do you want to continue? [Y/n]
      (Reading database ... 40192 files and directories currently installed.)
      Removing mongodb-org (3.4.2) ...
      Purging configuration files for mongodb-org (3.4.2) ...
      dpkg: warning: while removing mongodb-org, directory '/var/lib/mongodb' not empty so not removed
      Removing mongodb-org-server (3.4.2) ...
      Purging configuration files for mongodb-org-server (3.4.2) ...
      Processing triggers for man-db (2.7.0.2-5) ...
      user@sandbox:~$ mongo
      MongoDB shell version v3.4.2
      connecting to: mongodb://127.0.0.1:27017
      MongoDB server version: 3.4.2
      Server has startup warnings:
      2017-02-17T15:14:31.249+0100 I STORAGE  [initandlisten]
      2017-02-17T15:14:31.249+0100 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
      2017-02-17T15:14:31.249+0100 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten]
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten]
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten]
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
      2017-02-17T15:14:31.917+0100 I CONTROL  [initandlisten]
      >
      
      

      The prerm script of the package is lacking the stop action for systemd and manage only sysvinit script :

      cat prerm 
      #!/bin/sh
      set -e
      # Automatically added by dh_installinit
      if [ -x "/etc/init.d/mongod" ]; then
      	invoke-rc.d mongod stop || exit $?
      fi
      # End automatically added section
      

      You might add something like this to stop the service and disable it before removing the file /lib/systemd/system/mongod.service (which actually do a broken link on the sytem) :

      +if [ -f "/lib/systemd/system/mongod.service" ]; then
      +	systemctl stop mongod.service|| exit $?
      +      systemctl disable mongod.service > /dev/null
      +fi
      

      And, actually the postrm script seems to be fine.

      I have seen this issue on 3.2.9 version and 3.4.2 version of mongodb-org-server package on Debian Jessie. It should affect every version between them.

      Regards.
      F.

        1. deinstall.txt
          4 kB
        2. install.txt
          3 kB

            Assignee:
            backlog-server-devplatform [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
            Reporter:
            fcauvet franck cauvet
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: