How to stop and run Vapor again in Xcode? - vapor

I've followed the Vapor tutorial to create a hello app. In Xcode, when I run the Run scheme on my Mac, the app starts and runs as I can see by opening http://localhost:8080/. After making some changes in the code, I stop the Run scheme and I expect the Vapor server to shutdown. However, it continues to serve requests.
Message from debugger: The LLDB RPC server has exited unexpectedly. Please file a bug if you have reproducible steps.
Program ended with exit code: -1
Obviously when I make some changes and run the Run scheme again, I get the following runtime error:
Swift/ErrorType.swift:200: Fatal error: Error raised at top level: bind(descriptor:ptr:bytes:) failed: Address already in use (errno: 48)
Program ended with exit code: 9
How do I stop or restart the server?

This is a long standing issue with Xcode/LLDB. You have a few options:
attach to the process and stop it via Xcode
run killall Run
run lsof -i :8080 to find the process connected to port 8080 and then kill <process_id> (this is useful if you're running multiple apps side by side and only want to terminate the orphaned one)

This is quite frustrating and to be honest I dont know why this happens, but I do the following to terminate the process:
In Xcode,
Go to Debug -> Attach to Process
At the very top of the sub-menu is: Likley targets section with an entry Run (nnnn). It will have an icon of the Terminal application
Click to attach
Then stop the Xcode Run in the usual way.
Out of interest, the next time you run your vapor app, if you open the Debug Navigator, at the top you will see the Terminal icon with Run PID nnnn. Where nnnn is the PID. If you go to Debug -> Attach to Process again, you can see this at the top of the sub-menu as before. But you wont be able to attach to it because it is already being debugged.
Hope this helps you or someone in the future.

Related

React cannot find entry file in any of the roots

I am using React Native as a Pod in my iOS project.
When I try to load a view that I created with React Native I get the Error screen referring me to the Terminal window where npm is running.
In the Terminal the error I am seeing is:
Error: Cannot find entry file in any of the roots:
I tried a few things, moving the file to a different location, but no luck.
I did run "npm start" and I am looking for the file in "http://localhost:8081/".
The current location of the file is in the same location as where I ran "npm start" from.
I am completely stuck here.
Did I configure something wrong. How can I troubleshoot from here?
Check for the node server running in one of the bash terminal, this was probably kicked by previous ReactNative XCode project you launched earlier. Stop that process and run XCode project again, this should fix the problem.
Sorry for answering my own question (a bit lame), but I hope it helps somebody else.
Apperantly we need run the npm command by giving an alternative path.
npm run start -- --root <directory_with_your_react_component_js_sources>
On http://facebook.github.io/react-native/docs/embedded-app.html#content is a guide on how to integrate React Native in an existing app.
That happens when React wants to use a port that is already being used by other application. Since React listens to port 8081, you can get the process running at that port typing the following in Shell:
lsof -n -i4TCP:8081
You'll get an answer like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 28571 username 32u IPv6 0x742e2ab233abdb9f 0t0 TCP *:sunproxyadmin (LISTEN)
Just killed that by typing in shell
kill -9 <PID>. Use the same PID that has been provided in the last answer.
Then run npm start.
There's this issue:
https://github.com/facebook/react-native/issues/541
Which seems the same thing. The user there seemed to indicate that they had run the project from that directory before, which leads me to wonder if this is due to a hanging or left-over packager from a previous run? Try closing the terminal window and re-running the Xcode project.
In general this sounds like an issue with the packager not generating the files as expected. Are there any other messages in the terminal window?
I wanted to update this after getting a bit frustrated my setup still wasn't working after killing all node processes and running the command above.
There seems to be a ReactNative open issue at present: https://github.com/facebook/react-native/issues/14246
The solution for this is to kill the externally launched package manager and just run "npm start" in the project folder.
Check if you have index.ios or index in your AppDelegate.m:
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:#"index.ios" fallbackResource:nil];
I had index and I was previously using index.ios and index.android so that's why it was failing.
In my experience, it is because of Watchman and Jest.
The solution I've found is
add
name = name.replace('/', '\\');
to 'node_modules\jest-haste-map\build\crawlers\watchman.js'
You can check further info here
Watchman not working with React Native

Terminal not responding in Cloud9 IDE Rails

I'm working my way through the Ruby on Rails Tutorial, and suddenly the terminal is not responding to common commands.
Entering commands like "bundle exec rake test" or "rails console" creates the situation in the screenshot below and waiting hours does not change anything.
http://i59.tinypic.com/2poz5ah.png
I can type on the line but the Terminal still doesn't respond to any commands here. Ctrl+C allows me to escape the previous request and get back to the command line.
Strangely, "git status" works fine and quick.
Any ideas how to fix this?
I've tried restarting the Terminal and re-loading the workspace.
I just ran into the same problem two times (also going thru the Rails Tutorial) and here's how I went about adressing it:
Click on the workspace button in the top right corner- that's where it shows your CPU, Memory & Disk Usage (if you're on a laptop/small screen zoom out or make the screen as wide as possible to view that).
Next click on the "show process" button to see active processes.
After that I "force killed" my bash and ruby processes.
Lastly I clicked the "restart" button, which you see that when you first clicked to see the workspace info. Please note that if I went first to clicking this "restart" it had no effect... I had to force kill... THEN resart...
Viola, two times now it worked!
Not sure if this has any impact, but both times I mentally retraced my steps and realized I had several terminal windows open and willy-nilly ran the console multiple times in different terminal windows over the course of a few days. I would then run into not being able to run rails c UNLESS I have previously "properly" exited an already running console (meaning ctrl-c).
I've run into something similar while running Rails on my machine, and a full system restart does the trick. Perhaps due to the cloud based nature of Rails on Cloud9 there is some "sticky" process that stays on?
EDIT: Forgot to mention that on my machine I would also run "killall ruby" in a new terminal window. While that didn't work on Cloud9 it may be worth a try!
Anyhoo- lemme know if that does the trick!
Please do report these kind of (performance) questions to our Support desk via https://support.c9.io - we'll be able to help you quickly! Thanks.
what I did is just killed that process
ubuntu 5318 0.0 0.0 488820 16872 pts/3 Sl Dec24 0:01 spring server
kill -9 5318
You will have ur pid number. so just use it.
to get process -- use :
ps aux
Executing "bin/spring stop" would solve the issue as well. It is currently unknown why this happens and we are looking into that.

Error when attempting to run UI automation script from jenkins

I am using Xcode 6.1. And i need to run a UI automation script from jenkins as a post build action. The command that i use is shown below.
instruments -t $TRACETEMPLATE -w $DEVICE $APP_PATH -e UIASCRIPT $SCRIPT -e UIARESULTSPATH $RESULTS_PATH | grep "<" > test-reports/test-results.xml
When i run that the following error is thrown by jenkins.
Failed to authorize rights (0x1) with status: -60007.
2014-11-12 16:31:30.685 instruments[488:2607] -[XRSimulatorDevice prepareConnection:]: Unable to authorize simulated daemon (99637): 8
Instruments Trace Error : Target failed to run: Permission to debug com.test.app was denied.
Any help is much appreciated.
The user that invokes Instruments must have developer permissions. The user must be in the _developer group.
Security permissions allowing the user to access Instruments must be set. See the man page for DevToolsSecurity
The user must be logged in to a window server to use the simulator. How to do this will depend somewhat on your Jenkins and OS configuration for that user. In older versions of MacOS creating an SSH connection back into the machine and running Instruments through that connection typically worked. YMMV.
Note that any of the above steps escalates the rights for the Jenkins user, which was security implications.
I got an almost identical error message to yours, and it seemed to be because when Jenkins is launched as a Launch Daemon, it doesn't have access to the screen, even if you log in as "jenkins".
I found the solution from reading this discussion: https://issues.jenkins-ci.org/browse/JENKINS-14421
You can either launch Jenkins from Terminal with java -jar jenkins.war, or you can create a Launch Agent, which runs as the logged-in user and has access to the user's screen.
I achieved the latter solution by moving /Library/LaunchDaemons/org.jenkins-ci.plist to /Library/LaunchAgents/org.jenkins-ci.plist and removing the UserName key and value from the plist. Now Jenkins doesn't start automatically when I boot the machine, but it does start when I log into the desktop, which is required for running UI Automation tests anyway.
It appears that Jenkins still can't actually launch the Simulator app, but if Simulator is already running, the UI Automation scripts proceed just fine.
I also got this error message. Moving service from LaunchDaemons to LaunchAgents didn't solve the problem. My solution was as following:
remove the service by deleting /Library/LaunchAgents/org.jenkins-ci.plist file
create an iOS application using Automator tool. (Which I think exists by default):
I chose "Library" -> "Utilities" -> "Shell Script".
Enter the content of /Library/Application Support/Jenkins/jenkins-runner.sh.
Put export JENKINS_HOME=/path/to/jenkins at the top.
Save the app somewhere
Go to Preferences -> Users & Groups -> choose your user -> Add the saved app.
This way, jenkins is run as an application after login and it has all the privilages of any other application.

IntelliJ 11 hangs when executing grails command

I am using IntelliJ 11 with Grails 2.0.0 under Ubuntu. When IntelliJ executes any grails command it hangs straight away. I am not able to migrate my project to 2.0.0 (from 1.3.7) or even create a new grails project.
No exceptions thrown in the logs, hangs after clicking on create-app using grails.
Anyone have an idea what could be the problem here?
Thanks,
For me, the freeze only occurs when starting idea from a terminal window using & (ampersand for running in background, like this:
/path/to/your/ideahome/bin/idea.sh &
IDEA then starts correctly, but as soon as any grails command is run, the process enters "stopped" state and the IDEA GUI appears to be frozen.
When doing "fg" on the process, the application wakes up again and actually runs the grails command.
So, the workaround is of course to not run IDEA in background, for example by creating a desktop icon using the following as the "command":
bash -c "export JAVA_HOME=/path/to/your/javahome;/path/to/your/ideahome/bin/idea.sh"
I have found the following to 'unstick' the process though not every time.
when Intellij hangs due to some grails command or another, I run the following to see which processes are running (I have an alias set with the name 'idea' you would use whatever the command is to run idea)
ps -ef | grep idea
There are usually 3 or 4 processes, but the first one looks like:
username 19349 14977 0 10:41 pts/1 00:00:00 /bin/sh /usr/local/bin/idea
I run the following command to kill it
kill -9 {processId}
For example:
kill -9 19349
We use -9 to force full kill the process.
Intellij begins processing as normal. Sometimes I get the prompt about whether I am sure I want to exit to which I reply no.
Sometimes it does not work and I have to kill intelliJ entirely then start over. Most times it works.
Try 11.0.2 RC from http://confluence.jetbrains.net/display/IDEADEV/IDEA+11+EAP. If it doesn't help, file a bug at http://youtrack.jetbrains.net/issues/IDEA with a thread dump attached, refer to http://www.jetbrains.net/devnet/docs/DOC-260 for details.

iphone reboot programmatically

I have code
system("reboot")
The reboot command works in the terminal, but even if I run the app as root, the operation is still denied. Has anyone found any way that works, or can explain a bit about SBSetting's reboot, which makes me curious?
I have finally found a way to programmatically restart an iOS device without rooting a device!!!!
The command line tool to restart an iOS device is called libimobiledevice:
http://krypted.com/mac-os-x/use-libimobiledevice-to-view-ios-logs/
It is truly amazing. One snag I ran into while installing was trying to install this line:
brew install -v --devel --fresh automake autoconf libtool wget libimobiledevice
However I got around the install problem by running this line:
brew install -v --fresh automake autoconf libtool wget libimobiledevice
After that problem, I followed the rest of the instructions and voila!
Most of the commands can be found on this page:
http://krypted.com/uncategorized/command-line-ios-device-management/
The magic command that restarts the iOS device is:
idevicediagnostics restart
What is truly amazing about this tool is not only restarting an iOS device but also outputting iOS device logs to mac's terminal app using the following command:
idevicesyslog
I figured out a way to do it, although it's a bit convoluted. The problem is that even if you setup your app to run as root, when you make system() calls, you're apparently still limited to user mobile privileges. Since mobile cannot call reboot (successfully), this doesn't work.
The way I got around this problem is to take advantage of a new feature that SBSettings supports. SBSettings has a privileged daemon process that runs. It allows you to plug in your own commands, by simply writing a script (or other executable) and dumping it in the appropriate directory (/var/mobile/Library/SBSettings/Commands). Once you then restart the sbsettingsd process, you can get it to run your script by posting a notification. If you name your script
com.mycompany.reboot
then from within your app, you can execute this code:
#import <notify.h>
notify_post("com.mycompany.reboot");
Then, you make com.mycompany.reboot a simple shell script like this:
#!/bin/sh
reboot
And make sure to chmod 755 on your com.mycompany.reboot script. The full details of this SBSettings command feature can be found here:
http://thebigboss.org/guides/sbsettings-toggle-spec (see Calling External Functions and Scripts ...)
Anyway, it does require your app to depend on SBSettings, but it's a free app, and most users would probably want to have it anyway. For now, it accomplishes the goal of rebooting (or anything else that requires root access) programmatically, via notify_post().
This answer might feel hacky to some but I have not found a better solution on how to restart an iOS device that has not been jailbroken so here goes my answer:
In order to restart a device from the command line I do some prep work:
Connect device to computer
Add iTunes shortcut to your dock
Select spotlight and search for an application called Automator [must have Xcode installed in order to launch Automator!]
When Automator launches, select the Application option
Select the record button to start recording following actions
Select the iTunes shortcut
Select your device from the Device options
Select the Restore Backup... button
Select the Restore button
Select the stop button on the Automator app to stop recording.
From the Automator application, select File from the top bar and Save your newly recorded app to a location of your choosing
At this point you have an app file that will execute the steps mentioned above. I tend to leave iTunes open as it will always have the iOS device hooked up and ready to be accessed. When iTunes is closed and relaunched, the device takes time to fully connect with iTunes and this tends to break the flow of the Automator app.
At this point I can go into a terminal, go to the location of the app file and run the following command [EXAMPLE]:
open automator.app
(replace 'automator.app' with the name of your file)
If you are like me and your are running this command in jenkins, you will need to run the following commands:
open [location]/[your_app_name.app]
sleep 30
For some reason, the automator app needs the sleep time to complete all the recorded actions.
Also, I am sure you can also write an applescript to do all of this but I hate applescript and took the easy way out!
did you try NSTask: Execute a terminal command from a Cocoa app
This is not possible if the app is running in its sandbox. on a jailbroken phone you might be able to execute the reboot shell command.

Resources