Why can't I stop Solr from running? - ruby-on-rails-3

The sunspot_solr version that I am using is 1.3.3.
I am using sunspot_solr gem to start and stop a local instance of Solr. I use the following command to start it:
rake sunspot:solr:start
and the following command to stop it:
rake sunspot:solr:stop
However, stop is not working. I noticed that the pid written in the pids folder is not the correct one.
When I start, I can see the following as output on the ps -ef | grep 'java' command:
1000 4758 4752 0 20:32 ? 00:00:00 sh -c java -Djetty.port\=8982 -Dsolr.data.dir\=/home/panayotis/my_documents/ezMTA/solr/data/development -Dsolr.solr.home\=/home/panayotis/my_documents/ezMTA/solr -Djava.util.logging.config.file\=/tmp/logging.properties20120902-4758-13patuu -jar start.jar
1000 4761 4758 7 20:32 ? 00:00:01 java -Djetty.port=8982 -Dsolr.data.dir=/home/panayotis/my_documents/ezMTA/solr/data/development -Dsolr.solr.home=/home/panayotis/my_documents/ezMTA/solr -Djava.util.logging.config.file=/tmp/logging.properties20120902-4758-13patuu -jar start.jar
This means that the real server process is the one with pid "4761". Process "4758" is only there to start the server in a shell.
When I cat the pid file I see:
cat solr/pids/development/sunspot-solr-development.pid
4758
Which means that rake sunspot:solr:stop is killing "4758" and leaves "4761" up and running.

it's a bug!
1000 4758 4752 0 20:32 ? 00:00:00 sh -c java -Djetty.port\=8982 - Dsolr.data.dir\=/home/panayotis/my_documents/ezMTA/solr/data/development -Dsolr.solr.home\=/home/panayotis/my_documents/ezMTA/solr -Djava.util.logging.config.file\=/tmp/logging.properties20120902-4758-13patuu -jar start.jar
1000 4761 4758 7 20:32 ? 00:00:01 java -Djetty.port=8982 -Dsolr.data.dir=/home/panayotis/my_documents/ezMTA/solr/data/development -Dsolr.solr.home=/home/panayotis/my_documents/ezMTA/solr -Djava.util.logging.config.file=/tmp/logging.properties20120902-4758-13patuu -jar start.jar
because process 4758 is a foreground process, but process 4761 is a background process,so if you kill pid 4758,it will not destroy his child process 4761, the init process will become process 4761's parent!
in sunspot_solr/lib/sunspot/solr/server.rb #line 103
exec(Shellwords.shelljoin(command))
Shellwords.shelljoin(command) is a string,but Kernel#exec descrip:
exec([env,] command... [,options])
If single string is given as the command, it is taken as a command line that is subject to shell expansion before being executed.The standard shell means always "/bin/sh" on Unix-like systems.
so,it will start two process.
use this:
exec(*command)
will start one process,so rake sunspot:solr:stop will work correct.
see this pull request

I have downgraded to 'sunspot_solr', '1.3.1' and now it works ok.

Set env like this - RAILS_ENV=production rake sunspot:solr:stop

Related

podman - How to Start a Process in a Containerfile?

I have put a script with an endless loop inside a Containerfile.
When I go inside the container and run that script in the background I can see that the process is running by doing a ps -ef.
But when I try to start the process inside the Containerfile it is not running, even though the podman build and podman run commands are without error.
I am using rootless podman.
This is my Containerfile:
$ cat Containerfile
FROM alpine
RUN apk update
RUN apk add vim
RUN apk add bash
COPY ./useless_process.sh /home
RUN bash /home/useless_process.sh &
# how to build:
# podman build . -t "manualpihimage"
# how to run:
# podman run -it --name "manualpihcontainer" manualpihimage
I have also tried using the CMD and the ENTRYPOINT commands but the process did not start.
The expectation was that the process would run in the background.
I have tried it with Containerfile as follows. Note that I removed the useless & - makes no sense in the context of the container and used CMD because we don't want to run it while building the image but when we start the container.
FROM alpine
RUN apk update
RUN apk add vim
RUN apk add bash
COPY ./useless_process.sh /home
CMD bash /home/useless_process.sh
I created useless_process.sh with:
#!/bin/sh
while `/bin/true`; do
date
sleep 1
done
Then podman build . -t=image1 and podman run -d --name=container1 image1 to start it detached.
$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0744f29bec7c localhost/image1:latest /bin/sh -c bash /... 22 seconds ago Up 23 seconds ago container1
And we can see our useless process is running
$ podman exec -it container1 /bin/sh
/ # ps
PID USER TIME COMMAND
1 root 0:00 bash /home/useless_process.sh
188 root 0:00 /bin/sh
197 root 0:00 sleep 1
198 root 0:00 ps

ps call missing processes in Yocto

I'm trying to report on running processes in Yocto (Poky). ps aux doesn't work here, but standard ps call return much of what aux would in Debian. But it won't report my .sh script processes. Is there an argument that works here, or another call I can try? Thanks in advance.
You are probably using busybox. Busybox contains its own version of ps and might not have support for the flags you're using. A simple ls -l /bin/ps should give you indications whether or not it's symlinked to busybox or not.
My suggestion would be to include the package procps in your recipe (which contains the ps you're more familiar with).
Busybox ps should show you all your processes.
I've created this test script, pstest.sh:
#!/bin/sh
while true; do
sleep 10;
done
Which I've been running, both on a Debian box, aon a qemux86 based core-image-minimal, and on a custom embedded device built with OpenEmbedded / Yocto. (I.e. the last one is not running the Yocto kernel). On all of these devices, the following holds true:
# ./pstest.sh &
# ps
PID USER VSZ STAT COMMAND
1 root 4196 S {systemd} /sbin/init
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
5 root 0 SW< [kworker/0:0H]
.....
633 root 2452 S {pstest.sh} /bin/sh ./pstest.sh
634 root 2732 S sleep 10
638 root 3044 R ps
As you can see, I'm seeing the script process, as well as the sleep command. (Note: on Debian ps above has been replaced with busybox ps).
If you still can only see the sleep, could you try the following:
# cat /proc/`pidof sleep`/status | grep PPid
PPid: 633
By running that line, you should be able to see the parent PID of the sleep command; check which process that corresponds to.

Unable to start RabbitMQ

I have Googled so much, and not got any proper answer.So , I am posting this question for better result.
I have already killed the RabbitMQ server process .
Now when I am trying to start it again, it shows
Command
rabbitmqctl start_app
Error
{error_logger,{{2013,11,4},{11,26,8}},"Cookie file /ngs/app/ttet/.erlang.cookie must be accessible by owner only",[]}
{error_logger,{{2013,11,4},{11,26,8}},crash_report,[[{initial_call,{auth,init,['Argument__1']}}, {pid,<0.18.0>},{registered_name,[]},{error_info,{exit,{"Cookie file /ngs/app/curot/.erlang.cookie must be accessible by owner only",[{auth,init_cookie,0,[{file,"auth.erl"}, {line,285}]},{auth,init,1,[{file,"auth.erl"},{line,139}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,297}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"}, {line,227}]}]},[{gen_server,init_it,6,[{file,"gen_server.erl"},{line,321}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}},{ancestors,[net_sup,kernel_sup,<0.9.0>]},{messages,[]},{links,[<0.16.0>]},{dictionary,[]},{trap_exit,true},{status,running},{heap_size,610},{stack_size,24},{reductions,401}],[]]}
{error_logger,{{2013,11,4},{11,26,8}},supervisor_report,[{supervisor,{local,net_sup}}, {errorContext,start_error},{reason,{"Cookie file /ngs/app/ttet/.erlang.cookie must be accessible by owner only",[{auth,init_cookie,0,[{file,"auth.erl"},{line,285}]},{auth,init,1,[{file,"auth.erl"},{line,139}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,297}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,227}]}]}},{offender,[{pid,undefined},{name,auth},{mfargs,{auth,start_link,[]}},{restart_type,permanent},{shutdown,2000},{child_type,worker}]}]}
{error_logger,{{2013,11,4},{11,26,8}},supervisor_report,[{supervisor,{local,kernel_sup}},{errorContext,start_error},{reason,shutdown},{offender,[{pid,undefined},{name,net_sup},{mfargs,{erl_distribution,start_link,[]}},{restart_type,permanent},{shutdown,infinity},{child_type,supervisor}]}]}
{error_logger,{{2013,11,4},{11,26,8}},std_info,[{application,kernel},{exited,{shutdown,{kernel,start,[normal,[]]}}},{type,permanent}]}
{"Kernel pid terminated",application_controller,"{application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}}"}
Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,kernel,{shutdown,{kernel,start,[normal,[]]}}})
Erlang is running . Is it require to kill Erlang process.
[ttet#addr:17.566.98.656 Erlang]$:/ngs/app/ttet> ps -ef | grep erlang
ttet 13813 10547 0 11:57 pts/0 00:00:00 grep erlang
ttet 32155 1 0 Oct08 ? 00:00:14 /ngs/app/ttet/softwares/Erlang/lib/erlang/erts-5.9/bin/epmd -daemon
This helped me:
chmod 600 ~/.erlang.cookie
rabbitmqctl start_app
You can use rabbitmqctl start_app only after you call rabbitmqctl stop_app. These commands starts/stops RabbitMQ application, not Erlang node. If you really killed RabbitMQ node you need to call rabbitmq-server to start RabbitMQ. Check is there RabbitMQ node running you can calling ps -ef | grep rabbit.
Also from your logs I figured out that the reason of errors is not appropriate .erlnag.cookie file access mode - {error_info,{exit,{"Cookie file /ngs/app/curot/.erlang.cookie must be accessible by owner only".... Try to change it chmod 600 /ngs/app/curot/.erlang.cookie and start RabbitMQ server again.
It is not require to kill Erlang epmd as it is a daemon that acts as a name server on all hosts involved in distributed Erlang computations and does not interfere on you RabbitMQ instance.
I have solved this.
First step is I have changed the permission to /ngs/app/curot/.erlang.cookie.
And 2nd step I used rabbitmq-server -detached command for start the rabbitmq.
Now its working for me.

how to run rake task in background in rails

This is my command
bundle exec rake resque:work QUEUE="*" --trace
I want to run this command on my server as a background process.
please help me.
A method I often use is:
nohup bundle exec rake resque:work QUEUE="*" --trace > rake.out 2>&1 &
This will keep the task running even if you exit your shell. Then if I want to just observe trace output live, I do:
tail -f rake.out
And you can examine rake.out at any time.
If you need to kill it before completion, you can find it with ps and kill the pid.
Just in case somebody finds this 4 years later, bundle has an elegant way of doing this now. For example if you want to run sidekiq in the background you can do:
bundle exec sidekiq -e production -d -L ./log/sidekiq.log
The -d daemonizes to run in the background, but you will also need to use the -L to provide a logfile, else bundler will refuse to run your command in the background (deamonize).
Tested with bundler version 1.15.4
Update Oct 2019.
While the command still works in general, the specific command above will no longer work for sidekiq 6.0+, you'll need to use Upstart or Systemd if you use Linux: https://github.com/mperham/sidekiq/wiki/Deployment#running-your-own-process

ROR + A server is already running. Check .../tmp/pids/server.pid. Exiting

In my Rails Project, I am trying to run two different servers at different port. But it fails by giving this error at console.
C:\Rails>rails s
=> Booting Mongrel
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
A server is already running. Check C:/Rails/tmp/pids/server.pid.Exiting
Please check the updated answer.
After googling a lot, I just delete that file and restart the server. Then again system create that file, then again I delete that file. Now Server is running fine. And System generates another copy at the same place. But it is running well.
DELETE THAT FILE ....
If you want to run two servers then it may again create trouble. So
Both commands are checking the default PID file location (tmp/pids/server.pid), so you're seeing this error. Try running multiple servers like so:
Server 1: bundle exec rails s
Server 2: bundle exec rails s -p 3001 -P tmp/pids/server2.pid
Credit: https://stackoverflow.com/a/14446920/1376448
Thanks
UPDATE after Connor Leech comment about Forman Gem
Foreman can help manage multiple processes that your Rails app depends
upon when running in development. It also provides an export command
to move them into production.
You can use netstat to know which process is holding the rails webserver, then you can kill the pid and start it over again, assuming that for some weird reason the server is not responding or running in background and you don't find another way to restart it..
netstat -plntu | grep 3000
tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 7656/ruby
The last column shows the PID and the process name, then you only need to do:
kill -9 7656
and rails s to get it working again...
Hope it's useful
I find myself coming back to this webpage a lot to find the lsof -wni tcp:3000 command so I've found this method to be easier.
If you get this message:
A server is already running. Check /Users/username/project/tmp/pids/server.pid.
Exiting
And if you're running on a unix system (mac or linux) you can run these commands:
$ cat /Users/username/project/tmp/pids/server.pid
# output
71030
# Kill the process
$ kill -9 71030
Then run your server again!
I deleted the file with cd'ing in to the tmp directory then removing the file
rm server.pid
Then I restarted the server and I got this error
Exiting/Users/josephmellin/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/socket.rb:206:in `bind': Address already in use - bind(2) for 0.0.0.0:3000 (Errno::EADDRINUSE)
Then I could use the following command to see which process is running.
sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
And after I entered my password, I got this resoponse
ruby 2786 josephmellin 12u IPv4 0xfeadd8ae849eaec9 0t0 TCP *:3000 (LISTEN)
And then killed the process with the following command
KILL -9 2786
And then restarted the server (you will have a different number than 2786 - I left it here for demo purposes)
Step 1: remove .pid
C:/Rails/tmp/pids/server.pid.Exiting
# IN linux/unix shell
$ rm -rf <path to file>
Sometime this doesn't solve the problem, then you have to kill the process running by localhost, for such cases, follow STEP 2
STEP 2: List the process for localhost and kill it
# For Linux/Unix shell
$ lsof -wni tcp:3000
# output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 5946 rails 11u IPv4 79073 0t0 TCP *:3000 (LISTEN)
ruby 5946 rails 12u IPv4 103786 0t0 TCP 127.0.0.1:3000->127.0.0.1:53612 (ESTABLISHED)
# Kill the running process
$ kill -9 5946
run your server again
rails server
ps aux | grep rails
or
bundle exec rails s -p 3001 -P tmp/pids/server2.pid
Every instance of a RoR server creates a PID file. By default it is
#{Rails.root}/tmp/pids/server.pid
and if that file already exists it will refuse to start a new server.
To run more than one server of the same project on the same machine you should manually specify the PID file name for each instance of the server (I recommend simply appending a hyphen and the port number) using the -P option:
rails s -p 1234 -P tmp/pids/server-1234.pid
I'm told in some cases you may need to supply a full (rather than relative) path, but I don't know what those cases are.
You can see the PID for each proccess(the first column) :
ps vax | grep rails
// OR: ps auxw | grep rails
5236 pts/1 Sl+ 1:46 2 0.2 /usr/bin/ruby1.9.1 script/rails s -p 3001
5298 pts/2 Sl+ 0:12 2 0.7 /usr/bin/ruby1.9.1 script/rails s -p 3003
7356 pts/5 Sl+ 0:09 2 0.9 /usr/bin/ruby1.9.1 script/rails s -p 3002
7846 pts/3 Sl+ 0:19 2 1.7 /usr/bin/ruby1.9.1 script/rails s
Then kill the server:
kill -9 <pid>
To kill all running apps with "rails" in the name:
killall -9 rails
Use rails default commands, for example:
rake tmp:clear
Works for me, and really simple. ;)
single line command, that will take care of it.
kill -9 $(more C:/Rails/tmp/pids/server.pid)
I just had this problem, just deleted server.pid file and server works fine!
Remove that file: C:/Rails/tmp/pids/server.pid
A simpler way in which I found lesser commands . Go to the path which says a server is running in your folder structure . Search for the file. On the file itself shows a number which is the process id that is currently running. Lets say if the number is 'x', then simply type this command into your terminal
kill -9 x
However, note that this works in Ubuntu. Not sure, if it works in other OS as well.
Try to change the number in the pid file to another and save it.