2013-01-27

Android Mac Command Line

1.) Launch Android SDK Manager to download additional libraries and SDK versions

$ANDROID_SDK_PATH/tools/android sdk

2.) List Android SDK targets to create AVD (Android Virtual Devices)

$ANDROID_SDK_PATH/tools/android list targets

3.) Create AVD

$ANDROID_SDK_PATH/tools/android create avd -n avdName -t targetID 

4.) Start the AVD emulator

$ANDROID_SDK_PATH/tools/emulator -avd avdName

5.) Generate Android project build.xml if missing

$ANDROID_SDK_PATH/tools/android update project -p projectPath

6.) Compile Android project if build.xml exist

ant debug

7.) Install Android on emulator

ant debug install

or 

$ANDROID_SDK_PATH/platform-tools/adb install projectPath/bin/AppName.apk

Useful parameters

-r : Reinstall
-d: Install on USB device
-s emulatorID : Specifies emaulator ID in case running multiple emulators

8.) If running multiple emulators, see all emulators ID

$ANDROID_SDK_PATH/platform-tools/adb devices

2013-01-22

Unix Detective: Port of Call

Recently I had to administer an Unix server with no runbook. The immediate task was to find the application listening on port 8888, make some modifications, and restart.

1.) Find process listening on port 8888

netstat -plan | grep 8888

The output is

tcp     0   0 :::8888   :::*    LISTEN      2700/java 

This shows me that a java program at Process ID (PID) 2700 is listening on port 8888

2.) Find process info of PID 2700

ps -fp 2700 | more

The output is

oracle  2700   1  0 18:55 ?     0:00:02 
/usr/java/latest/bin/java -Xmx1024m -Xms256m -Dapex.port=8888
-Djava.io.tmpdir=/home/oracle/tmp
-jar/home/oracle/listener/apex.war 2>&1 >/tmp/apexListener.log

This shows me the full command line for PID 2700. Luckily the command line has all the necessary information like program type (Oracle Apex), log location, war file location, temporary directory, etc.

Sometimes we do not get so lucky and the command line is more cryptic. If that  is the case, execute command

lsof -p 2700

That command shows a list of open files used by process 2700. That will usually lead to log location and other important files.

...

java    2700 oracle    2w   REG        3,1     1700 1796967 /tmp/apex_listener.log
java    2700 oracle    3r   REG       3,65  9828505  134585 /home/oracle/listener/apex.war
java    2700 oracle    4r   REG        3,1 51796975  361047 /usr/java/jdk1.6.0_20/jre/lib/rt.jar
java    2700 oracle    5r   REG       3,65  1869025  132940 /home/oracle/tmp/apex/apex/____embedded/start.jar
java    2700 oracle    6r   REG       3,65  1539291  132946 /home/oracle/tmp/apex/apex/WEB-INF/lib/poi-3.6-20091214.jar
...

3.) Find how to stop and start the application
The ps -fp command in step 2 shows me that the parent process PID is 1. (It is the number after 2700). 

ps -fp 1 | more

gives the output

root    1     0  0 18:54 ?    00:00:00 init [5]

The command init is the startup script process that executes when Unix first boots up.  The startup scripts are in directory /etc/init.d

cd /etc/init.d
find . -name "*" | xargs grep apex

The output is

./oracle:   su - oracle -c "/home/oracle/apexlistener.sh start"
./oracle:   su - oracle -c "/home/oracle/apexlistener.sh stop"

Reading the file ./oracle with the command

more ./oracle

shows me how to stop and start Oracle Apex.

Find Unused Unix Ports

Problem:
You need to bring up another Unix web server but port 80 is already in use. How do you find another unused Unix port?

Solution:
(as one line)

netstat -ln | grep -v LISTENING | awk '{print $4}' | grep ":" | sort | uniq


You will get an output like

0.0.0.0:5353
0.0.0.0:68
0.0.0.0:80
10.0.2.15:123
::1:10089
::1:123

The number after the last colon is the port in use, e.g. 80, 123, 5353.  Pick any Unix port not already in use and assigned.

Oracle Linux Listener Permission Error

Problem:
When starting the Oracle listener, you get the error

lsnrctl: error while loading shared libraries: /ORA_PATH/lib/libnnz11.so: cannot restore segment prot after reloc: Permission denied


Solution:
The Oracle is running on Security-Enhanced Linux (SELinux) and the OS is not granting Oracle proper permission on the libnnz11.so library.

As root user or sudo, grant the proper permission via

chcon -v -t textrel_shlib_t '/ORA_PATH/lib/libnnz11.so'

If errors are still occurring, you can set SELinux to permissive move with command

setenforce 0

To make the change to SELinux permissive mode permanent, edit the file /etc/selinux/config and change the line "SELINUX=enforcing" to

SELINUX=permissive

android:layout_height

Android UI XML Attribute

Name
android:layout_height

Description
Controls the height of the UI element.

Values
Value Description
wrap_contentUI element is automatically sized to fit the UI element content
match_parent UI element is automatically sized to fit the UI element parent container.
fill_parent Deprecated. Functionally identical as match_parent.
#dp Density-independent pixels. Actual size depends on screen resolution of device. The preferred unit to define a specific numeric UI element size. Example usage: 16dp
#sp Scale-independent pixels. Actual size depends on both screen resolution and user's font size settings. Example usage: 16sp
#pt 1/72 of an inch. Example usage: 16pt
#mm A millimeter. Example usage: 16mm
#in An inch. Example usage: 16in
#px A physical pixel. Not recommended to use. Example usage: 16px

Example Usage
<TextView android:layout_height="wrap_content" />

Reference
Android API: layout_height