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.
#!/bin/sh
OSXvnc-keepalive
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
1.71
For no documentable reason I can discern the server gets a 137 code when a user logs out
1.7
Only restart on items where the first bit is NOT set (less than 128)
1.5
Replace spurious ls -l entry with a much more appropriate pwd
1.4
Uses proper -lt and checks for less than 200 rather than more than 0 since process only return unsigned shorts
1.33
Modified so that keepalive only shuts down on unrecoverable errors
1.31
Modified so that OSXvnc can live in directories with spaces
while [ “$STOPNOW” -lt “1” ]
do
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" ]
then
# 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" ]
then
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
STOPNOW=1
fi
fi
sleep 5
done
echo "date '+%Y-%m-%d %H:%M:%S' $0: Shutdown with exit status: $RESULT"