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

Incorrect dependency on multi-user.target causes dependency loop for systemd

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 4.0.11
    • Component/s: None
    • None
    • ALL

      Hello!

      I noticed quite serious issue in your official systemd unit file for MongoDB 4.0.11 in Ubuntu 18.04.

      Your current systemd unit file looks like:

      [Unit]
      Description=MongoDB Database Server
      After=multi-user.target
      Documentation=https://docs.mongodb.org/manual[Service]
      User=mongodb
      Group=mongodb
      EnvironmentFile=-/etc/default/mongod
      ExecStart=/usr/bin/mongod --config /etc/mongod.conf
      PIDFile=/var/run/mongodb/mongod.pid
      # file size
      LimitFSIZE=infinity
      # cpu time
      LimitCPU=infinity
      # virtual memory size
      LimitAS=infinity
      # open files
      LimitNOFILE=64000
      # processes/threads
      LimitNPROC=64000
      # locked memory
      LimitMEMLOCK=infinity
      # total threads (user+kernel)
      TasksMax=infinity
      TasksAccounting=false# Recommended limits for for mongod as specified in
      # http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings[Install]
      WantedBy=multi-user.target
      

      You may notice two following sections:

      After=multi-user.target
      ...
      [Install]
      WantedBy=multi-user.target

      First "After" is not required at all. Systemd will run service on multi-user.target level because you have correct configuration in "Install" section.

      And this "After=multi-user.target" dependency causes serious problems for any service which runs on same run level but requires mongodb because it creates dependency cycle which prevents proper loading of application which depend on MongoDB.

      It may happen with any application which configured this way:

      [Unit]
      Description=App with MongoDB dependency 
      After=mongod.service
       
      [Service]
      Type=forking
      ExecStart=...
      PIDFile=...
       
      [Install]
      WantedBy=multi-user.target
      

      It will cause following issues from systemd perspective:

      [    3.649328] systemd[1]: multi-user.target: Found ordering cycle on app.service/start
      [    3.658031] systemd[1]: multi-user.target: Found dependency on mongod.service/start
      [    3.665973] systemd[1]: multi-user.target: Found dependency on multi-user.target/start
      [    3.674482] systemd[1]: multi-user.target: Job app.service/start deleted to break ordering cycle starting with multi-user.target/start
      

      Please check this issue. It's quite serious one because it causes issues for any application which depends on MongoDB.

            Assignee:
            Unassigned Unassigned
            Reporter:
            pavel.odintsov Pavel Odintsov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: