How to start jscodeshift in inspect mode? - jscodeshift

This used to be runnable but recently I'm encounter the following issue.
By running the following command:
node --inspect-brk ./node_modules/.bin/jscodeshift mod.js file.
I am encountering this problem
Debugger listening on ws://127.0.0.1:9229/7e57a2d3-0885-44b3-b51e-b47dc8417d87
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
Starting inspector on 127.0.0.1:9229 failed: address already in use
All done.
Results:
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 0.035seconds

What worked for me:
Start node-inspector
Install jscodeshift in my local repo as a dev dependency.
put debugger statement in my script
run jscodeshift via node with --debug-brk arg and added --run-in-band jscodeshift param.
For example :-
I entered node
--debug-brk ./node_modules/jscodeshift/bin/jscodeshift.sh -t my-refactor-script.js --run-in-band
If you add a file pattern at the end, it works fine, which in the case of debugging is helpful when you want to test just one trouble file.
I did not test debugging jscodeshift installed via npm -g

The answer that worked for me was installing ndb, https://github.com/GoogleChromeLabs/ndb, and prefixing the command with it.
ndb node --inspect-brk ./node_modules/.bin/jscodeshift mod.js

The reason inspect mode doesn't work is because another process (e.g. another instance of the inspector) is already using the default port (9229), so they're conflicting. Either use a different port for the inspector or kill the process that's currently using the port.
If you use a different port, you'll be able to start the inspector. Just pass the desired port-number (e.g. 39479) to --inspect-brk.
Your example:
node --inspect-brk ./node_modules/.bin/jscodeshift mod.js file.
Could for example be: node --inspect-brk=39479 ./node_modules/.bin/jscodeshift mod.js file.
DANGER: If you need the port 9229, you can kill the process/inspector that's currently using that port, but if you don't know what that process is doing you could damage things: lsof -i TCP:9229 | grep LISTEN | awk '{print $2}' | xargs kill -9

Related

How to stop\close\kill tcp connection on macOS

First of all this is not a duplicate. Overall my question is:
I have another application currently running on macOS and I want to cut (sever or close or stop) it tcp connection from terminal. The problem is I don't want to kill process 'cause this is a solution what I found in another answers. + I have an access to sudo and I know the PID.
What I did and it doesn't work:
lsof -i TCP:X | awk '/LISTEN/ {print $2}' | xargs kill -9
I tried to change X to particular value which I got from this command
sudo lsof -i -n -P | grep TCP
The second thing placed here https://www.scm.keele.ac.uk/staff/stan/2016/05/16/closing-sockets-without-killing-processes/
But from that line lldb -p $PID I got an error like this:
error: attach failed: attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries when the attached failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
Maybe I missed something or maybe I should find a special program for my purpose? The Windows I see have one -> https://www.nirsoft.net/utils/cports.html
I'm really curious about it 'cause all answers which I found suggests users to kill all process. But I don't want it.
Ok.. just try to learn code from here -> https://github.com/doug-leith/appFirewall
Thanks dude for providing minus feedback for me. But my answer is the only one on internet which lead to working firewall!

Check status of GMediaRenderer

I use GMediaRenderer to send audio via UPNP from a Raspberry Pi. Occasionally, for reasons unknown, I have to SSH into my Pi and send the command sudo service gmediarenderer restart to get it to work properly. I'd like to add a command to crontab or similar that periodically checks whether the service is running properly. I already have a crontab entry that checks whether the service is running, and starts if it isn't. The trouble I'm having is that sometimes, even though the service is running, it doesn't appear to be communicating with UPNP control points. Executing the restart command brings it back, so I assume it is simply the case that the service has crashed but not closed down.
Does anyone know how to programmatically check (preferably using a bash script) whether the GMediaRenderer service is up and running?
I have found a solution to this. The command gssdp-discover returns a list of active renderers. I setup a sudo crontab job to run a bash script every minute that checks whether or not a particular renderer is running, and to restart gmediarenderer if it isn't found.
The following command will list your active renderers:
gssdp-discover -i wlan0 --timeout=3
Change wlan0 above depending on your specific network connection. In my case, the renderer that I'm interested in is listed as urn:av-openhome-org:service:Info:1 (run the command with and without the renderer active, and look for the one that only appears when running). So, my bash script contains the following:
gssdp-discover -i wlan0 --timeout=3 --target=urn:av-openhome-org:service:Info:1 | grep available &> /dev/null
if [ $? == 0 ]; then
echo "OpenHome renderer is already running"
else
echo "restarting gmediarenderer"
/etc/init.d/gmediarenderer stop
/etc/init.d/gmediarenderer start
fi

How can the strace logs of the ever running binary from rcS can be logged?

I am trying to do a profiling on my embedded Linux box. This is running a software.
I want to do a profiling on my software using strace.
The application is the main software that keeps running forever.
How can I run the strace and log the outputs to a file.
In my rcS script.
I run the application like this
./my_app
Now, with strace.
strace ./my_app -> I want to log these outputs on a file, and I should be able to access the file without killing the application. Remember this application never terminates.
Please help!
Instead of a target filename, use the -p option to strace to specify the process ID of an already running process you wish to attach to.
Chris is actually right. Strace takes the -p option, which enables you to attach to a running process just by specifying the processes PID.
Let's say your 'my_app' process runs with PID 2301 (you can see the PID by logging into your device and us 'ps'). Try doing 'strace -p 2301', and you will see all system calls for that PID. You can throw it to a file by redirecting everywhere: 'strace -p 2301 > /tmp/my_app-strace'.
Hope this helps.

Buffered pipe in bash

I'm running a Bukkit (Minecraft) server on a Linux machine and I want to have the server gracefully shut down using the server's stop command and the computer suspend at a certain time using pm-suspend from the command line. Here's what I've got:
me#comp~/dir$ perl -e 'sleep [time]; print "stop\\n";' | ./server && sudo pm-suspend
(I've edited by /etc/sudoers so I don't have to enter my password when I suspend.)
The thing is, while the perl -e is sleeping, the server is expecting a constant stream of bytes, (That's my guess. I could be misunderstanding something.) so it prints out all of the nothings it receives, taking up precious resources:
me#comp~/dir$ ...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...
Is there any such thing as a buffered pipe? If not, are there any ways to send delayed input to a script?
You may want to have a look at Bukkit's wiki, which recommends an init script for permanently running servers.
This init script uses rather unconventional approach to communicate with running server. The server is started in screen session, then all commands are send to the server console via screen, e.g.
screen -p 0 -S $SCREEN -X eval 'stuff \"stop\"\015'
See https://github.com/Ahtenus/minecraft-init/blob/master/minecraft
This approach suggest that bukkit may be expecting standard input to be attached to a terminal, thus requiring screen wrapper (which is itself terminal emulator) for unattended runs.

JMeter load test thread dump

I am using JMeter for load testing and some of my threads just hang. I want to do a thread dump but none of the following work from my linux machine
First get JMeter process id using
jps -l
Then did
sudo -u <username> jstack <pid>
and get the following msg
15141: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding
even
kill -3 15141
comes up with nothing
After lot of googling and trial and error found the solution
To take thread dumps, start JMeter using command line.
Open terminal (A)
$ cd /media/9260C06E60C05A9D/Downloads/jakarta-jmeter-2.4/bin
$ ./jmeter > temp
In another terminal (B)
Get the process id of JMeter
$ jps -l
$ kill -QUIT 21735
Now check temp file for thread dump.
In order to use jstack make sure the user and group user are the same as the user running jstack

Resources