VineServer2.1 quits at logout

I have my remote system start OSXvnc-server when it starts up. If I am not logged in to my user account on the remote machine, I get the login window when I use a client to connect to the server. I can login and use the remote system without difficulty. However, if I logout from the remote desktop, I would expect to return to the login window. Instead the vine server quits and my connection closes. A message “server exited with result 137” is appended to the osxvnc_exit.log file, and a new system server is spawned—unless this same “error” has happened five times in a row, in which case no new server is started.

Is this normal? Seems like there ought to be another approach. I never want to be forced to reboot the remote machine in order to start the system vnc-server.


First, I see that I can manually start the server by invoking

sudo /Library/StartupItems/OSXvnc/OSXvnc

It seems that the SIGKILL signal (137 = 9 + 128) is sent to the server when a user logs out. After five consecutive exits with this signal, the server is allowed to die. I don’t understand why this behavior is desirable.

I modified /Library/StartupItems/OSXvnc/OSXvnc-keepalive

The modified version copied below seems to do what I want. But I’m hardly an expert, so please let me know if my changes are harmful.



This little script, as you might imagine, will relaunch OSXvnc-server

when a user logs out and the OS kills the process (because it’s running an event loop)

Modification Log:

Modified by LZ 2007-06-04

2.0 Adopted these contributions…

2006-06-07 Marvin Simkin

Try to capture a little more detail when it dies


For no documentable reason I can discern the server gets a 137 code when a user logs out


Only restart on items where the first bit is NOT set (less than 128)


Replace spurious ls -l entry with a much more appropriate pwd


Uses proper -lt and checks for less than 200 rather than more than 0 since process only return unsigned shorts


Modified so that keepalive only shuts down on unrecoverable errors


Modified so that OSXvnc can live in directories with spaces


Initial version

echo "date '+%Y-%m-%d %H:%M:%S' $0: Starting"
echo "date '+%Y-%m-%d %H:%M:%S' pwd: ‘pwd’"
echo "date '+%Y-%m-%d %H:%M:%S' id: ‘id’"
echo "date '+%Y-%m-%d %H:%M:%S' uname -a: ‘uname -a’"
echo "date '+%Y-%m-%d %H:%M:%S' uptime: ‘uptime’"


while [ “$STOPNOW” -lt “1” ]
echo "date '+%Y-%m-%d %H:%M:%S' $0: Starting Server ‘$1’"
“$@” # Run our parameters
RESULT=$? # Record Result
echo "date '+%Y-%m-%d %H:%M:%S' Server exited with result: $RESULT"
echo "date '+%Y-%m-%d %H:%M:%S' Server exited with result: $RESULT" >> /var/log/osxvnc_exit.log

signal code 137 = 9 + 128 corresponds to SIGKILL (kill signal from term)

this signal is sent when a user logs out

don’t treat recurrence of this code as an error; let the server restart!

if [ "$RESULT" -ne "137" ]
    	# check for same problem recurring frequently
    	COUNT=`cut -f1,7 -d' ' < /var/log/osxvnc_exit.log |
      	uniq -c |
      	tail -1 |
      	sed "s/^  *//" |
      	cut -f1 -d' '`

    	# set the repeated failures limit here
    	if [ "$COUNT" -gt "4" ]
      		echo "`date '+%Y-%m-%d %H:%M:%S'` The same error '$RESULT' happened $COUNT times in a row, not restarting!"
      		echo "`date '+%Y-%m-%d %H:%M:%S'` The same error '$RESULT' happened $COUNT times in a row, not restarting!" >> /var/log/osxvnc_exit.log

sleep 5


echo "date '+%Y-%m-%d %H:%M:%S' $0: Shutdown with exit status: $RESULT"

Nope, that’s a fine addition. We’ll probably adopt it here as well, thanks for the tweak.

Glad to help.

By the way, it seems that a better way to manually start the system’s OSXvnc-server is

sudo SystemStarter start VNC


sudo SystemStarter stop VNC

stops the server, and

sudo SystemStarter restart VNC

is also available.