I am using source installation of cassandra. After installation I ran it like this:
$ pwd
/var/users/ec2-user/apache-cassandra-3.10
$ bin/cassandra -f
After this I am getting error:
ERROR [main] 2017-04-04 14:40:34,195 CassandraDaemon.java:752 - Port already in use: 7199; nested exception is:
java.net.BindException: Address already in use (Bind failed)
java.net.BindException: Address already in use (Bind failed)
Then I grep for 7199
$ ps aux | grep 7199
-javaagent:/home/ec2-user/apache-cassandra-3 .10/bin/../lib/jamm-0.3.0.jar -Dcassandra.jmx.local.port=7199
....
org.apache.cassandra.service.CassandraDaemon
Now I am unable to kill CassandraDaemon
kill -9 <process_id_of_CassandraDaemon>
or
pkill -f CassandraDaemon
This is not working. I get 7199 still running .
Please help.
Try one of this at a time:
Try to run these commands with sudo.
sudo service cassandra stop (if you are running on ubuntu).
Restart server :)
7199 is not the process id. It actually a port.
execute this command and find which program already acquired this port.
> netstat -antp | grep 7199
Then use kill command to terminate that program. After then try running cassandra again.
I found the answer by self.
my cassandra was running under supervisord so I had to stop supervisord by running following command
sudo /etc/init.d/supervisord stop
Then I can kill cassandra process.
Related
What shell command would you use to stop Cassandra started locally? Is there one that stops it without the PID? If no, what command can you use to get the PID in shell script?
Please tailor to your individual situation, since you mentioned that C* is started locally.
However you can use something like this in your script:
#!/bin/bash
PID=$(cat /var/run/cassandra/cassandra.pid)
sudo kill -9 $PID
If you started Cassandra without designating a file for the PID, then you'll have to do something tricky, like this:
ps -ef | grep cassandra | grep "jmx\.local\.port=7199" | awk '{print $2}'
96165
Basically you're using ps to get the status of all processes, grepping for "cassandra", and then grepping for something very specific to the Cassandra process (like local JMX on port 7199). Then, if you pipe that all through awk, you can pretty easily just pull the second space-delimited "column."
There's probably a more graceful way to do this, but it'll work.
Then, as a user with privileges to the cassandra process, you can just run a kill on that PID. Or, you could encapsulate that all into one, single command:
kill $(ps -ef | grep cassandra | grep "jmx\.local\.port=7199" | awk '{print $2}')
Stopping a local Cassandra instance depends on the installation type.
If you've installed Cassandra as a YUM (RHEL/CentOS) or APT (Debian) package, stop the service with:
$ sudo service cassandra stop
If you've installed Cassandra using the binary tarball, you can simply kill it with:
$ pkill cassandra
Note that if you're running Cassandra as another user such as root, you'll need to use sudo to get elevated permissions. Cheers!
This question is not a duplicate of mariadb server: I can't stop the server with `mysql.server stop`.
I don’t want to run MariaDB at boot so brew services isn’t an option.
MariaDB version is 10.4.11-MariaDB.
Think I found the culprit.
Having a look at the source code of mysql.server (cat /usr/local/bin/mysql.server), I discovered that running mysql.server start runs mysqld_safe as me (whoami) which is what I expected.
Now, I also discovered that running mysql.server stop runs a su_kill function that runs su as mysql which fails because the mysql user doesn’t exist on macOS.
user='mysql'
su_kill() {
if test "$USER" = "$user"; then
kill $* >/dev/null 2>&1
else
su - $user -s /bin/sh -c "kill $*" >/dev/null 2>&1
fi
}
Not sure if I am doing something wrong, but according to the documentation, running mysql.server start is the right way of starting MariaDB on brew installs.
Anyhow, to patch mysql.server stop, run:
cp /usr/local/bin/mysql.server /usr/local/bin/mysql.server.backup
sed -i "" "s/user='mysql'/user=\`whoami\`/g" /usr/local/bin/mysql.server
Originally, whenever I tried mysql.server stop I would get the error:
ERROR! MySQL server PID file could not be found!
At some point, mysql.server stop would just hang.
Exploring #sunknudsen's answer, I cd'ed to the directory:
$ cd /usr/local/bin/
then opened the file:
mysql.server
The code user='mysql' only appears on one line, so I just commented out that line and replaced it with:
185 #user='mysql'
186 user=`whoami`
Now, this is what happens:
~$ mysql.server start
Starting MariaDB
.200804 15:43:28 mysqld_safe Logging to '/usr/local/var/mysql/My-MacBook-Pro-2.local.err'.
200804 15:43:29 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
SUCCESS!
~$ mysql.server stop
Shutting down MariaDB
. SUCCESS!
~$ mysql.server stop
ERROR! MariaDB server PID file could not be found!
The correct start/stop status is also indicated in System Preferences/MySQL.
Running postgreSQL 9.4.5_2 currently
I have tried
pg_ctl stop -W -t 1 -s -D /usr/local/var/postgres -m f
Normally no news is good news but after I will run
pg_ctl status -D /usr/local/var/postgres
and get pg_ctl: server is running (PID: 536)
I have also tried
pg_ctl restart -w -D /usr/local/var/postgres -c -m i
Response message is:
waiting for server to shut down.......................... failed
pg_ctl: server does not shut down
I've also checked my /Library/LaunchDaemons/ to see why the service is starting at login but no luck so far. Anyone have any ideas on where I should check next? Force quit in the activity monitor also isn't helping me any.
Sadly none of the previous answers help me, it worked for me with:
brew services stop postgresql
Cheers
I tried various options; finally, the below command worked.
sudo -u postgres ./pg_ctl -D /your/data/directory/path stop
example
sudo -u postgres ./pg_ctl -D /Library/PostgreSQL/11/data stop
As per the comments, the recommended command is without the ./ when calling pg_ctl:
sudo -u postgres pg_ctl -D /Library/PostgreSQL/11/data stop
Tried sudo and su but no such luck.
Just found this gui
https://github.com/MaccaTech/postgresql-mac-preferences
If anyone can help with the terminal commands that would be very much appreciated, but till then the gui will get the job done.
Had the same issue, I had installed postgres locally and wanted to wrap in a docker container instead.
I solved it pretty radically by 1) uninstalling postgres 2) kill the leftover process on postgres port. If you don't un-install the process restarts and grabs the port again - look at your Brewfile form brew bundle dump to check for a restart_service: true flag.
I reasoned that, as I am using containers, I should not need the local one anyway, but !! attention this will remove postgres from your system.
brew uninstall postgres
...
lsof -i :5432 # this to find the PID for the process
kill - 9 <the PID you found at previous command>
Note: if you still want to used psql you can brew install libpq, and add psql to your PATH (the command output shows you what to add to your .zshrc, or similar)
you can stop the server using this command
{pg_ctl -D /usr/local/var/postgres stop -s -m fast}
Adding onto the solutions already stated :
if you decide to use the pg_ctl command, ensure that you are executing the command as a user with the permissions to access the databases/database server.
this means :
the current logged in user on your terminal should have those permissions
or
first run :
$ sudo su <name_of_database_user>
pg_ctl -D /Library/PostgreSQL/<version_here>/data/ stop
the same goes for the start command.
credit : https://gist.github.com/kingbin/9435292
(essentially hosted a file with the commands on github, saved me some time :^) )
I had a stray docker container running Postgres that I had forgotten about.
I have installed mosquito broker on my mac using brew install mosquitto.
Normally I don't give any commands to start the mosquitto server. It is started automatically when I switch on my mac.
I have verified that it is running by using the command ps -ef | grep mosquitto, which gives the following output
501 209 153 0 2:20PM ?? 0:06.93/usr/local/opt/mosquitto/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf
501 2559 1007 0 10:36AM ttys001 0:00.00 grep mosquitto
501 865 815 0 2:32PM ttys003 0:00.86 mosquitto_sub -h 127.0.0.1 -t esb.test2
Then I stopped the server by killing the mosquitto process using kill -9 above-pid.
Now I would like to know how can I restart the server again from command line, but without restarting my mac.
If you've installed mosquitto from homebrew, you can use launchctl to control the service, e.g.
$ launchctl load /usr/local/Cellar/mosquitto/1.4.2/homebrew.mxcl.mosquitto.plist
$ launchctl unload /usr/local/Cellar/mosquitto/1.4.2/homebrew.mxcl.mosquitto.plist
$ launchctl start homebrew.mxcl.mosquitto
$ launchctl stop homebrew.mxcl.mosquitto
You could kill the mosquitto process using the steps detailed in the answer here, then restart it in the same way you did originally.
To summarise the answer
killall mosquitto
Should do the job to stop the existing process.
I'm using nginx on OS X 10.8. Freshly installed nginx but can't find a way to restart nginx except kill nginx_pid say kill 64116. Wondering if there are better ways to restart nginx.
Found some methods on Google and SO but didn't work:
nginx -s restart
sudo fuser -k 80/tcp ; sudo /etc/init.d/nginx restart
The error message for nginx -s restart is
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
Sometimes also get this error msg:
nginx: invalid option: "-s restart"
Try running sudo nginx before starting nginx.
To reload config files:
sudo nginx -s reload
To fully restart nginx:
sudo nginx -s quit
sudo nginx
Details
There is no restart signal for nginx. From the docs, here are the signals that the master process accepts:
SIGINT, SIGTERM Shut down quickly.
SIGHUP Reload configuration, start the new worker process with a new configuration, and gracefully shut down old worker processes.
SIGQUIT Shut down gracefully.
SIGUSR1 Reopen log files.
SIGUSR2 Upgrade the nginx executable on the fly.
SIGWINCH Shut down worker processes gracefully.
Presumably you could send these signals to the process id manually, but the nginx command has the flag nginx -s <signal> that sends signals to the master process for you. Your options are:
stop SIGTERM
quit SIGQUIT
reopen SIGUSR1
reload SIGHUP
No need to futz with the pid manually.
Edit: just realized much of this info was already in comments on the other answers. Leaving this here anyway to summarize the situation.
What is your nginx pid file location? This is specified in the configuration file, default paths specified compile-time in the config script. You can search for it as such:
find / -name nginx.pid 2>/dev/null (must issue while nginx is running)
Solution:
sudo mkdir -p /usr/local/var/run/
ln -s /current/path/to/pid/file /usr/local/var/run/nginx.pid
$ sudo nginx -c /usr/local/etc/nginx/nginx.conf
$ sudo nginx -s reload
Source Link: https://blog.csdn.net/github_33644920/article/details/51733436
Try this:
sudo nginx -s stop
followed by a:
sudo nginx
It seems that nginx keeps track of its state, to if you stop it twice, it will complain. But the above worked for me.
I do it like this:
First kill the progress
ps aux | grep nginx
kill -9 {pid}
Then start nginx
nginx
It works!
As a future resource, you can consult http://wiki.nginx.org/CommandLine
Nginx probably runs as root, so you will need to run a variant of the following command to affect it.
sudo nginx -s stop | reload | quit | reopen
There is usually not much reason to restart Nginx like Apache would need. If you have modified a configuration file, you may just want to the reload option.
check if this directory exists:
/usr/local/var/run
this error can occurs when nginx try to initialise pid file in
localisation that doesn't exist.
There is a bug here. Depending on whether nginx is running while you modify/restart apache and/or modify nginx configs it is possible for this file (which is essentially just a process ID pointer) to be destroyed.
When you attempt to send any signal to nginx like
nginx -s quit;
nginx -s stop;
nginx -s reload;
nginx uses this file to reference the ID of the process to which it needs to send the signal. If the file isn't there the link between the active running process of nginx & the cli app is effectively broken.
I actually ended up in a state where two nginx processes were running simultaneously so killed both.
To work around this, you can either Force the termination of existing nginx processes via Activity Monitor (then run nginx & have the cli app create a new nginx.pid file) or if you REALLY need to keep nginx running but want to run nginx -s reload - manually create a file in the /run path called nginx.pid and insert the PID of the currently running nginx processs (obtained via Activity Monitor).
To reload the custom config file use
nginx -s reload -c /etc/nginx/conf.d/<config file>.conf
This could simply mean that nginx is already stopped - not running at the moment.
First, confirm whether nginx is running, execute:
$ ps aux | grep nginx
i got the same error link you, i tried many way to fix it but it not working
after that i run the command line and it work well:
nginx -c /usr/local/etc/nginx/nginx.conf
the information i got from here
https://blog.csdn.net/wn1245343496/article/details/77974756
One way to stop or reload is through the below command,
For stop:
sudo /usr/local/nginx/sbin/nginx -s stop
Run reload only if the nginx is running:
sudo /usr/local/nginx/sbin/nginx -s reload
By doing like the above, you wont get nginx: [error] open() "/usr/local/var/run/nginx.pid" this issue