I'm running ubuntu 14.04 and I just want to restart (stop and start) couchDB, which is running on cloud 9. I tried these but none of them seems to work:
1.
ps -U couchdb -o pid= | xargs kill -9
2.
sudo couchdb stop
3.
curl -X POST http://[username]:[password]#127.0.0.1:5984/_restart -H"Content-Type: application/json"
Starting the couchdb the way the Cloud9 doc says will allow a simple Control + C to close it:
sudo mkdir -p /var/run/couchdb
sudo chown couchdb:couchdb /var/run/couchdb
sudo su couchdb -c /usr/bin/couchdb
However is that's not what you want you can always find the PID and kill it:
mikeumus#couchdb:~/workspace (master) $ pstree -ap|grep couchdb
| |-grep,9050 --color=auto couchdb
`-sudo,9018 su couchdb -c /usr/bin/couchdb
`-su,9019 couchdb -c /usr/bin/couchdb
`-beam.smp,9020 -Bd -K true -A 4 -- -root /usr/lib/erlang -progname erl -- -home /var/lib/couchdb ---noshe
mikeumus#couchdb:~/workspace (master) $ sudo kill -- -9018
mikeumus#couchdb:~/workspace (master) $ pstree -ap|grep couchdb
| |-grep,9071 --color=auto couchdb
Don't mind the color process still running, the couchdb process is now off. If you want to find and kill the couchdb in a single command, try:
kill $(ps aux | grep '[c]ouchdb' | awk '{print $2}')
Explained in this Stack Overflow Answer: https://stackoverflow.com/a/3510850/1762493
Related
I have to make ssh request for different nodes based on given IP.
different ssh commands are stored in node.txt as below
0.0.0.0 a ssh -t user#0.0.0.0 sudo -u node0 /path/script.sh
0.0.0.1 b ssh -t user#0.0.0.1 sudo -u node1 /path/script.sh
0.0.0.2 c ssh -t user#0.0.0.2 sudo -u node2 /path/script.sh
I try to grep the needed ssh command like this
comm=$(grep 0.0.0.2 node.txt | grep c | cut -f3)
when I run
status=$($comm)
the following error appears:
/path/script.sh not found
while if I hard coded the command in the script itself it work correctly,
comm='ssh -t user#0.0.0.2 sudo -u node2 /path/script.sh'
status=$($comm)
what could be the problem here?
#Karim Ater
Try the following at your system:
comm=$(grep 0.0.0.2 node.txt | grep c | cut -f3)
$ echo $comm
Hence I tried
comm=$(grep 0.0.0.2 node.txt | grep c | sed "s/.*ssh/ssh/;")
$ echo $comm
I cannot confirm the contents of node.txt to know related delimiter.
Hence I used sed instead of using cut.
I seem to have a weird issue:
I want to restart a reverse ssh tunnel on boot, I've tried it with an init script (that works fine when executed as user) and with an added line in /etc/rc.d but none of it works. What I get after boot is:
$ ps ax | grep autossh
397 pts/10 S+ 0:00 grep --color=auto autossh
1351 ? Ss 0:00 /usr/lib/autossh/autossh -M 22221 -N -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu#server
but I'm unable to login from server. So I did the following after boot:
$ sudo killall -KILL autossh
[sudo] password for ron:
$ /usr/bin/autossh -M 22221 -f -N -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu#server
upon which I can login using port 19999 just fine!
The keys permissions look like: (but root should not need to care, would it?)
$ ls -l ~/.ssh/etherwan.key
-r-------- 1 ron ron 1675 Nov 6 04:15 /home/ron/.ssh/etherwan.key
Replace ~/.ssh/etherwan.key in your rc.d script with /home/ron/.ssh/etherwan.key
The '~' character is expanded to the user's home directory by the shell, but rc.d scripts are run as root.
I want to know which port is my Jonas, on which a Java project has been deployed, is attached to in a Linux server. I have the pid of the Jonas and tried netstat -lnp but I found no port attached to that PID.
Any idea of how to do this.
Open a terminal application i.e. shell prompt.
Run any one of the following command:
sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo nmap -sTU -O IP-address-Here
lsof command
The syntax is:
$ sudo lsof -i -P -n
$ sudo lsof -i -P -n | grep LISTEN
$ doas lsof -i -P -n | grep LISTEN ### [OpenBSD] ###
There are many ways to do, I prefer this
sudo netstat -pan |grep pid
Also, you can use
sudo lsof -Pan -p pid -i
pid should be actual "pid" number that you have
I want to execute specific script at remote server by ssh in background.
I found some solution about nohup.
But, nohup is not running without "2>&1"
I want to know what's the difference between existing "2>&1" and not.
nohup needs "2>&1" expression?
(Please understand my bad English)
This is my 'iperf_server.sh' script.
iperf -s -p 1 -w 128K
And, It is my host machine command.
$ ssh [id]#[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null &"
$ ssh [id]#[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null 2>&1 &"
$ ssh -t [id]#[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null &"
Connection to iperf-server closed.
$ ssh -t [id]#[host] "nohup echo [password] | sudo -S [Home_DIR]/iperf_server.sh > /dev/null 2>&1 &"
Connection to iperf-server closed.
This is ps command result in iperf server
# ps -eLf | grep iperf | grep -v grep
# ps -eLf | grep iperf | grep -v grep
00:00:00 sudo -S [HOME_DIR]/iperf_server.sh
00:00:00 sh [HOME_DIR]/iperf_server.sh
00:00:00 iperf -s -p 1 -w 128K
00:00:00 iperf -s -p 1 -w 128K
00:00:00 iperf -s -p 1 -w 128K
# killall iperf
# ps -eLf | grep iperf | grep -v grep
# ps -eLf | grep iperf | grep -v grep
Take the & off the end.
This should do it:
ssh -t [id]#[host] "nohup echo [password] | sudo -S [Home_dir]/iperf_server.sh > /dev/null 2>&1"
By the way this is a huge security risk. Don't echo the password on the command line! If you really want to use a password like this at least do something like cat pwd.txt | sudo -S instead.
I'm writing a small script to restart my lighttpd server:
1. kill already running process
2. start new server
The script is the following:
PID=$(ps aux | grep lighttpd | grep -v grep | cut -c9-15)
kill $PID
sudo lighttpd -f /etc/lighttpd/lighttpd.conf
My problem is that in a terminal window the command
ps aux | grep lighttpd | grep -v grep | cut -c9-15
gives the result: 11685 but if it runs within the shell script than the result is 11685 13339 13340
What am I missing here?
The ps output of the line containing the lighttpd job is
root 11685 0.0 0.0 11096 1960 ? S 16:40 0:00 lighttpd -f /etc/lighttpd/lighttpd.conf
Why you are wasting time in Linux/unix for grepping PID and killing it when you have killall command
/usr/bin/killall
You can directly
killall lighttpd or /usr/bin/killall lighttpd
if not superuser then use sudo
sudo killall lighttpd or sudo /usr/bin/killall lighttpd
can use preferably -9 with killall like in your case would be sudo killall lighttpd
then restart it via
sudo lighttpd -f /etc/lighttpd/lighttpd.conf
if you are looking for fully automated script then make use of except commands
Click here