Temporarily route stdout/stderr of a forked mongod process to console - linux

I started a mongodb server instance with the following command line parameters
mongod --port 12345 --fork --logpath mongodb/test/logs/log.txt --dbpath mongodb/test/wiredTiger
How can I temporarily make this database instance write its stdout/stderr messages to my console window?
Or is it possible to connect to it via a mongo client and instruct the server to echo those messages to this client?

If your server runs on a *nix environment you can use tail command from a terminal like so:
tail -f /${path}/mongodb/test/logs/log.txt
It will just give you a scrolling view of your log.txt file in the console screen.

Sorry i'm not a user of mongod, so i'm guessing here:
Mongod seems to be c++ program using cout, cerr streams, eg see initializer.cpp:95 (that is line 95 of that file, you may need scroll down a bit)
Q: Does the mongod command redirect everything (stdout,stderr) to the logfile given in logpath? If so, maybe just remove the 'logpath' option. (haven't tested it.)
To test where the output goes, maybe try to run it with some invalid startup parameters, and see where the output goes.

Start it without --fork and --log so that it will run in foreground and write logs to console:
mongod --port 12345 --dbpath mongodb/test/wiredTiger
This will start db on port 12345

Related

How to hide output of mongo terminal (Node.Js)

I am working with MongoDB in a Node server.
While my program is running i get a lot of output in the shell, like querys and other information. If i am right that is a lot of work more for the process, so i want to hide all kind of output.
I try runing the comand with the parameter --quiet
mongod --quiet
So i assume that i miss a configuration in the mongo driver of node.
Technicals:
MongoDB Version: 3.2.9
Node Version:v6.4.0
mongod documentation states:
--quiet
Runs the mongod in a quiet mode that attempts to limit the amount of
output.
This option suppresses:
output from database commands
replication activity
connection accepted events connection closed events
So still some output emerges from the process. To prevent this and hide ALL the output, both stdout and stderr, you need to say either of these equivalent commands:
process &>/dev/null
process >/dev/null 2>&1
In your case:
mongod &>/dev/null
mongod >/dev/null 2>&1
See What is /dev/null 2>&1? for some explanations on how this works.

sudo service command not found when installing mongodb

I am currently on OS/X using macbook. I want to stop the instance of mongodb service running. Hence I tried:
> sudo service mongodb stop
sudo: service: command not found
After looking up on Google, they asked me to add PATH hence I did the following:
> `vim ~/.bash_profile` (created a new bash_profile) and added the following there:
export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
It does not seem to work and I still get the same error:
The command you are using is for Linux. To kill all mongod instances on your system, you have to issue
killall mongod
in a Terminal window. In order to kill a specific mongod instance, you have to issue
ps ax | grep [m]ongod
This will give you a list of mongod instances currently running on your Mac. Pick the one you want to stop (you can distinguish them via their command line options) and have a look to the very left of that line. The number is the process id (or pid for short) of that mongod instance. You kill that instance by issuing
kill <pid>
Replacing <pid> with the actual process id.

BASH - how to make this always running from system boot and on crash restart?

I have this protocol port open to read remotely from Python, PHP applications but daily it crash and the port is unavailable as a result Python, PHP all client application fails
$ cat /var/tmp/server.sh
#!/bin/bash
while true; do tail -f /usr/local/freeswitch/log/freeswitch.log | nc -l -p 9999 -q 1 &
Q. Is there anyway to make this script always running like service this start or stop and if its crashed that somehow it automatically again get restarted ? Any advise or link to do such thing? i am using CentOS 6.x
Put your script in /etc/inittab as following
id:1:respawn:/var/tmp/server.sh
Refer to http://linux.about.com/od/commands/l/blcmdl5_inittab.htm for more information about the /etc/initab file.
After editing /etc/inittab restart your system.

How to start mongod from boot script without running as root?

mongod runs fine as my own system user, but when I attempt to start it from a boot script using sudo, it fails.
I'm not running it as root, i'm doing:
sudo -u normaluser /user/local/bin/mongod --fork --logpath=/var/log/mongodb.log --logappend >/dev/null 2>&1 &
The log file is writeable by normaluser and I have no problem running it as normaluser directly.
How can I start this on boot?
Ok, given our conversation in the comments above I think you should look at the following file:
Red Hat based init script
It seems like you might want to follow that and write something like:
daemon --user normaluser mongod --fork --logpath=/var/log/mongodb.log --logappend >/dev/null 2>&1 &

JBoss Server Stopping

I'm having a problem with keeping a JBoss server running. Here's the command I'm using to start it:
sudo /JBOSS_HOME/bin/run.sh conf -b servername.domainname.tld
JBoss starts okay after about 4 minutes or so, and when I ps it, it shows up as a process. However, if I happen to log out of SSH and ps again, it's been stopped. Is there a way to start the server so it doesn't automatically stop when a user logs out of SSH?
I think the problem here is the standard output stream.
Redirect the output to a file and start the process in background like following.
sudo /JBOSS_HOME/bin/run.sh conf -b servername.domainname.tld > log_file &
This may help.

Resources