Finding rails process server ID debian - ruby-on-rails

OK guys,
So i managed to get ruby and rails and all necessary gem installed on out server, (if anyone saw my last question, the firewall was blocking the download of the various packages and gems so they were being currupted) and I started up the rails server, works good, but I called it with -d and now have no idea how to end it..
I've researched, and apparently you have to use the kill command, thats all well and good but I can't find the process ID for the rails server... I'm not even sure what to look for.. in some posts I found before it told me to look in i think usr/lib/tmp, but i dont have a tmp in there..
so, anyone got a better answer for me?
p.s. its a debian server

You can list all ruby processes by running : ps aux |grep ruby.
The second columns contain the process id, you just have to use kill PROCESS_ID (replace PROCESS_ID by your process number) to terminate the server process.

Related

Address already in use issue when running rails

Hi all I am new to rails and I am facing issue with running the rails app in WSL. I generated a new rails project and just set it up for deployment using capistrano. The deployment was successful. However, now I cant run rails locally. rails s gives me error.
I am posting the log here
I tried checking the port to see if any process was using port 3000 but it showed nothing. The commands that I tried are
lsof -wni tcp:3000
ps aux | grep puma
but they show no process that I can kill. I dont think this is an issue with WSL because I can run another newly created rails app.
Any help is highly appreciated. Thanks
I used to get this error too. I then realised that after I deleted the server.pid file found in either:
management\tmp\pids or > gateway\tmp\pids
and restarted the service, it ended up working.
I recommend you make a local copy of the file(s) in the pid folder incase you need it, then delete it, restart your service and see what happens.

How to organize and rename unicorn_rails process name?

I am running a server with multiple Rails apps. I want a different unicorn process name for each app, e.g:
unicorn_ecommerce for the ecommerce app.
unicorn_hotsite for the hotsite.
Instead of the traditional "unicorn_rails" for every app. So when I type in the terminal pgrep -lf unicorn I get the apps currently running. I also would like to know if there is a better way to organize your unicorn processes.
I found this question while trying to differentiate my unicorn processes in ps aux | grep unicorn, not sure if you have the same kind of issues as Renaming Unicorn processes or if you'd be better served by one of the options in https://askubuntu.com/questions/157075/why-does-ps-aux-grep-x-give-better-results-than-pgrep-x
Just in case someone is looking for better names in ps aux there is a pretty simple solution that I'm sure most people figure out by themselves. If you're like me and needed a little help just use the following tip from the manpage:
Using an absolute path for CONFIG_FILE is recommended as it makes multiple instances of Unicorn easily distinguishable when viewing ps(1) output.
http://manpages.ubuntu.com/manpages/saucy/man1/unicorn_rails.1.html (-c, --config-file CONFIG_FILE section)
rename your /etc/init.d/unicorn_rails file to anything you want.
then your process will be spawn with this name as well.

Using Ubuntu 11.04, I can't shut down rails server using CTRL-C

For some reason, when I type "rails s", sometimes I can't shut the server down using CTRL-C. It's using Web brick, the default.
Sometimes it works for hours. Other times it doesn't work at all and I must constantly kill the process if I want to shut down the server.
Is this a known problem? How can I fix it?
If you need to know more info, please just ask and I'll tell you what I can. Because I don't know what is causing it, I am at a loss as to what info to provide you with.
EDIT: I am adding a git repository:
gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git', :require => 'rails_development_boost'
But to be fair, I've not had this problem with this line enabled... and I've also had this problem when this gem line didn't exist.
The way I solved this problem was to do the following:
To stop the rails server while it's running, press:
CTRL-C
CTRL-Z
You will get control back to bash. Then type (without the $):
$ fg
And this will go back into the process, and then quit out of Rails s properly.
It's a little annoying, but this sure beats killing the process manually. It's not too bad and it's the best I could figure out.
This is a kernel bug that affects Ubuntu 11.04 (it's fixed in 11.10, fwiw). You can install kernel 2.6.39 to fix it.
I'm using the xorg-edgers PPA which includes 2.6.39, and I don't experience the issue.

Ruby on Rails: How to start the WEBrick server automatically on Windows in background?

In order to run the my Rails application on Windows XP I open a command line, cd to application's directory, and then run rails server.
I would like to automate this, such that every time I turn on my computer, all I'll have to do is to type localhost:3000 in a browser.
How could I do this ?
The simpler way is to create a batch file with the instruction what you give in the command prompt like
d:
cd projects\myapp
ruby script\server
and then drop a copy of the file to Windows Start -> All Programs -> start up folder.
You have few possibilities to do that.
using the registry you can use HKLM\Software\Microsoft\Windows\CurrentVersion\Run or the better approach would be to create a service, you can see this KB with some instruction how to make a service of whatever executable you want.
have you thought about , AUTOEXEC.BAT or creating some batch files. you create right cmd commands that are run at start up. http://www.aumha.org/a/batches.php
The best approach is turn your application into a service. There is a solution for Mongrel (a web server similar to webrick) called mongrel_service, but is not compatible with Rails 3 (due several changes of Rails internals)
However, you can repurpose mongrel_service codebase to work with thin, another webserver that works with Rails 3.
Please look here where is the only reference to mongrel_service script. changing it to thin start could work.
Perhaps is not the answer you're looking for (as there is some work to be done) but is something :)
start rubyw script/rails server webrick
start -> start in another console
rubyw -> run ruby detached from console

Thinking Sphinx delta indexing fails in production

Here's what I've determined:
Delta indexing works fine in development
Delta indexing does not work when I push to the production server, and no action is logged in searchd.log
I'm running Phusion Passenger, and, as recommended in the basic troubleshooting guide, have confirmed that:
www-data has permission to run indexing rake tasks (ran them from command line manually)
the path to indexer and searchd are correct (/usr/local/bin)
there are no errors in production.log
What on earth could I possibly be missing? I'm running Ruby Enterprise 1.8.6, Rails 2.3.4, Sphinx 0.9.8.1, and Thinking Sphinx 1.2.11.
Thanks!
Last night as I slept it hit me. Unsurprisingly, it was a stupid issue involving bad configuration, though I am rather surprised that it produced the results it did. I guess I don't know much about Thinking Sphinx internals.
Recently I migrated servers. sphinx.yml looked like this:
production:
bin_path: '/usr/local/bin'
host: mysql.mysite.com
On the new server, MySQL was just a local service, but I had forgotten to remove that line. Interestingly, manual rake reindexing still worked just fine. I'm intrigued that Thinking Sphinx didn't throw an error when trying to reload the deltas, since mysql.mysite.com no longer exists, even though that was clearly the source of the issue.
Thanks for all your help, and sorry to have brought up such a silly problem.
Are there any clues in Apache/Nginx's error log?
Here's the next troubleshooting step I would take. Open up the file for the delta indexing strategy you are using (presumably lib/thinking_sphinx/deltas/default_delta.rb). Find the line where it actually generates the indexing command. In mine (v1.1.6) it's line 20:
output = `#{config.bin_path}indexer --config #{config.config_file} #{rotate} #{delta_index_name model}`
Change that so you can log the command itself, and maybe log the output as well:
command = `#{config.bin_path}indexer --config #{config.config_file} #{rotate} #{delta_index_name model}`
RAILS_DEFAULT_LOGGER.info(command)
output = `#{command}`
RAILS_DEFAULT_LOGGER.info(output)
Deploy that to production and tail the log while modifying a delta-indexed model. Hopefully that will actually show you the problem. Of course maybe the problem is elsewhere in the code and you won't even get to this point, but this is where I would start.
I was having this problem and found the "bin_path" solution mentioned above. When it didn't seem to work, it took me a while to realize that I'd pasted in the example code for "production" when I was testing on "stagiing" environment. Problem solved!
This was after making sure that the rake tasks that config, index, and start sphinx are all running as the same user as your passenger instance. If you log into the server as root to run these tasks, they will work in the console but not via passenger.
I had the same problem. Works on the command line, not inthe app.
Turns out that we still had a slave database that we were using for the indexing, but the slave wasn't getting updated.
As above, same issues were faced our side on two machine. The first one we had an issue with mysql which showed in apache2 log. Only seemed to affect local OSX machine..
Second time when we deployed to Ubuntu server, we had same issue. Rails c production was fine, no errors, bla bla bla.
Ended up being a permissions problem. Couldn't figure this out as there were no problems starting, although I guess I was doing so as root.
Using capistrano and passenger, we did this:
Create a passenger user and added to www-data group
Changed user in deploy.rb to be passenger
Manually changed all the /current files to be owned by above
Logged in as passenger user.
Ran rake ts:rebuild RAILS_ENV="production"
Worked a treat for us...
Good luck

Resources