Adding TSL To Mongo causes it to crash - mongodb

I have a 3 mongodb replication architecture up and running. When I add TSL to the /etc/mongod conf file mongod it crashes right away and writes nothing to mongo log. I put the pem file containing all the certs and key in /etc/ssl/mongo.pem with the key at the bottom of the file. I did a chmod 600 on the pem file. I am adding TSL to the primary first and stopping and starting mongod. My mongod TLS config:
net:
port: 27017
bindIpAll: true
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongo.pem
security:
keyFile: /opt/mongod/keyfile
The error I get when starting:
ec2-user#ip-10-0-16-140 log]$ sudo service mongod start
Starting mongod (via systemctl): Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[FAILED]
The return from the status call:
[ec2-user#ip-10-0-16-140 ~]$ systemctl status mongod.service
● mongod.service - SYSV: Mongo is a scalable, document-oriented database.
Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2020-02-28 00:43:51 UTC; 17s ago
Docs: man:systemd-sysv-generator(8)
Process: 18327 ExecStop=/etc/rc.d/init.d/mongod stop (code=exited, status=0/SUCCESS)
Process: 18548 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal runuser[18559]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal runuser[18559]: pam_unix(runuser:session): session closed for user mongod
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal mongod[18548]: Starting mongod: [FAILED]
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=1
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: mongod.service failed.
[ec2-user#ip-10-0-16-140 ~]$ journalctl -xe
Feb 28 00:42:13 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18523]: pam_unix(sudo:session): session closed for user root
Feb 28 00:42:27 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18525]: ec2-user : TTY=pts/0 ; PWD=/home/ec2-user ; USER=root ; COMMAND=/bin/vi /etc/mongo.pem
Feb 28 00:42:27 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18525]: pam_unix(sudo:session): session opened for user root by ec2-user(uid=0)
Feb 28 00:42:31 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18525]: pam_unix(sudo:session): session closed for user root
Feb 28 00:42:38 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18527]: ec2-user : TTY=pts/0 ; PWD=/home/ec2-user ; USER=root ; COMMAND=/bin/vi /etc/ssl/mongo.pem
Feb 28 00:42:38 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18527]: pam_unix(sudo:session): session opened for user root by ec2-user(uid=0)
Feb 28 00:43:38 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18527]: pam_unix(sudo:session): session closed for user root
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18529]: ec2-user : TTY=pts/0 ; PWD=/home/ec2-user ; USER=root ; COMMAND=/sbin/service mongod start
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18529]: pam_unix(sudo:session): session opened for user root by ec2-user(uid=0)
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
-- Subject: Unit mongod.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mongod.service has begun starting up.
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal runuser[18559]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal runuser[18559]: pam_unix(runuser:session): session closed for user mongod
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal mongod[18548]: Starting mongod: [FAILED]
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: mongod.service: control process exited, code=exited status=1
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
-- Subject: Unit mongod.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mongod.service has failed.
--
-- The result is failed.
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: Unit mongod.service entered failed state.
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal systemd[1]: mongod.service failed.
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal sudo[18529]: pam_unix(sudo:session): session closed for user root
Feb 28 00:43:51 ip-10-0-16-140.us-gov-east-1.compute.internal dhclient[2603]: XMT: Solicit on eth0, interval 113300ms.

It can be an issue with your mongodb.pem file. For testing purposes, you can create a self-signed certificate and key like this:
openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key
cat mongodb-cert.key mongodb-cert.crt > mongodb.pem
and then set the permissions on the PEM file, you can use
chmod 600 mongodb.pem
consider the following configuration file for a mongod instance:
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongodb.pem
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb"
processManagement:
fork: true
net:
bindIp: 0.0.0.0
port: 27017
Note: bindIP with 0.0.0.0 is not best practice, but it good place to start
Also, you may find logs in /var/log/mongodb/mongod.log as the default path

Related

Why mongod.service is killed by my system?

I am using MongoDB 4.4 version on ubuntu 20.4, using 2 mongo instances on the same server. I encountered this problem:
Sep 03 10:45:25 mlnode systemd[1]: Stopping MongoDB Database Server...
Sep 03 10:45:25 mlnode systemd[1]: mongod.service: Succeeded.
Sep 03 10:45:25 mlnode systemd[1]: Stopped MongoDB Database Server.
Sep 03 10:45:25 mlnode systemd[1]: Started MongoDB Database Server.
Sep 03 10:55:46 mlnode systemd[1]: Stopping MongoDB Database Server...
Sep 03 10:55:46 mlnode systemd[1]: mongod.service: Succeeded.
Sep 03 10:55:46 mlnode systemd[1]: Stopped MongoDB Database Server.
Sep 03 10:55:46 mlnode systemd[1]: Started MongoDB Database Server.
Sep 03 11:05:05 mlnode systemd[1]: Stopping MongoDB Database Server...
Sep 03 11:05:05 mlnode systemd[1]: mongod.service: Succeeded.
Sep 03 11:05:05 mlnode systemd[1]: Stopped MongoDB Database Server.
Sep 03 11:05:05 mlnode systemd[1]: Started MongoDB Database Server.
Sep 03 11:13:20 mlnode systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile= references a path below legacy directory /var/run/, updating /var/run/mongodb/mongod.pid → /run/mongodb/mongod.pid; please update the unit file accordingly.
Sep 03 11:25:47 mlnode systemd[1]: /lib/systemd/system/mongod.service:11: PIDFile= references a path below legacy directory /var/run/, updating /var/run/mongodb/mongod.pid → /run/mongodb/mongod.pid; please update the unit file accordingly.
Sep 03 11:56:47 mlnode systemd[1]: mongod.service: Main process exited, code=killed, status=6/ABRT
Sep 03 11:56:47 mlnode systemd[1]: mongod.service: Failed with result 'signal'
Wondering why the system is killing mongod.service, I don't have any clue. Then I checked my mongo logs:
{"t":{"$date":"2020-09-03T11:56:46.379+05:30"},"s":"F", "c":"-", "id":23083, "ctx":"conn10155","msg":"Invariant failure","attr":{"expr":"ret","error":"UnknownError: -31803: WT_NOTFOUND: item not found","file":"src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp","line":1598}}
{"t":{"$date":"2020-09-03T11:56:46.379+05:30"},"s":"F", "c":"-", "id":23084, "ctx":"conn10155","msg":"\n\n***aborting after invariant() failure\n\n"}
{"t":{"$date":"2020-09-03T11:56:46.379+05:30"},"s":"F", "c":"CONTROL", "id":4757800, "ctx":"conn10155","msg":"Writing fatal message","attr":{"message":"Got signal: 6 (Aborted).\n"}}
First, stop mongodb if you restarted:
sudo systemctl stop mongod
Next, I detected the database corruption:
sudo mongod --repair --dbpath /var/lib/mongodb
Next, run commands:
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
Finally
sudo systemctl start mongod
From: https://sondnpt00343.medium.com/how-to-fix-mongod-service-32dbbe51a4ee
I figured out that my Linux ulimits were not set to the recommended values of mongod instance.
One of the limits ( locked-in-memory ) was 65536 and in /lib/systemd/system/mongod.service LimitMEMLOCK was infinity.
So I've changed that to 65536, restarted the service and it was working again.
This worked for me!
First, I detected the database corruption.
sudo mongod --repair --dbpath /var/lib/mongodb
Then, I restarted the service but I faced another problem (exit-code).
Next, I ran following commands on the terminal :
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
Finally, I restarted the mongodb service.
sudo systemctl restart mongod
And then this worked for me very well.

MongoDB unregistered authentication error Centos 7

After reconfigure mongod.conf when trying to start mongod.service I'm getting error message.
I tried to run the command "mongod -f /path-to-configuration-file/
but everything is going ok so I tried to give permitions to db and log folder running the commands:
1 - chmod 777 /path-to-files
2 - chown mongod:mongod /path-to-files -R
After doing that I tried to give permition to port 40017 but still getting error.
My mongod.conf file:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /bin/rsmongo/log/mongod.log
# Where and how to store data.
storage:
dbPath: /bin/rsmongo/data/db
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 40017
Systemctl status mongod.service result:
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Ter 2018-12-18 14:02:01 BRST; 9s ago
Docs: https://docs.mongodb.org/manual
Process: 3880 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
Process: 3877 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 3874 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 3872 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: Starting MongoDB Database Server...
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: 2018-12-18T14:02:01.128-0200 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: about to fork child process, waiting until server is ready for connections.
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: forked process: 3883
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: ERROR: child process failed, exited with error number 1
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: To see additional information in this output, start without the "--fork" option.
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: mongod.service: control process exited, code=exited status=1
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: Failed to start MongoDB Database Server.
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: Unit mongod.service entered failed state.
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: mongod.service failed.
Journalctl -xe reult:
Dez 18 14:01:01 bon-lap-srv01 CROND[3850]: (root) CMD (run-parts /etc/cron.hourly)
Dez 18 14:01:01 bon-lap-srv01 run-parts(/etc/cron.hourly)[3853]: starting 0anacron
Dez 18 14:01:01 bon-lap-srv01 run-parts(/etc/cron.hourly)[3859]: finished 0anacron
Dez 18 14:01:01 bon-lap-srv01 run-parts(/etc/cron.hourly)[3861]: starting 0yum-hourly.cron
Dez 18 14:01:01 bon-lap-srv01 run-parts(/etc/cron.hourly)[3865]: finished 0yum-hourly.cron
Dez 18 14:02:01 bon-lap-srv01 polkitd[1006]: Registered Authentication Agent for unix-process:3867:1091339 (system bus name :1.51 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/fr
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: Starting MongoDB Database Server...
-- Subject: Unidade mongod.service sendo iniciado
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- A unidade mongod.service está sendo iniciada.
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: 2018-12-18T14:02:01.128-0200 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: about to fork child process, waiting until server is ready for connections.
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: forked process: 3883
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: ERROR: child process failed, exited with error number 1
Dez 18 14:02:01 bon-lap-srv01 mongod[3880]: To see additional information in this output, start without the "--fork" option.
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: mongod.service: control process exited, code=exited status=1
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: Failed to start MongoDB Database Server.
-- Subject: A unidade mongod.service falhou
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- A unidade mongod.service falhou.
--
-- O resultado é failed.
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: Unit mongod.service entered failed state.
Dez 18 14:02:01 bon-lap-srv01 systemd[1]: mongod.service failed.
Dez 18 14:02:01 bon-lap-srv01 polkitd[1006]: Unregistered Authentication Agent for unix-process:3867:1091339 (system bus name :1.51, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, loc
SOLVED
I deleted a file called "mongodb-40017.sock" at /tmp folder then it worked as expected.

Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory

I have an application called "Informer." I am trying to register it as a service and I'm not sure where I have gone wrong.
Here is informer.service:
[Unit]
Description=Informer Docker
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
User=root
WorkingDirectory=/opt/Informer5 <===Modify for the appropriate directory
ExecStart=/opt/Informer5/informer5.sh start <===Modify for the appropriate directory
ExecStop=/opt/Informer5/informer5.sh stop <===Modify for the appropriate directory
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
This file is in my /etc/systemd/system folder. I have enabled the service via
sudo systemctl enable informer
when I execute
sudo systemctl start informer
The response I get is
Job for informer.service failed because the control process exited with error code. See "systemctl status informer.service" and "journalctl -xe" for details.
So, running, systemctl status informer.service, I see the following:
$sudo systemctl status informer.service
● informer.service - Informer Docker
Loaded: loaded (/etc/systemd/system/informer.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2018-09-18 08:49:07 EDT; 4min 2s ago
Process: 5780 ExecStart=/opt/Informer5/informer5.sh start <===Modify for the appropriate directory (code=exited, status=200/CHDIR)
Main PID: 5780 (code=exited, status=200/CHDIR)
Sep 18 08:49:07 informer5 systemd[1]: Starting Informer Docker...
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Main process exited, code=exited, status=200/CHDIR
Sep 18 08:49:07 informer5 systemd[1]: Failed to start Informer Docker.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Running $ sudo journalctl -xe, I get:
$ sudo journalctl -xe
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has failed.
--
-- The result is failed.
Sep 18 08:06:36 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:06:36 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Sep 18 08:06:36 informer5 sudo[5690]: pam_unix(sudo:session): session closed for user root
Sep 18 08:12:40 informer5 sudo[5712]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/cat /etc/systemd/system/informer.service
Sep 18 08:12:40 informer5 sudo[5712]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:12:40 informer5 sudo[5712]: pam_unix(sudo:session): session closed for user root
Sep 18 08:15:01 informer5 CRON[5716]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:15:01 informer5 CRON[5717]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:15:01 informer5 CRON[5716]: pam_unix(cron:session): session closed for user root
Sep 18 08:17:01 informer5 CRON[5721]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:17:01 informer5 CRON[5722]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 18 08:17:01 informer5 CRON[5721]: pam_unix(cron:session): session closed for user root
Sep 18 08:25:01 informer5 CRON[5732]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:25:01 informer5 CRON[5733]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:25:01 informer5 CRON[5732]: pam_unix(cron:session): session closed for user root
Sep 18 08:35:01 informer5 CRON[5745]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:35:01 informer5 CRON[5746]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:35:01 informer5 CRON[5745]: pam_unix(cron:session): session closed for user root
Sep 18 08:45:01 informer5 CRON[5758]: pam_unix(cron:session): session opened for user root by (uid=0)
Sep 18 08:45:01 informer5 CRON[5759]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
Sep 18 08:45:01 informer5 CRON[5758]: pam_unix(cron:session): session closed for user root
Sep 18 08:47:43 informer5 sudo[5774]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/cat /etc/systemd/system/informer.service
Sep 18 08:47:43 informer5 sudo[5774]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:47:43 informer5 sudo[5774]: pam_unix(sudo:session): session closed for user root
Sep 18 08:49:07 informer5 sudo[5777]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/systemctl start informer
Sep 18 08:49:07 informer5 sudo[5777]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:49:07 informer5 systemd[5780]: informer.service: Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory
-- Subject: Process /opt/Informer5/informer5.sh could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /opt/Informer5/informer5.sh could not be executed and failed.
--
-- The error number returned by this process is 2.
Sep 18 08:49:07 informer5 systemd[1]: Starting Informer Docker...
-- Subject: Unit informer.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has begun starting up.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Main process exited, code=exited, status=200/CHDIR
Sep 18 08:49:07 informer5 systemd[1]: Failed to start Informer Docker.
-- Subject: Unit informer.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit informer.service has failed.
--
-- The result is failed.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Unit entered failed state.
Sep 18 08:49:07 informer5 systemd[1]: informer.service: Failed with result 'exit-code'.
Sep 18 08:49:07 informer5 sudo[5777]: pam_unix(sudo:session): session closed for user root
Sep 18 08:53:09 informer5 sudo[5787]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/systemctl status informer.service
Sep 18 08:53:09 informer5 sudo[5787]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
Sep 18 08:53:09 informer5 systemd[1]: Configuration file /etc/systemd/system/informer.service is marked executable. Please remove executable permission bits. Proceeding anyway.
Sep 18 08:53:09 informer5 sudo[5787]: pam_unix(sudo:session): session closed for user root
Sep 18 08:54:01 informer5 sudo[5791]: n_connor : TTY=pts/0 ; PWD=/opt/Informer5 ; USER=root ; COMMAND=/bin/journalctl -xe
Sep 18 08:54:01 informer5 sudo[5791]: pam_unix(sudo:session): session opened for user root by n_connor(uid=0)
I think that the salient error here is informer.service: Failed at step CHDIR spawning /opt/Informer5/informer5.sh: No such file or directory
I have checked that the file does exist and I can manually start the service using that file as root. I have a home directory set in the service file. I have no idea where this error is coming from. I am using ubuntu 16.04 and I have enabled root login with ssh. Any ideas?
I added #!/bin/bash in the bash file at the top and it worked
e.g.
nano server.sh
#!/bin/bash
echo "Serving Web App!"
serve -s build -p 4004
chmod +x server.sh
nano /etc/systemd/system/web.service
[Unit]
Description=Web App
After=network.target
[Service]
WorkingDirectory=/var/www/html/web
User=root
ExecStart=/var/www/html/web/server.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Things to note
Verify the WorkingDirectory e.g cd /var/www/html/web if it does not exist create it e.g. cd /var/www/html/web

MongoDB fails starting as a service on CentOS 7

I've a Google cloud VM with MongoDB server running for many months. Today the VM restarted and MongoDB won't run as a service (i can run it mannualy as a process and starts OK).
OS: CentOS 7
MongoDB Verion: 3.2.16
The error thrown:
>sudo service mongod start
Starting mongod (via systemctl): Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[FAILED]
So if i run "systemctl status mongod.service":
>sudo systemctl status mongod.service
mongod.service - SYSV: Mongo is a scalable, document-oriented database.
Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2018-02-05 18:05:49 UTC; 1min 20s ago
Docs: man:systemd-sysv-generator(8)
Process: 3755 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)
Feb 05 18:05:49 todoturnos-testing systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Feb 05 18:05:49 todoturnos-testing runuser[3762]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Feb 05 18:05:49 todoturnos-testing mongod[3755]: Starting mongod: [FAILED]
Feb 05 18:05:49 todoturnos-testing systemd[1]: mongod.service: control process exited, code=exited status=1
Feb 05 18:05:49 todoturnos-testing systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
Feb 05 18:05:49 todoturnos-testing systemd[1]: Unit mongod.service entered failed state.
Feb 05 18:05:49 todoturnos-testing systemd[1]: mongod.service failed.
If i run "journalctl -xe"
>sudo journalctl -xe
Feb 05 18:09:58 todoturnos-testing sudo[3827]: janokpodelmundi : TTY=pts/0 ; PWD=/usr/lib/tmpfiles.d ; USER=root ; COMMAND=/sbin/service mongod start
Feb 05 18:09:58 todoturnos-testing polkitd[348]: Registered Authentication Agent for unix-process:3847:870363 (system bus name :1.242 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /or
Feb 05 18:09:58 todoturnos-testing systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
-- Subject: Unit mongod.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mongod.service has begun starting up.
Feb 05 18:09:58 todoturnos-testing runuser[3860]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Feb 05 18:09:58 todoturnos-testing runuser[3860]: pam_unix(runuser:session): session closed for user mongod
Feb 05 18:09:58 todoturnos-testing mongod[3853]: Starting mongod: [FAILED]
Feb 05 18:09:58 todoturnos-testing systemd[1]: mongod.service: control process exited, code=exited status=1
Feb 05 18:09:58 todoturnos-testing systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
-- Subject: Unit mongod.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit mongod.service has failed.
--
-- The result is failed.
Feb 05 18:09:58 todoturnos-testing systemd[1]: Unit mongod.service entered failed state.
Feb 05 18:09:58 todoturnos-testing systemd[1]: mongod.service failed.
Feb 05 18:09:58 todoturnos-testing polkitd[348]: Unregistered Authentication Agent for unix-process:3847:870363 (system bus name :1.242, object path /org/freedesktop/PolicyKit1/AuthenticationAgent,
Feb 05 18:10:00 todoturnos-testing sudo[3866]: janokpodelmundi : TTY=pts/0 ; PWD=/usr/lib/tmpfiles.d ; USER=root ; COMMAND=/bin/journalctl -xe
lines 2280-2321/2321 (END)
Where "janokpodelmundi" is my username.
So, i have disabled SELINUX as i know it could be related with this problem, but didn't resolved it.
I've also changed the "pid" file location to ensure the permissions are OK,and had disabled forking in the config as well.
My mongodb config:
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork d run in background
pidFilePath: /var/run/mongo/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 # Listen to local interface only, comment to listen on all interfaces.
The mongodb log is empty, and it's not generating rows at any time.
I have been trying many alternatives i've found on internet but the problem persists.
Any help would be great.
Solution:
After trying the "mongod -f /path-to-config-file" and getting the "incorrect YAML" error at line 29, i pasted from original mongo conf the lines 26-29:
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 #
After that i tried again the "mongod -f path-to-config-file" and succeed.
YAML files require spaces for indentation and not tabs. Seems that you have a funny character/indent within your conf file. The easiest way to debug this is to start off with a basic conf file and add in options and make sure your indents etc are correct before adding another option
As mentioned above , the issue may be caused because files isn't in Yaml format
run :
mongod -f /etc/mongod.conf
you will get in what line the issue is (fix the extra spaces and issue will be solved)

RHEL7 systemd start mongo services automatically?

I have a RHEL7 server that is part of a Mongo cluster. There are three mongo processes that I would like to be automatically started on system boot. One mongod, one arbiter and one mongos:
/usr/bin/mongod -f /etc/mongo_shard001.conf
/usr/bin/mongod -f /etc/mongoarb.conf
/usr/bin/mongos -f /etc/mongos.conf
I have been trying to create systemd services for these commands i.e
[Unit]
Description=mongo configuration server
After=network.target
[Service]
User=mongod
Group=mongod
ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf
[Install]
WantedBy=multi-user.target
When I try to do sudo systemctl daemon-reload && sudo systemctl start mongoconf, I get this error
● mongoconf.service - mongo configuration server
Loaded: loaded (/etc/systemd/system/mongoconf.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2017-02-02 14:38:34 AWST; 20s ago
Process: 5114 ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf (code=exited, status=1/FAILURE)
Main PID: 5114 (code=exited, status=1/FAILURE)
Feb 02 14:38:34 mdb1 systemd[1]: Started mongo configuration server.
Feb 02 14:38:34 mdb1 systemd[1]: Starting mongo configuration server...
Feb 02 14:38:34 mdb1 systemd[1]: mongoconf.service: main process exited, code=exited, status=1/FAILURE
Feb 02 14:38:34 mdb1 systemd[1]: Unit mongoconf.service entered failed state.
Feb 02 14:38:34 mdb1 systemd[1]: mongoconf.service failed.
I have also tried using a forked type with pid file:
[Unit]
Description=mongo configuration server
After=network.target
[Service]
User=mongod
Group=mongod
ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf --pidfilepath /var/lib/mongoconf/pid --fork
Type=forking
PIDFile=/var/run/mongodb/mongoconf/pid
[Install]
WantedBy=multi-user.target
But gives this error
● mongoconf.service - mongo configuration server
Loaded: loaded (/etc/systemd/system/mongoconf.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2017-02-02 14:45:36 AWST; 4s ago
Process: 5256 ExecStart=/usr/bin/mongod -f /etc/mongoconf.conf --pidfilepath /var/lib/mongoconf/pid --fork (code=exited, status=1/FAILURE)
Main PID: 5114 (code=exited, status=1/FAILURE)
Feb 02 14:45:36 mdb1 systemd[1]: Starting mongo configuration server...
Feb 02 14:45:36 mdb1 mongod[5256]: about to fork child process, waiting until server is ready for connections.
Feb 02 14:45:36 mdb1 mongod[5256]: forked process: 5258
Feb 02 14:45:36 mdb1 systemd[1]: mongoconf.service: control process exited, code=exited status=1
Feb 02 14:45:36 mdb1 systemd[1]: Failed to start mongo configuration server.
Feb 02 14:45:36 mdb1 systemd[1]: Unit mongoconf.service entered failed state.
Feb 02 14:45:36 mdb1 systemd[1]: mongoconf.service failed.
Starting the mongo config manually works fine and creates the pid file
/usr/bin/mongod -f /etc/mongoconf.conf --pidfilepath /var/lib/mongoconf/pid --fork
The version of mongod I am using is the one from mongodb.com, and I installed it following their install guide.
db version v3.4.1
git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
from this repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
I am wondering if I am going about this the wrong way, is there a better way to do this?
I know you said rhel7 but since it's the only answer coming up on duckduckgo for this question, this can be useful. Under Ubuntu 15 and up:
sudo systemctl enable mongod.service
Here is my solution
make a bash script with these lines
/usr/bin/mongod -f /etc/mongo_shard001.conf
/usr/bin/mongod -f /etc/mongoarb.conf
/usr/bin/mongos -f /etc/mongos.conf
and then add this line to your crontab
#reboot root cd /foldername && ./scriptname.sh
systemd would be a better solution, if anyone knows how to set it up.
the mongo documentation is no help