How to disable guard after uninstalling Ruby? - ruby

I installed Ruby on a server (1.9.3 via RVM), set up Guard on some directories, then established I didn't need any of this anymore and uninstalled Ruby (via an RVM command).
My problem is, any directory access to the directories Guard was watching still triggers an attempt to launch Ruby (which is no longer there), therefore causing an error.
I thought that, since Guard was a Ruby gem, uninstalling Ruby would "turn off" guard. It seems there's more to it than that, and that some process still remains.
How do I kill the ghost of guard?
Another thread suggested I run ps aux | grep guard to find the PID of the guard process then kill it, but the only thing that finds is the grep guard itself:
root 6754 0.0 0.0 6384 676 pts/1 S+ 13:45 0:00 grep guard
It seems like whatever this "ghost of guard" is, it's not called guard.
It's probably not relevant, but in case it is, guard was launched via the Drupal Drush command drush omega-guard which is part of the Drupal theme Omega-4, and here's an example of an error that the ghost of guard is causing (this is accessing the Centos server from windows using SFTP):

This command should list all the processes using Linux inotify subsystem on which Guard is based:
$ ps -p `find /proc -name task -prune -o -type l -lname anon_inode:inotify -print 2> /dev/null | cut -d/ -f3`
PID TTY STAT TIME COMMAND
1102 ? Ssl 0:16 evince
3651 ? Ss 0:01 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
4071 ? Sl 0:00 /usr/lib/x86_64-linux-gnu/ibus/ibus-gconf
4075 ? Sl 1:08 /usr/lib/x86_64-linux-gnu/ibus/ibus-x11 --kill-daemon
4092 ? Sl 0:18 /usr/lib/ibus-mozc/ibus-engine-mozc --ibus
4468 ? Ssl 188:36 skype
4788 ? S<l 622:27 /usr/bin/pulseaudio --start --log-target=syslog
7102 pts/0 S+ 0:00 inotifywait -r -m -e modify --format %f JavaFXSceneBuilder2.0/
7998 ? Ssl 6:53 gvim
8549 ? Ssl 11:11 /opt/google/chrome/chrome
8597 ? Ssl 307:04 /usr/lib/firefox/firefox
9459 ? Sl 50:05 /usr/lib/firefox/plugin-container /usr/lib/flashplugin-installer/libflashplayer.so -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 8597 true plugin
16444 ? Ssl 1:31 gvim
16452 ? Ssl 24:39 /home/nodakai/.dropbox-dist/dropbox-lnx.x86_64-2.10.27/dropbox
24514 ? S 0:01 /usr/lib/gvfs/gvfs-gdu-volume-monitor
24527 ? Sl 0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
32491 ? Sl 11:10 /usr/lib/libreoffice/program/soffice.bin --splash-pipe=5
You might as well install Ruby and Guard again to uninstall them in a proper way.

Related

systemd and StandardInput. taking control of tty

I have a systemd unit script which looks something like this
cat /usr/lib/systemd/system/hello.service
[Unit]
Description=Simple Hello World service
After=syslog.target network.target
[Service]
Type=forking
EnvironmentFile=/root/hello.env
ExecStart=/bin/gdb /root/hello
StandardInput=tty-force
StandardOutput=inherit
TTYPath=/dev/pts/0
TTYReset=yes
TimeoutStartSec=infinty
[Install]
WantedBy=multi-user.target
The whole point is, i want to start the service with gdb on start up.[Since the process involves lot of environmental variables i cannot use the gdb directly on the process.]
systemctl start hello (which is actually working).
But once i exit out of gdb tty is completely messed up.None of the control key work, ^Z, ^C.
This are the observation till now.
As describer by systemd man pages with "StandardInput=tty-force", will actually force the executing process to take control of tty.
Before i launch the process
# tty
/dev/pts/0
# ps -aef | grep bash
root 2805 2803 0 10:42 pts/0 00:00:00 -bash
root 2860 2805 0 10:45 pts/0 00:00:00 grep --color=auto bash
After i launch
# tty
/dev/pts/0
# ps -aef | grep bash
root 2805 2803 0 10:42 ? 00:00:00 -bash
root 2884 2805 0 10:47 ? 00:00:00 grep --color=auto bash
Tried reset the terminal, still doesn't work.
subsequent systemctl command dsplay the below error
systemctl stop hello
Error creating textual authentication agent: Error opening current controlling terminal for the process (`/dev/tty'): No such device or address (polkit-error-quark, 0)
So the question is is there a way to reset the tty back to bash ?

nohup job control rhel6/centos

I have a question about UNIX job control in RHEL6
Basically, I am trying to implement passenger debug log rotation using logrotate. I am following the instructions here:
https://github.com/phusion/passenger/wiki/Phusion-Passenger-and-logrotation
I've got everything setup correctly (I think). My problem is this; when I spawn the background job using
nohup pipetool $HOME/passenger.log < $HOME/passenger.pipe &
And then log out and back in, if I inspect the process table, for example by using 'ps aux' if I check the pid of the process it appears as with the command 'bash'. I have tried changing the first line of the command to "#!/usr/bin/ruby". Here is an example of this:
[root#server]# nohup pipetool /var/log/nginx/passenger-debug.log < /var/pipe/passenger.pipe &
[1] 63767
[root#server]# exit
exit
[me#server]$ sudo su
[sudo] password for me:
[root#server]# ps aux | grep 63767
root 63767 0.0 0.0 108144 2392 pts/0 S 15:26 0:00 bash
root 63887 0.0 0.0 103236 856 pts/0 S+ 15:26 0:00 grep 63767
[root#server]#
When this occurs the line in the supplied logrotate file ( killall -HUP pipetool ) fails because the 'pipetool' is not matched. Again, I've tried changing the first line to #!/usr/bin/ruby. This had no impact. So, my question is basically; is there any good way to have the actual command appear in the process table instead of just 'bash' when spawned using job control? I am using bash as the shell when I invoke the pipetool. I appreciate you taking the time to help me.
This should work for you: edit pipetool to set the global variable $PROGRAM_NAME:
$PROGRAM_NAME = 'pipetool'
The script should then show up as pipetool in the process list.

What is a Rack - "no acceptor" error?

While trying to run my config.ru, I'm getting an odd error I can't seem to debug called a 'No acceptor' error.
Full error message:
eventmachine.rb:572:in `start_tcp_server': no acceptor (RuntimeError)
Does anyone know what this error means? Thanks.
As #Fivell says, I think the problem is that you have a previous instance of thin still running. Rather than start on another port though, I would recommend killing the previous instance. Something like this should do the job (I recreated the problem here, so this is real output on my end):
telemachus caps $ ps ax | grep ruby
153 ?? S 7:52.18 ruby /usr/local/bin/djsd
15801 ?? S 0:00.40 ruby caps.rb # this is our problem, get it's PID
15973 s000 S+ 0:00.00 grep ruby
telemachus caps $ kill -9 15801 # thin needs -9 - hard to kill
telemachus caps $ ps ax | grep ruby
153 ?? R 7:52.86 ruby /usr/local/bin/djsd
16057 s000 S+ 0:00.00 grep ruby
Depending on how you started your app, you may need to grep for something different (say if you used shotgun or rackup).
I think the problem is that using port is already binded (maybe you started your application earlier) Try to change port
rackup config.ru -p port #default port is 9292 change to something else
or if you use thin
thin start -p port -a 0.0.0.0 -R config.ru #default port is 8080 change to something else
I am getting this error although there are no zombie processes and the port is not binded.
This works:
thin -p9292 start
But this does not:
rackup

Popen getting pid of newly run process

I want to run some application in background and later kill it by pid.
pipe = IO.popen("firefox 'some_url' 2>&1 &")
pipe.pid
This code starts firefox and return me some pid, but unfortunately it's not firefox's pid.
pipe = IO.popen("firefox")
pipe.pid
This code starts firefox and return mi some pid, firefox's pid.
Is there any solution to start external application and get its pid? Firefox is only for example it could be any other application. I also tried with libs like: Open3 and Open4 but seems to be the same effect.
I also wonder if '$!' bash variable is good solution for this? Run something in background and read '$!', what do you think?
Since you are running it in the background (command &), you get the interpreter's PID:
>> pipe = IO.popen("xcalc &")
>> pipe.pid
=> 11204
$ ps awx | grep "pts/8"
11204 pts/8 Z+ 0:00 [sh] <defunct>
11205 pts/8 S+ 0:00 xcalc
Drop the &:
>> pipe = IO.popen("xcalc")
>> pipe.pid
=> 11206
$ ps awx | grep "pts/8"
11206 pts/8 S 0:00 xcalc
For the additional issue with the redirection, see #kares' answer
it's not just about running it in the background but also due 2>&1
redirecting err/out causes IO.popen to put another process in front of your actual process ( pipe.pid won't be correct)
here's a detailed insight: http://unethicalblogger.com/2011/11/12/popen-can-suck-it.html
possible fix for this could be using exec e.g. IO.popen("exec firefox 'some_url' 2>&1")

How to kill a process in MacOS?

I tried kill -9 698 but the process did not die.
$ ps -ef | grep chromium
502 698 811 0 0:01.24 ?? 0:07.28 /Users/lucius/chromium/src/xcodebuild/Debug/Chromium.app/Contents/MacOS/Chromium
502 854 732 0 0:00.00 ttys001 0:00.00 grep chromium
$ kill -9 698
$ ps -ef | grep chromium
502 698 811 0 0:01.24 ?? 0:07.28 /Users/lucius/chromium/src/xcodebuild/Debug/Chromium.app/Contents/MacOS/Chromium
502 854 732 0 0:00.00 ttys001 0:00.00 grep chromium
If you're trying to kill -9 it, you have the correct PID, and nothing happens, then you don't have permissions to kill the process.
Solution:
$ sudo kill -9 PID
Okay, sure enough Mac OS/X does give an error message for this case:
$ kill -9 196
-bash: kill: (196) - Operation not permitted
So, if you're not getting an error message, you somehow aren't getting the right PID.
Some cases you might want to kill all the process running in a specific port. For example, if I am running a node app on 3000 port and I want to kill that and start a new one; then I found this command useful.
Find the process IDs running on TCP port 3000 and kill it
kill -9 `lsof -i TCP:3000 | awk '/LISTEN/{print $2}'`
If you know the process name you can use:
killall Dock
If you don't you can open Activity Monitor and find it.
Do you can list the process using a port with command lsof, for example:
lsof -i tcp:PORT_NUMBER_HERE
Replace the word PORT_NUMBER_HERE to the port number that you are using, then a the process running on the port will be listed. Then you have just to kill the process ID founded like this:
kill PID_NUMBER
Where PID_NUMBER is the process ID running on the port.
If kill -9 isn't working, then neither will killall (or even killall -9 which would be more "intense"). Apparently the chromium process is stuck in a non-interruptible system call (i.e., in the kernel, not in userland) -- didn't think MacOSX had any of those left, but I guess there's always one more:-(. If that process has a controlling terminal you can probably background it and kill it while backgrounded; otherwise (or if the intense killing doesn't work even once the process is bakcgrounded) I'm out of ideas and I'm thinking you might have to reboot:-(.
I just now searched for this as I'm in a similar situation, and instead of kill -9 698 I tried sudo kill 428 where 428 was the pid of the process I'm trying to kill. It worked cleanly for me, in the absence of the hyphen '-' character. I hope it helps!
Given the path to your program, I assume you're currently running this under Xcode, and are probably at a debug breakpoint. Processes cannot be killed in this state because of the underlying implementation of breakpoints.
The first step would be to go to your Xcode process and stop debugging. If for some strange reason you have lost access to Xcode (perhaps Xcode has lost access to its gdb sub-process), then the solution is to kill the gdb process. More generally, the solution here is to kill the parent process. In your case this is PID 811 (the third column).
There is no need to use -9 in this case.
I have experienced that if kill -9 PID doesn't work and you own the process, you can use kill -s kill PID which is kind of surprising as the man page says you can kill -signal_number PID.
in the spotlight, search for Activity Monitor. You can force fully remove any application from here.
I recently faced similar issue where the atom editor will not close. Neither was responding. Kill / kill -9 / force exit from Activity Monitor - didn't work. Finally had to restart my mac to close the app.

Resources