Supervisor problems with django on OSX - django

I am using django-supervisor and my supervisor configuration is here.
Running python manage.py supervisor works great on my 3 Ubuntu machines, but when I try to run it on my mac (10.10), I have 2 problems with django:
If I add print statements in code, I can't see it in the console
If I stop the supervisor and start it again, it says that my django port is already in use
and I have to run: lsof -i :8000 | awk '{print $2}' | tail -n +2 | xargs kill every time in order to run the django inside the supervisor.
These 2 problems don't happen on Ubuntu machines.
My Mac is used for dev environment only.
Any ideas how can I fix them?

Related

Pre warmed Java Docker image with class data sharing

I want to create a docker image that runs on a Java Service with OpenJ9's Class Data Sharing feature to improve startup performance.
I want to create the Class Cache while building the image using a multi stage docker build.
I saw a few mentions of pre warming a docker image like this online
https://github.com/barecode/adopt-openj9-spring-boot/blob/master/Dockerfile.openj9.warmed
however, i'm not able to recreate it here is my Dockerfile
FROM adoptopenjdk/openjdk11-openj9:alpine as base
ADD libs/ /libs
ADD service.jar /service.jar
RUN mkdir /hi
WORKDIR /hi
RUN ls /
RUN java -Xshareclasses:name=mycache -Xshareclasses:cacheDir=/hi -Xshareclasses -jar /usr/share/app/service.jar &
RUN sleep 5
RUN ls -la /hi
FROM adoptopenjdk/openjdk11-openj9:alpine-jre
COPY --from=base libs/ /usr/share/app/libs
COPY --from=base service.jar /usr/share/app/service.jar
RUN /bin/sh -c 'ps aux | grep java | grep service | awk '{print $2}' | xargs kill -1'
#RUN java -Xshareclasses:listAllCaches
ENTRYPOINT ["java","-jar", "-Xshareclasses" , "-Xtune:virtualized", "-XX:+UseContainerSupport", "/usr/share/app/service.jar"]
my problem is that when I'm running
RUN java -Xshareclasses:name=mycache -Xshareclasses:cacheDir=/hi -Xshareclasses -jar /usr/share/app/service.jar &
and then expecting the cache file to be saved on /hi, the file isn't there.
any help will be appreciated.
Thanks.
OpenJ9 only reads the last -Xshareclasses option provided. This makes it easy to replace previous options in the commandline when developing / debugging as in some environments, it's hard to modify the existing commandline args.
Change the command to:
RUN java -Xshareclasses:name=mycache,cacheDir=/hi -jar /usr/share/app/service.jar &
and the cache will be created in the /hi directory.
For example:
# java -Xshareclasses:name=mycache,cacheDir=/hi -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.4+11)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.15.1, JRE 11 Linux amd64-64-Bit Compressed References 20190717_286 (JIT enabled, AOT enabled)
OpenJ9 - 0f66c6431
OMR - ec782f26
JCL - fa49279450 based on jdk-11.0.4+11)
# ls /hi
C290M11F1A64P_mycache_G37

Stop Django server without control key

I need to kill the Django development server from a shellscript in linux. How can this be done, since the shell script can't hold the 'CONTROL' key? Is there sytnax that performs the same function?
I tried:
$CONTROL-C
$^C
$SIGINT
Use kill to kill the process that is running your Django server:
ps -ax shows you all the running processes, you could ps -ax | grep runserver to just show the processes with runserver in them
kill xxxx kills the process number xxxx

What kind of commands/scripts can I run when An EC2 instance launches?

I read from the AWS docs:
Also, because the script is not run interactively, you cannot include
commands that require user feedback (such as yum update without the -y
flag).
I have this commands:
#!/bin/bash
THIS_NODE_IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
​
xvfb-run java -jar /home/ubuntu/selenium_server.jar -host $THIS_NODE_IP -role webdriver -port 8181 -maxSession 10 -maxInstances 10 -hub http://my-selenium-hub.com:8080/grid/register platform=LINUX &
...which do not seem to run. The selenium node that starts surely creates feedback in the console but I send it to background and it is not interactive.
your process is run as you launch the ec2 instance but it will stop when the user who launches the instance will disconnect
If you want to keep the process after user has disconnected, you can use nohup and if you want to get the output of the command you can use a redirection to a file like using >, something like
nohup <yourlongcommand> &> /path_to_file/nohup.grid.out&
you can then follow the execution of selenium from the nohup.grid.out file

How to launch or run an apk installed via adb on Google Glass

I wanted to share my experience on how to run an android app on Google Glass after installing it. In case, app does not have voice triggers defined and cannot be launched by 'OK Glass..', how can you run an app?
I got this answer from posts in Stackoverflow including this post: How to start an application using android ADB tools?
After connecting your glass to your computer, you have two options (These has been tested on mac):
1) How to launch/run an apt installed via adb if we know the activity/package name:
adb shell am start -n com.package.name/com.package.name.ActivityName
adb shell am start -n com.package.name/.ActivityName
** If you need to find out the list of installed packages on your glass:
adb shell 'pm list packages -f'
2) How to launch/run an apt if we don’t know the activity/package name?
a) create a file named "adb-run.sh" with these 3 lines:
pkg=$(aapt dump badging $1|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}')
act=$(aapt dump badging $1|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}')
adb shell am start -n $pkg/$act
b) "chmod +x adb-run.sh" to make it executable
c) adb-run.sh myapp.apk
Note: This requires that you have aapt in your path. You can find it under the new build tools folder in the SDK:
echo ‘export PATH=$PATH:/Users/USERNAME/LOCATIONofSDK/platform-tools/:/Users/USERNAME/LOCATIONofSDK/build-tools/android-4.3/’ >> ~/.bash_profile
You might consider using ChromeADB ... a great extension that does not need all the command line work.
You can use launchy.
Just install this app on Glass and then go to the settings... launchy will start and provide you the ability to run the APKs you've installed.
https://github.com/kaze0/launchy

How to stop gunicorn_django in virtualenv?

I am trying out gunicorn, and I installed it inside a virtualenv with a django site. I got gunicorn running with this command:
gunicorn_django -b 127.0.0.1:9000
Which is all well and good. I haven't setup a bash script or hooked it to upstart (I am on Ubuntu) yet, because I am testing it out.
Meantime, my connection to the server was broken, and thus I lost the console, and I can no longer do CTRL + C to stop the server after reconnecting.
How do I stop gunicorn_django, when it is already running?
The general solution to problems like this is to do ps ax|grep gunicorn to look for the relevant process, then do kill xxxx where xxxx is the number in the first column.
Just found this also - pkill - which will kill all processes matching the search text:
$ pkill gunicorn
No idea how well supported it is, but can confirm that it works on Ubuntu 12.04
(from http://www.howtogeek.com/howto/linux/kill-linux-processes-easier-with-pkill/)
A faster way:
> kill -9 `ps aux | grep gunicorn | awk '{print $2}'`
updated code
This was a bug that has just been fixed here.