My problem is simple yet the solution isn't easily found.
On my server I've had mongodb running for a few months and suddenly it stopped working. I start mongodb using $ systemctl start mongodb but it doesn't work anymore.
The response I get when I run $ systemctl status mongodb is:
Active: failed
Process: ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
(code=exited, status=100)
What could it be? I've got a back-up of .ns and .0/.1/.2 files.
Related
Have a CentOS7 Linux machine running (not managed by me; have limited rights to/in it).
Have a request to set PostgreSQL up in it.
Just installed PostgreSQL from the CentOS repository:
sudo yum install postgresql-server postgresql-contrib
All good with it.
Then did initialization of the database:
sudo yum install postgresql-server postgresql-contrib
All good with it.
But then the start:
sudo systemctl start postgresql
Fails:
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.
I do not have access to systemd-journal so nothing tod with "journalctl -xe", but then the:
systemctl status postgresql.service
returns:
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2020-04-24 16:41:04 EEST; 33s ago
Process: 30690 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=1/FAILURE)
Process: 30684 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
postgres --version
postgres (PostgreSQL) 9.2.24
Any ideas what could be wrong here? Hot to continue with that?
As the echo $PGDATA shows you have PG9.3 as well. Which means that 9.2 service will not start because the port 5432 might be already occupied by postgres 9.3
Do the following
ps- ef | grep postgres
And get the postgres process id and kill all postgres processes.
Remove the 9.3 data directory using
rm -rf /var/lib/pgsql/9.3
Go to /usr/pgsql-9.2/bin and run the initdb using below command
./postgresql92-setup initdb
After that start the postgresql-9.2 service using
systemctl start postgresql-9.2.service
There must be both PostgreSQL 9.2 and 9.3 installed on your machine. Deinstall them both and install version 12 from the PostgreSQL site. Remove the data directory and create a new one with the v12 installation. Then try again.
After install mongodb on CentOS, I'm typingthe command systemctl status mongod, but the following problem appears (also see picture):
systemctl status mongod ● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled;
vendor preset: disabled) Active: failed (Result: exit-code) 02-28
20:17:01 CST; Process: 3558 ExecStart=/usr/bin/mongod $OPTIONS
(code=exited, status=2) Process: 3556 ExecStartPre=/usr/bin/chmod 0755
/var/run/mongodb (code=exited, status=0/SUCCESS) Process: 3554
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
(code=exited, status=0/SUCCESS) Process: 3547
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited,
status=0/SUCCESS)
Thank you so much for reading my problem. If you can help me solve the problem, I will appreciate it very much.
Figure
This happends often when you started the service as a different user.
Follow this:
- try first stoping the service.
sudo systemctl stop mongod
then remove this file:
sudo rm /tmp/mongodb-27017.sock
restart mongodb service
sudo systemctl start mongod
if that doesnt do it, i would suggest to remove mongodb and follow this guide: (it worked for me perfectly on CentOS 7)
try installing mongodb like this:
Create a /etc/yum.repos.d/mongodb-org-4.2.repo file so that you can install MongoDB directly using yum:
sudo vi /etc/yum.repos.d/mongodb-org.repo
Paste this inside the mongodb-org.repo
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
verify that the MongoDB repository exists
yum repolist
Installing mongodb
sudo yum install mongodb-org
Start the mongodb service:
sudo systemctl start mongod
The reload command requests that the mongod process reads the configuration file, /etc/mongod.conf, and applies any changes without requiring a restart
sudo systemctl reload mongod
try access the database server with the MongoDB Shell:
mongo
this helped me allot on centos7,
let me know if you need anything else.
cheers,
Radi
I have followed all the answers mentioned in stackoverflow still ima getting the same error as Failed to start mongod.service: Unit mongod.service not found.
how to solve this ?
i have ubuntu cosmic and mongoDB version 3.0
I've faced the some issue.
here the solution
please check that you have the configuration file for MongoDB mongodb.service in the main directory /etc/systemd/system/
if you couldn't found it just create it with
sudo vi /etc/systemd/system/mongodb.service
then add the following content to the file
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
Run the mongod service
sudo systemctl start mongodb
sudo systemctl status mongodb
Make the service permanent
sudo systemctl enable mongodb
Have you tried sudo service mongod start
I have following the instruction from this link
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
And when I'm going to
sudo service mongod start
it's shown as unrecognized service
I have known that I may need to use mongodb instead of mongod, but it's the same.
Then I have checked all services list by
service --status-all
There's no mongodb-related service in the list
I have reinstall it again and it's the same. I have also searched through the internet and I cannot find the solution. I install on Windows's ubuntu bash. I have reinstall bash once before this issue (14.04 to 16.04). Last time I installed it before I reinstalled bash it work just fine.
Thank you in advance for your answers.
I faced the same issue. I don't know the reason and solution but you can check the status of mongo itself by this command:
sudo service mongod status
You may see something like this output:
root#lab# service mongod status
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Fri 2018-04-06 09:47:57 BST; 1min 31s ago
Docs: https://docs.mongodb.org/manual
Main PID: 5973 (mongod)
CGroup: /system.slice/mongod.service
└─5973 /usr/bin/mongod --quiet --config /etc/mongod.conf
I ran MongoDB in background in the Ubuntu server with the following command :
mongod --fork --logpath /var/log/mongod.log
But sometimes database crashes and I have to restart manually, my question is how to restart automatically if database crashes ?
I have tried to add in /etc/init/mongodb.conf:
respawn
respawn limit 10 90
But still if I kill monogodb process it haven't started automatically. What is the problem ?
Thanks
Depending what operating system you are using, you should use the packages provided for your distribution at https://docs.mongodb.com/manual/administration/install-on-linux/ and then the start scripts provided.
For ubuntu you need to create the systemd file
If you install the .deb package from the link I provided earlier you can then create a systemd script by doing the following.
Create /etc/systemd/system/mongodb.service with the contents
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
then run
systemctl start mongodb
systemctl enable mongodb
Then you can use systemctl restart mongodb whenever you want to start.