Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to keep VNC running' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to keep VNC running
Authored by: diamondsw on Mar 05, '03 12:40:05PM

Of course, if you download the VNC server from Redstone, then it comes with scripts and such to run it as a StartupItem, and relaunch it automatically. As an aside, OSXvnc doesn't crash often that I can tell, but the gotcha is when you logout, OS X quits the WindowServer and THAT kills VNC.

A couple of starter files for getting a VNC StartupItem up and running, <b>and</b> keep everything self-contained in the StartupItem (no hard-coded paths or other ickiness). The completed startup item will contain (assuming /Library/StartupItems/OSXvnc/ is the location):

<code>
-rwxr-xr-x 1 jochs admin 8 Feb 3 09:51 .osxvncauth*
-rwxr-xr-x 1 jochs admin 742 Feb 18 15:24 OSXvnc*
-rwxr-xr-x 1 jochs admin 312 Feb 17 21:09 OSXvnc-keepalive*
-rwxr-xr-x 1 jochs admin 243888 Feb 3 09:51 OSXvnc-server*
-rw-r--r-- 1 jochs admin 553 Feb 3 11:46 StartupParameters.plist
-rw-r--r-- 1 root admin 116 Mar 5 01:28 osxvnc.log
</code>

<b>.osxvncauth</b> - encrypted password file created by "storepassword"
<b>OSXvnc</b> - shell script that is run automatically when OS X loads the startupitem
<b>OSXvnc-keepalive</b> - a shell script to always check for VNC and relaunch it if necessary
<b>OSXvnc-server</b> - the actual VNC server
<b>StartupParameters.plist</b> - Simple required file describing the StartupItem
<b>osxvnc.log</b> - any output and log messages from the VNC server

Now for the interesting files:

StartupParameters.plist:
<code>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Description</key>
<string>VNC Server</string>
<key>Messages</key>
<dict>
<key>start</key>
<string>Starting VNC Server</string>
<key>stop</key>
<string>Stopping VNC Server</string>
</dict>
<key>OrderPreference</key>
<string>None</string>
<key>Provides</key>
<array>
<string>VNC</string>
</array>
<key>Requires</key>
<array>
<string>Resolver</string>
</array>
</dict>
</plist>
</code>

OSXvnc:
<code>
#!/bin/sh

##
# VNC Server
##

. /etc/rc.common

StartService ()
{
SERVICE_PATH=`dirname $0`

CheckForNetwork
if [ "${NETWORKUP}" = "-NO-" ]; then exit; fi
ConsoleMessage "Starting VNC Server"

$SERVICE_PATH/OSXvnc-keepalive &
exit 0
}

StopService ()
{
# Stop the wrapper process first
SERVICE_PID=`/bin/ps -auxwwww | grep OSXvnc-keepalive | grep -v grep | awk 'NF > 2 {print \$2}'`
if [ "${SERVICE_PID:=""}" ]; then kill $SERVICE_PID; fi

# Stop the VNC server itself
SERVICE_PID=`/bin/ps -auxwwww | grep OSXvnc-server | grep -v grep | awk 'NF > 2 {print \$2}'`
if [ "${SERVICE_PID:=""}" ]; then kill $SERVICE_PID; fi
}

RestartService () { StopService; StartService; }

RunService "$1"
</code>

OSXvnc-keepalive:
<code>
#!/bin/sh

VNCPATH=`dirname $0`
VNCARGS="-rfbport 5900 -rfbauth ${VNCPATH}/.osxvncauth -swapButtons -dontdisconnect -disableScreenSaver
-allowsleep -localhost"

while true
do
$VNCPATH/OSXvnc-server $VNCARGS > $VNCPATH/osxvnc.log 2>&1
RESULT=$?
sleep 5
done

echo "OSXVNC Shutdown with exit status" $RESULT
</code>



[ Reply to This | # ]
A script to keep VNC running
Authored by: heissenbuttel on Mar 24, '03 02:52:54PM

Anyone else seem to have problems with the saved password, or is it just me? Seems I have to manually open the OSXvnc.app, enter my password, and restart server before I can login using Chicken of the VNC.

Anyone have any fixes for this?



[ Reply to This | # ]