Posts tagged: os x

OS X and Apache Web server

OS X Snow Leopard and the Apache Web server

This is the server run from System Preferences > Sharing > Web Sharing

The inspired location for configuration files is … wait for it …. /etc/apache2

OS X and Apache Web server

How to configure and run the Apache Web server included on OS X

OS X Startup Keyboard options

From Apple Mac OS X keyboard shortcuts

Startup keyboard shortcuts

Press the key or key combination until the expected function occurs/appears (for example, hold Option during startup until Startup Manager appears, or Shift until “Safe Boot” appears). Tip: If a startup function doesn’t work and you use a third-party keyboard, connect an Apple keyboard and try again.

Key or key combination What it does

Option Display all bootable volumes (Startup Manager)
Shift Perform Safe Boot (start up in Safe Mode)
C Start from a bootable disc (DVD, CD)
T Start in FireWire target disk mode
N Start from NetBoot server
X Force Mac OS X startup (if non-Mac OS X startup volumes are present)
Command-V Start in Verbose Mode
Command-S Start in Single User Mode

OS X Snow Leopard Screen sharing from the command line

With thanks to Mac OS X Hints.

In OS X 10.6, Snow Leopard you can enable / disable screen sharing from the command-line.

To enable screen sharing:

$ sudo sh -c "/bin/echo -n enabled > /private/etc/ScreenSharing.launchd"

To disable screen sharing:

$ sudo sh -c "rm /private/etc/ScreenSharing.launchd"

OS X Java Versions

OS X uses a weird and wonderful structure for Java components that allows multiple versions of Java to coexist happily on the same system. Depending on what you want to do, choosing between them can create challenges.

Apple references that were useful compiling this article:

Thanks also go to various others who have already plumbed the mysteries of OS X and Java.

OS X Directory Structure

OS X places all kinds of Java components in the directory structure starting at:

/System/Library/Frameworks

The component that’s of particular interest for this discussion is the JavaVM itself. That structure starts at:

/System/Library/Frameworks/JavaVM.framework

Each distinct Java version has a directory in

/System/Library/Frameworks/JavaVM.framework/Versions

Here’s a sample from my machine

lrwxr-xr-x   1 root  wheel     5B Aug 31 21:35 1.3 -> 1.3.1
drwxr-xr-x   3 root  wheel   102B Jul 20 19:35 1.3.1
lrwxr-xr-x   1 root  wheel     5B Nov 26 03:43 1.5 -> 1.5.0
drwxr-xr-x   8 root  wheel   272B Jan  2  2007 1.5.0
lrwxr-xr-x   1 root  wheel     5B Aug 31 21:35 1.6 -> 1.6.0
drwxr-xr-x   8 root  wheel   272B Oct 18 08:31 1.6.0
drwxr-xr-x   9 root  wheel   306B Oct 18 08:31 A
lrwxr-xr-x   1 root  wheel     1B Aug 31 21:35 Current -> A
lrwxr-xr-x   1 root  wheel     3B Aug 31 21:35 CurrentJDK -> 1.6

There are several interesting points about the subdirectories managed here.

  • The primary release (e.g ’1.5′) is always a link to the corresponding current ‘dot’ or ‘subrelease’ for that version (e.g ’1.5.0′)
  • ‘CurrentJDK’ is linked to whatever is the currently active Java JDK Version
  • ‘Current’ is linked to the currently selected Java SE version

There are several levels of indirection involved. You can stop here if you don’t need a further information or a bad headache. In this excursion, I’ll deal with the 1.6 (Java 6) trajectory.

  • ‘./Current’ is linked to ‘./A’
    • ‘./A’ appears to encompass both Java SE elements and Java JDK elements
    • ‘./A/Commands’ appears to contain JSE binaries
    • ‘./A/Headers’  appears to contain JDK headers
  • ‘./1.6.0′ links to ‘/System/Library/Frameworks/JavaVM.framework/Home’
    • ‘Home’  appears to have JDK binaries fot the specified (default?) version  (debug versions?)

This all serves to set the scene for the most interesting link from the point of view of daily use – ‘/Library/Java/Home’:

/Library/Java/Home -> /System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Home ->
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

This is the directory that Apple recommends using to set the ‘JAVA_HOME’ variable – beloved of the Java world, and required to get almost anything Java-based to work.

export JAVA_HOME=/Library/Java/Home
export PATH=${JAVA_HOME}/bin:${PATH}

Java Versions

Changes that affect everything on the system

If you want to change the Java version for everything on the system, you can do so with the Java Preferences application

/Applications/Utilities/Java Preferences

On the ‘General’ tab, follow the instructions to change the selection.

osx-javapreferences-general

If the version you want doesn’t appear on the list, you need something more radical (To be supplied).

Changes that affect the specific command you’re running

The Apple-sanctioned way to run a specific Java version from the command line is simple.  This deliberately does not involve changing the Java Preferences.

These changes shown below will only apply for the lifetime of the (bash) shell in which they are used. Using the setup illustrated above for my machine:

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
$JAVA_HOME/bin/java

This technique has been tested successfully in two environments:

  • Clean Snow Leopard install – Defaults to Java 1.6 – with manual install of Java 1.5 to run Java 1.5
  • Existing Leopard – default Java 1.5 installation – with manual install of Java 1.6 – to run Java 1.6

Adding a DNS nameserver to OS X Leopard

To add a DNS nameserver to OS X Leopard

Summarized from these excellent articles, Overriding DHCP- or VPN-assigned DNS servers in Mac OS X Leopard, Updating OS X Network Settings to Use a Local DNS Server, and Using a Local DNS Server in Leopard

In OS X (Leopard and later) DNS entries are arranged as a hierarchy – general to specific. You need the most specific applicable entry. Order – general to specific. Output is from scutil list command.

  • State:/Network/Global/DNS
  • Setup:/Network/Service/0/DNS (Fixed Network Adapter)
  • State:/Network/Service/B5DD6BDA-F1B3-40C7-9CEC-03CF97DE7B0A/DNS (Airport Connection)
  • State:/Network/Service/com.cisco.VPN/DNS (CISCO VPN)

So, now for the commands to adjust everything

sudo scutil
list State:/Network/Service/[^/]+/DNS
[Pick the appropriate service]
show State:/Network/Service/com.cisco.VPN/DNS
[
 {
  ServerAddresses :  {
    0 : 10.1.10.211
    1 : 10.1.10.100
  }
}
]
d.init
get State:/Network/Service/com.cisco.VPN/DNS
d.add ServerAddresses 10.1.10.74 10.1.10.211 10.1.10.100
d.show
[
 {
  ServerAddresses :  {
    0 : 10.1.10.74
    1 : 10.1.10.211
    2 : 10.1.10.100
  }
}
]
set State:/Network/Service/com.cisco.VPN/DNS
^D

Remember to flush your local DNS cache after all is said and done:

(Leopard and later) dscacheutil -flushcache

OS X Leopard – Advanced User Settings

In OS X Leopart, ro access advanced user settings:

System Preferences > Accounts > Unlock > Control-Click on User Name > Advanced Settings

OS X Flush DNS Cache

To flush the  DNS cache in OS X (as superuser):

lookupd -flushcache (Tiger)
dscacheutil -flushcache (Leopard and later)

OS X – Setting JAVA_HOME

With thanks to Setting JAVA_HOME on Mac OS X 10.5

(bash) export JAVA_HOME=/Library/Java/Home

OS X – Running two copies of Firefox at the same time

The essential trick to running two copies of Firefox at the same time on OS X is to run them both with the commant line options ‘–no-remote’.

/Applications/Web/Firefox.app/Contents/MacOS/firefox -no-remote

I chose to do serveral more things to create a really clean solution.

Create a new profile – say ‘FirefoxTest’

/Applications/Web/Firefox.app/Contents/MacOS/firefox -ProfileManager

Create a new copy of the Firefox application

rsync – a  /Applications/Web/Firefox.app/  /Applications/Web/FirefoxTest.app

Create script files to start both copies of Firefox

In /Applications/Web/Firefox.app/Contents/MacOS, create a executable script file with contents similar to:

#!/usr/bin/env bash

# firefox-single

# Run a standard Firefox setup, but disable single application locking

/Applications/Web/Firefox.app/Contents/MacOS/firefox -P default --no-remote &

And for the second copy of Firefox, in /Applications/Web/FirefoxTest.app/Contents/MacOS something similar to

#!/usr/bin/env bash

# firefox-test

# Run a test Firefox setup, but disable single application locking

/Applications/Web/FirefoxTest.app/Contents/MacOS/firefox -P FirefoxTest --no-remote &

Change the application ‘Info.plist’ file

(in Firefox.app/Contents or the equivalent location)

Key Value
CFBundleExecutable firefox-single
CFBundleIdentifier org.mozilla.firefox.single

For the test copy, use something similar to the following:

Key Value
CFBundleExecutable firefox-test
CFBundleIdentifier org.mozilla.firefox.single-test

The ‘CFBundleExecutable’ entry links the startup Icon (also the command-line ‘open’ command) to the new script file you’ve created to run Firefox.

The ‘CFBundleIdentifier’ ensures that OS X sees separate applications running when managing the applications.

Recache the ‘Info.plist’ file

The last, critical step, is to force OS X to recache the ‘Info.plist’ file (where it caches I don’t know):

touch /Applications/Web/Firefox.app

and

touch /Applications/Web/FirefoxTest.app

Conclusion

Now you’ve got two nice icons you can drag to your toolbar to click, you’ll be running two copies of Firefox side by side – and you’ll forget you had to do this.

WordPress Themes