sudo service command not found when installing mongodb - linux

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.

Related

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

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

Where does store pidfiles for filebeat and metricbeat in centos 7

I need to add monit checker for my filbeat/metricbeat process.
I want to check the process via pid file, but I can't find where the system stores these files in centos 7.
e.g. in my local ubuntu 14.04 it stores under this path /var/run/filebeat.pid, /var/run/metricbeat.pid.
I have tried to find the file in the whole system (find / -name filebeat.pid), but I couldn't.
If there is no why to check via pidfile, do I have another way to check the process state?
Any suggestion would be helpful, thanks in advance )
First get the process id using the name of the executable e.g. filebeat/metricbeat in your case.
Here's an example searching for the xinetd process
Search for your process using pgrep:
$ sudo pgrep xinetd
1180
1180 is the PID of the xinetd process. You can get its arguments like so:
$ cat /proc/1180/cmdline
/usr/sbin/xinetd-stayalive-pidfile/var/run/xinetd.pid
If this doesn't specify the pidfile as an argument, you can try lsof to list open files associated with the process id.
$ sudo lsof -p <Process ID>

What's the difference between the commands 'sudo gearmand -d' and 'sudo service gearman-job-server start'?

I'm learning gearman and found that there are two ways to start the gearman:
sudo gearmand -d
sudo service gearman-job-server start
What's the difference?
When to use each of them?
Thanks for any feedback!
Well this is not specific to gearmand but it applies to almost all linux daemons/services.
The program/service can be invoked through different ways. Directly from the terminal, through scripts in /etc and other means. I am assuming you know what sudo does.
# gearmand -d
You are invoking gearmand executable directly. The shell knows where the executable is, because the PATH is set. You may search its location by using "whereis gearmand" or finding it with find.
This is the direct way of calling the application/service.
"daemon" is a background process. The "-d" argument to gearman starts it in daemon mode (in background).
Advantage/s:
If you compile multiple version of the service on the same machine, in this case "gearman", you can invoke them individually without installing/reinstalling.
Sometimes the installation doesn't work or the service might not support startup scripts etc.
Disadvantage/s:
May not give a uniform output like standard scripts / commands.
You may need to know the location of the file.
# service gearman-job-server start
calls the script service which usually looks into the directory "/etc/init.d". If you wish to find where service is searching for the services in your linux distribution, you can look it up.
Search the location of service script "whereis service" then open it in less by "less path_to_service" or directly by "whereis service | cut -d " " -f2 | xargs less" to see the service file.
The service script sort of standardizes the way scripts are called in linux these days.
$ service service_name start
service_name started
$ service service_name start
service_name already running
$ service service_name stop
service_name stopped.
$ service service_name stop
service_name not running.
This provides a uniform way of starting or stopping all services.

How to check if a service that I don't know the name of is running on Ubuntu

I do not know the service's name, but would like to stop the service by checking its status.
For example, if I want to check if the PostgreSQL service is running or not, but I don't know the service's name, then how could I check its status?
I know the command to check the status if the service name is known.
I don't have an Ubuntu box, but on Red Hat Linux you can see all running services by running the following command:
service --status-all
On the list the + indicates the service is running, - indicates service is not running, ? indicates the service state cannot be determined.
For Ubuntu (checked with 12.04)
You can get list of all services and select by color one of them with 'grep':
sudo service --status-all | grep postgres
Or you may use another way if you know correct name of service:
sudo service postgresql status
Maybe what you want is the ps command;
ps -ef
will show you all processes running. Then if you have an idea of what you're looking for use grep to filter;
ps -ef | grep postgres
There is a simple way to verify if a service is running
systemctl status service_name
Try PostgreSQL:
systemctl status postgresql
If you run the following command you will get a list of services:
sudo service --status-all
To get a list of upstart jobs run this command:
sudo initctl list
You can use the below command to check the list of all services.
ps aux
To check your own service:
ps aux | grep postgres
the best way is using of nmap tool in terminal.
nmap is an useful tool that analyse an up system, using it's IP Address, then show all actived network services.
open terminal and use of this example :
~$ nmap 192.168.1.3/24
Starting Nmap 5.21 ( http://nmap.org ) at 2016-05-16 22:49 IRDT
Nmap scan report for 192.168.1.3
Host is up (0.00020s latency).
Not shown: 994 closed ports
PORT STATE SERVICE
22/tcp open ssh
23/tcp open telnet
139/tcp open netbios-ssn
445/tcp open microsoft-ds
3389/tcp open ms-term-serv
3689/tcp open rendezvous
run
ps -ef | grep name-related-to-process
above command will give all the details like pid, start time about the process.
like if you want all java realted process give java
or if you have name of process place the name
To check the status of a service on linux operating system :
//in case of super user(admin) requires
sudo service {service_name} status
// in case of normal user
service {service_name} status
To stop or start service
// in case of admin requires
sudo service {service_name} start/stop
// in case of normal user
service {service_name} start/stop
To get the list of all services along with PID :
sudo service --status-all
You can use systemctl instead of directly calling service :
systemctl status/start/stop {service_name}
Dirty way to find running services. (sometime it is not accurate because some custom script doesn't have |status| option)
[root#server ~]# for qw in `ls /etc/init.d/*`; do $qw status | grep -i running; done
auditd (pid 1089) is running...
crond (pid 1296) is running...
fail2ban-server (pid 1309) is running...
httpd (pid 7895) is running...
messagebus (pid 1145) is running...
mysqld (pid 1994) is running...
master (pid 1272) is running...
radiusd (pid 1712) is running...
redis-server (pid 1133) is running...
rsyslogd (pid 1109) is running...
openssh-daemon (pid 7040) is running...
For centos, below command worked for me (:
locate postgres | grep service
Output:
/usr/lib/firewalld/services/postgresql.xml
/usr/lib/systemd/system/postgresql-9.3.service
sudo systemctl status postgresql-9.3.service
for Centos 6.10 :
/sbin/service serviceNAME status
for Centos 7.6 and ubuntu 18.04:
systemctl status NAME.service
works for all of them:
service --status-all
Based on this answer on a similar topic https://askubuntu.com/a/58406 I prefer: /etc/init.d/postgres status
if you are looking particularly for postgres there is a specific command called "pgrep"
you can find the usage in the below mentioned article
https://mydbanotebook.org/post/troubleshooting-01/
this article provides the following details:
check if postgres server is running
where does postgres store all the server config
how to start/stop postgres
hope this is helpful

Stop Unlisted Services

I have just reinstalled LAMPP. When I try starting LAMPP using /opt/lampp/lampp start, it says another ftp and mysql daemon is already running along with another web server. I deleted the old instance of LAMPP without stopping all the services. When I use service --status-all these services aren't listed.
Is there any way I can stop it now?
Yes, with this : pkill -f apache; pkill -f httpd
You can run that on each service you want to stop.
To test if it's still running, try pgrep -fl <APP_NAME>.
If it's the case, consider using pkill -1 -f <APP_NAME> and if still present pkill -9 -f <APP_NAME>. -9 is the higher signal. Don't use -9 by default, you will facing problems with not well closed applications (file descriptors and other system stuff)
see man 7 signal.

Resources