[SERVER-28525] SystemD services depending on mongod will be started before mongo is ready to take connections Created: 28/Mar/17  Updated: 21/Sep/17  Resolved: 07/Apr/17

Status: Closed
Project: Core Server
Component/s: Packaging
Affects Version/s: 3.4.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Stephen Lynx Assignee: Mark Agarunov
Resolution: Done Votes: 0
Labels: init-script, systemd
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Centos 7.


Issue Links:
Related
is related to SERVER-31206 SystemD services depending on mongod ... Closed
Operating System: ALL
Steps To Reproduce:

Make a systemD script that is set to start after mongod.
When the service is started, mongo won't be ready yet to take connections, causing the service to fail if it depends on that.

Participants:

 Description   

I have the following systemD script for my software:

[Unit]
Description=LynxChan
After=mongod.service
 
[Service]
ExecStart=/usr/bin/lynxchan
User=node
StandardOutput=syslog
Restart=on-abort
 
[Install]
WantedBy=multi-user.target

See "After=mongod.service". Because of that, my software expects mongo to be ready to take connections when it is booted by this init script.

However, for 3.4, mongo is not ready yet to take connections when my software runs.

I just tested with 3.2 and everything works as expected, my service is always able to connect to mongo when the system boots.



 Comments   
Comment by Stephen Lynx [ 08/Sep/17 ]

Changed my init script to

[Unit]
Description=LynxChan
After=mongod.service
Wants=mongod.service
 
[Service]
ExecStart=/usr/bin/lynxchan
User=sergio
StandardOutput=syslog
Restart=on-abort
 
[Install]
WantedBy=multi-user.target

Still not starting on boot.

Comment by Mark Agarunov [ 04/Apr/17 ]

Hello stephenlynx,

Looking over the unit file you've provided, you may get the desired behavior by adding Requires=mongod.service or Wants=mongod.service to the [Unit] section of your service. The systemd documentation has a bit more info on these parameters.

Thanks,
Mark

Comment by Ramon Fernandez Marina [ 04/Apr/17 ]

Thanks for your report stephenlynx, we can reproduce the behavior you describe and are investigating.

Generated at Thu Feb 08 04:18:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.