How to stop default/initial started services

Hi,

We’re using docker to start some backend services and we were running out of memory.
Is it possible to properly stop initial circleci services like mysql/postgresql/mongodb ? Doing sudo service <name> stop seems not enough as the service is still running during the test step and so for now we have to delete the binary of these services to make sure their are not restarted…
That’s why we’ll like to know how to stop initial services in a clean way.

Thanks,

Matthieu

1 Like

I am also interested in knowing how to turn off default services.

I’m currently blocked due to mongodb restarting during the test step. Can anyone at Circle please provide some guidance here?

Snippets or whole circle.yml files are really useful in order to provide help. Where and how are you trying to stop these services currently?

Thanks for the reply, @FelicianoTech. I started by trying the method proposed by @frank in https://discuss.circleci.com/t/cant-start-mongo-container-as-it-conflicts-with-some-other-mongo-service/1628:

machine:
  post:
    - sudo service mongodb stop

Note that it actually must be mongod as opposed to mongodb.

I’ve also tried sudo killall mongod, and I’ve tried a combination of both commands in the machine and test sections to the same effect - the service does indeed stop, but by the time I get to the test section, there seems to be a 50% chance that /usr/bin/mongod --config /etc/mongod.conf is running again.

The only way thus far that I’ve successfully worked around this is by changing my mongo containers’ host ports to something other than 27017.

I’m running on Ubuntu 14.04.

Can you try stopping it in the test section? For example:

test
  pre:
    - sudo service mongodb stop; sleep 5

Then start whatever needs that port after that line?

@FelicianoTech that seems to have worked, thank you.

However, it must be noted that the service is mongod as opposed to mongodb.

test
  pre:
    - sudo service mongod stop; sleep 5
  override:
    - ps aux
    - docker-compose up -d
    - run tests

EDIT: turns out this may not be true, actually. With the above setup after stopping mongod, I’m seeing the process pop up in later steps.

Stop mongod:

ps aux shows the process has returned:

…and thus my network issue returns, and I’m unable to start my mongod container:

failed to create endpoint database_1 on network bridge: listen tcp 0.0.0.0:27017: bind: address already in use

Okay here we go. Right before the line sudo service mongod stop put this line echo "manual" | sudo tee /etc/init/mongod. That will prevent MongoDB from being started up again after it is stopped.

Thanks @FelicianoTech. FWIW I’m still working around with different mongo container ports as that solves more than 1 problem for me.

Appreciate the responses. :+1:

Feliciano almost hit the spot. What worked for me was to put this line

echo "manual" | sudo tee /etc/init/mongod.override

Right before the sudo service mongod stop.