how do I kill a port in use -- eventmachine - ruby

I get the following error:
eventmachine.rb:534:in `start_tcp_server': no acceptor (port is in use or requires root privileges)
I'm not sure what the process or port is and want to kill it so I can run my script again.
How do I do that?

ps ax | grep ruby
kill -9 [pid]
Example:
ps ax | grep ruby
#=> 857 pts/19 Sl+ 0:04 /home/andreydeineko/.rvm/rubies/ruby-2.2.3/bin/ruby bin/rails server
#=> 14639 pts/18 S+ 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn rails
#=> 25368 pts/17 Sl+ 0:02 /home/andreydeineko/.rvm/rubies/ruby-2.2.3/bin/ruby bin/rails c
kill -9 857
ps ax | grep ruby
#=> 14639 pts/18 S+ 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn rails
#=> 25368 pts/17 Sl+ 0:02 /home/andreydeineko/.rvm/rubies/ruby-2.2.3/bin/ruby bin/rails c

Related

Why are zombie processes invisible when doing ps -f on mac?

Given this C program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
pid_t pid;
if ((pid = fork()) >= 0) {
if (pid == 0) {
exit(0);
} else {
sleep(999);
}
}
return 0;
}
after running:
$ gcc -o zombie zombie.c
$ ./zombie &
$ ps -f
only the parent process is showing:
501 77474 74651 0 2:36PM ttys000 0:00.00 ./zombie
On Linux the same program shows this:
osboxes 6900 6835 0 13:37 pts/1 00:00:00 ./zombie
osboxes 6903 6900 0 13:37 pts/1 00:00:00 [zombie] <defunct>
Now, strangely, on OSX when starting more than one zombie programs..
$ ./zombie &
$ ./zombie &
$ ps -f
.. the zombie processes (in brackets) show up:
501 77653 74651 0 2:39PM ttys000 0:00.00 ./zombie
501 77664 74651 0 2:39PM ttys000 0:00.00 ./zombie
501 77667 77664 0 2:39PM ttys000 0:00.00 (zombie)
What's the reason for this?

Rsync Multiple Sleeping Processes?

My rsync script for creating daily incremental backups is working pretty well now. But I have noticed after a week or so that I am left with hundreds of Sleeping Rsync Processes running. Has this to do with my script? Is there a command I can add to the script to stop this?
Here is the Bash Script
#!/bin/bash
LinkDest=/home/backup/files/backupdaily/monday
WeekDay=$(date +%A)
case $WeekDay in
Monday)
rsync -avz --delete --exclude backup --exclude virtual_machines /home /home/backup/files/backupdaily/monday
;;
Tuesday|Wednesday|Thursday|Friday|Saturday)
rsync -avz --exclude backup --exclude virtual_machines --link- dest=$LinkDest /home /home/backup/files/backupdaily/$WeekDay
;;
Sunday)
exit 0
;;
esac
here is my entry in the crontab -e logged in as root
#Backup Schedule
# Daily
* 0 * * * /usr/local/src/backup/backup_daily_v3.sh
This is the Process View
PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ COMMAND
1096 root 20 0 116M 1720 716 S 0.0 0.0 14:26.33 |- SCREEN
5169 root 20 0 105M 1428 1084 S 0.0 0.0 0:00.07 | |- /bin/bash
4012 root 20 0 105M 1188 968 S 0.0 0.0 0:00.00 | |- /bin/bash
1097 root 20 0 105M 980 676 S 0.0 0.0 0:00.34 | |- /bin/bash

Parse command output with awk and count results

I have an output from the 'multipath -ll' command
From RHEL:
mpath114 (3600507680283095ea8000000000004fa) dm-28 IBM,2145
[size=200G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=50][active]
\_ 19:0:0:40 sdea 128:32 [active][ready]
\_ 20:0:1:40 sdeb 128:48 [active][ready]
\_ 20:0:1:41 sdec 128:16 [failed][faulty]
\_ round-robin 0 [prio=10][enabled]
\_ 20:0:0:40 sdba 67:64 [active][ready]
\_ 19:0:1:40 sdgg 131:192 [active][ready]
mpath131 (3600507680283095ea800000000000504) dm-39 IBM,2145
[size=10G][features=1 queue_if_no_path][hwhandler=0][rw]
\_ round-robin 0 [prio=50][active]
\_ 20:0:1:1 sdbl 67:240 [active][ready]
\_ 19:0:0:1 sdc 8:32 [active][ready]
\_ round-robin 0 [prio=10][enabled]
\_ 19:0:1:1 sdet 129:80 [active][ready]
\_ 20:0:0:1 sdk 8:160 [active][ready]
[..]
Or from SLES server:
mpathmzp (36005076801c7061ef800000000000089) dm-0 IBM,2145
size=10G features='1 queue_if_no_path' hwhandler='0' wp=rw
|-+- policy='round-robin 0' prio=50 status=enabled
| `- 67:0:2:0 sde 8:64 active ready running
| `- 68:0:0:1 sdl 8:76 failed faulty running
`-+- policy='round-robin 0' prio=10 status=enabled
|- 67:0:3:0 sdc 8:32 active ready running
`- 68:0:0:0 sdd 8:48 active ready running
[..]
I would like to parse it (preferably with awk or bash), to display summary of the configuration.
It should print the pseudo multipath device and the number of active paths and the failed (if any)
Sample:
dm-39, 10G, Total: 4 paths, active: 4, failed: 0
dm-28, 200G, Total: 5 paths, active: 4, failed: 1
Same for the SLES:
dm-0, 10G, Total: 4 paths, active: 3, failed: 1
If also possible, I'd like to sort the output so that the paths with no failed and most active paths are on top, and end with the devicess with the failed paths.
Thanks for helping!
This awk should do:
multipath -ll | awk 'NR>1 {r=f=0;for (i=1;i<=NF;i++) if ($i~/ready/) r++; else if ($i~/faulty/) f++;split($5,a,"=|]");print $3,a[2]"\tTotal: "r+f" paths, active: "r,"failed: "f}' RS="mpath" OFS=", "
dm-28, 200G Total: 5 paths, active: 4, failed: 1
dm-39, 10G Total: 4 paths, active: 4, failed: 0

sidekiq does not process jobs, jobs stuck in enqueue

I have a simple application that works with the twitter stream api, sidekiq, unicorn and sinatra. All works well, instead of... the job are not being processed at all. They are stuck in Enqueued (And I know that from the sidekiq web UI).
This is my code:
Procfile:
sidekiq: bundle exec sidekiq -C config/sidekiq.yml -e development -r ./lib/tweet_streamer.rb
unicorn: bundle exec unicorn -c config/unicorn.rb
redis: redis-stable/src/redis-server
config/unicorn.rb:
listen 5000, :tcp_nopush => true
timeout 30
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
end
after_fork do |server, worker|
end
the tweet_streamer.rb:
require_relative "../config/tweetstream"
require_relative "workers"
class TweetStreamer
client = TweetStream::Client.new
client.on_enhance_your_calm do |s|
puts "on_enhance_your_calm #{s}"
end
puts "onstream"
client.userstream do |status|
##
## TODO: Some kind of log
##
puts "start process"
# TweetStatusWorker.perform_async(status.to_hash)
Sidekiq::Client.push('class' => TweetStatusWorker, 'args' => ["a"])
puts "process started!"
end
end
the workers.rb
require_relative "../config/sidekiq"
require_relative 'workers/tweet_status_worker'
the config/sidekiq.rb:
require 'sidekiq'
Sidekiq.configure_client do |config|
config.redis = { :size => 1 }
end
Sidekiq.configure_server do |config|
config.redis = { :size => 6 }
end
the worker:
class TweetStatusWorker
include Sidekiq::Worker
def perform(status)
logger.warn "I'm working on it!"
end
end
My sidekiq.yml:
---
:pidfile: tmp/pids/sidekiq.pid
development:
:verbose: true
:logfile: log/sidekiq_development.log
My config.ru:
require "rubygems"
require "sinatra"
Bundler.require
require File.expand_path '../twitter_module.rb', __FILE__
require 'sidekiq/web'
run Rack::URLMap.new('/' => TwitterModule, '/sidekiq' => Sidekiq::Web)
My app class:
require 'sinatra/base'
class TwitterModule < Sinatra::Base
end
This is the log that I received when I start the application and I make a tweet for start a process and all seems to be fine..
17:36:31 sidekiq.1 | started with pid 65599
17:36:31 unicorn.1 | started with pid 65600
17:36:31 redis.1 | started with pid 65601
17:36:31 redis.1 | [65601] 14 Oct 17:36:31.717 # Warning: no config file specified, using the default config. In order to specify a config file use redis-stable/src/redis-server /path/to/redis.conf
17:36:31 redis.1 | [65601] 14 Oct 17:36:31.718 * Max number of open files set to 10032
17:36:31 redis.1 | _._
17:36:31 redis.1 | _.-``__ ''-._
17:36:31 redis.1 | _.-`` `. `_. ''-._ Redis 2.6.16 (f132ada8/1) 64 bit
17:36:31 redis.1 | .-`` .-```. ```\/ _.,_ ''-._
17:36:31 redis.1 | ( ' , .-` | `, ) Running in stand alone mode
17:36:31 redis.1 | |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
17:36:31 redis.1 | | `-._ `._ / _.-' | PID: 65601
17:36:31 redis.1 | `-._ `-._ `-./ _.-' _.-'
17:36:31 redis.1 | |`-._`-._ `-.__.-' _.-'_.-'|
17:36:31 redis.1 | | `-._`-._ _.-'_.-' | http://redis.io
17:36:31 redis.1 | `-._ `-._`-.__.-'_.-' _.-'
17:36:31 redis.1 | |`-._`-._ `-.__.-' _.-'_.-'|
17:36:31 redis.1 | | `-._`-._ _.-'_.-' |
17:36:31 redis.1 | `-._ `-._`-.__.-'_.-' _.-'
17:36:31 redis.1 | `-._ `-.__.-' _.-'
17:36:31 redis.1 | `-._ _.-'
17:36:31 redis.1 | `-.__.-'
17:36:31 redis.1 |
17:36:31 redis.1 | [65601] 14 Oct 17:36:31.719 # Server started, Redis version 2.6.16
17:36:31 redis.1 | [65601] 14 Oct 17:36:31.728 * DB loaded from disk: 0.010 seconds
17:36:31 redis.1 | [65601] 14 Oct 17:36:31.728 * The server is now ready to accept connections on port 6379
17:36:33 unicorn.1 | I, [2013-10-14T17:36:33.208428 #65600] INFO -- : Refreshing Gem list
17:36:33 unicorn.1 | I, [2013-10-14T17:36:33.813454 #65600] INFO -- : listening on addr=0.0.0.0:5000 fd=9
17:36:33 unicorn.1 | I, [2013-10-14T17:36:33.814790 #65600] INFO -- : master process ready
17:36:33 unicorn.1 | I, [2013-10-14T17:36:33.816138 #65607] INFO -- : worker=0 ready
17:36:33 sidekiq.1 | onstream
17:36:43 sidekiq.1 | start process
17:36:43 sidekiq.1 | process started!
nothing in the sidekiq log obviously:
2013-10-14T16:36:43Z 65599 TID-ouo5je95k INFO: Booting Sidekiq 2.15.1 using redis://localhost:6379/0 with options {:size=>6}
2013-10-14T16:37:32Z 65599 TID-ouo5je95k DEBUG: Terminating 4 actors...
UPDATE:
Ok I found it. Is the streamer the problem. If I run the job outside of the streamer block, this works well. Any Idea about why this append and how I can solve it?

How to find Sidekiq is running or not

In one of my project i am using Sidekiq
Is there any inbuilt Sidekiq console method/method that helps me to find whether sidekiq is running or not.
My requirement is kind of a pre check condition where if Sidekiq is not running i will raise a error.
I tried using the grep like
'ps -ef | grep sidekiq'
but it's not solving my purpose.
The method i am looking for should be something like:
Sidekiq.is_running?
Thanks in advance.
I also Tried
Sidekiq not running
1.9.3p392 :021 > system 'ps aux | grep sidekiq'
ankitgupta 6683 0.0 0.0 2432768 600 s001 R+ 11:47AM 0:00.00 grep sidekiq
ankitgupta 6681 0.0 0.0 2433432 916 s001 S+ 11:47AM 0:00.01 sh -c ps aux | grep sidekiq
=> true
Sidekiq is running
1.9.3p392 :022 > system 'ps aux | grep sidekiq'
ankitgupta 6725 0.0 0.0 2432768 600 s001 S+ 11:57AM 0:00.00 grep sidekiq
ankitgupta 6723 0.0 0.0 2433432 916 s001 S+ 11:57AM 0:00.00 sh -c ps aux | grep sidekiq
ankitgupta 6707 0.0 1.3 3207416 111608 s002 S+ 11:56AM 0:07.46 sidekiq 2.11.2 project_name [0 of 25 busy]
=> true
It is always returning true.. I want to catch the process when it runs
A little trick:
ps aux | grep '[s]idekiq'
Hope it works
Ideally you can do this directly from ruby itself. Put this in some rake task or standalone script (don't forget to specify Sidekiq connection details)
ps = Sidekiq::ProcessSet.new
ps.size # => 2
ps.each do |process|
p process['busy'] # => 3
p process['hostname'] # => 'myhost.local'
p process['pid'] # => 16131
end
ps.each(&:quiet!) # equivalent to the USR1 signal
ps.each(&:stop!) # equivalent to the TERM signal
From https://github.com/mperham/sidekiq/wiki/API#processes
See this question for how to filter ps output using grep, while eliminating the grep command from the the output.
I see, try this out:
module Process
class << self
def is_running?(pid)
begin
Process.kill(0, pid)
true
rescue Errno::ESRCH
false
end
end
end
end
1.9.3p392 :001 > puts `ps aux | grep -i [s]idekiq`
It'll return you pid like: 12247, and you can check if it's running:
Process.is_running?(12247) // true | false
You can add the following lines to your config/routes.rb
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
Start your server, open a browser and check your processess and your jobs
You can find it from Sidekiq Wiki

Resources