Skip to content

Commit 0458a60

Browse files
committed
Fix vnc start script
1 parent d9ab8fc commit 0458a60

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

resources/scripts/start-vnc-server.sh

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ touch $HOME/.vnc/passwd
2323
echo "$VNC_PW" | vncpasswd -f >> $HOME/.vnc/passwd
2424
chmod 600 $HOME/.vnc/passwd
2525

26-
# Setting pidfile + command to execute
27-
pidfile="$HOME/.vnc/*:1.pid"
2826
config_file=$HOME/.vnc/config
2927
touch $config_file
3028
printf "geometry=$VNC_RESOLUTION\ndepth=$VNC_COL_DEPTH\ndesktop=Desktop-GUI\nsession=xfce" > ~/.vnc/config
@@ -33,16 +31,28 @@ command="/usr/libexec/vncserver $DISPLAY"
3331
# Proxy signals
3432
function kill_app(){
3533
# correct forwarding of shutdown signal
36-
kill -s SIGTERM $!
34+
_wait_pid=$!
35+
kill -s SIGTERM $_wait_pid
3736
trap - SIGTERM && kill -- -$$
38-
kill $(cat $pidfile)
37+
if [ -n "$(pidof xinit)" ] ; then
38+
### ignore the errors if not alive any more
39+
kill $(pidof xinit) > /dev/null 2>&1
40+
fi
3941
exit 0 # exit okay
4042
}
41-
trap "kill_app" SIGINT SIGTERM EXIT
43+
trap "kill_app" SIGINT SIGTERM SIGQUIT EXIT
44+
45+
# Old way: is not supported in tiger vnc 11
46+
# /usr/libexec/vncserver -kill $DISPLAY &
47+
48+
# Kill vnc server via the xinit script
49+
# init_pid="$(pidof xinit)"
50+
if [ -n "$(pidof xinit)" ] ; then
51+
### ignore the errors if not alive any more
52+
kill $(pidof xinit) > /dev/null 2>&1
53+
fi
4254

4355
#cleanup tmp from previous run
44-
# run vncserver kill in background
45-
/usr/libexec/vncserver -kill $DISPLAY &
4656
rm -rfv /tmp/.X*-lock /tmp/.x*-lock /tmp/.X11-unix
4757
# Delete existing logs
4858
find $HOME/.vnc/ -name '*.log' -delete
@@ -51,19 +61,23 @@ find $HOME/.vnc/ -name '*.log' -delete
5161
# Launch daemon
5262

5363
sleep 1
54-
$command
55-
sleep 4
64+
$command &> "$HOME/.vnc/vnc.log" &
65+
sleep 5
66+
67+
_wait_pid=$!
5668

57-
tail -f -q --pid $(cat $pidfile) $HOME/.vnc/*.log &
69+
echo "Started VNC Server $_wait_pid"
70+
71+
tail -f -q --pid $_wait_pid $HOME/.vnc/*.log &
5872

5973
# Disable screensaver and power management - needs to run after the vnc server is started
60-
xset -dpms && xset s noblank && xset s off
74+
xset s noblank && xset s off
75+
# dpms option not available: xset -display :1 -dpms &&
6176

6277
# Loop while the pidfile and the process exist
6378
echo "Starting monitoring pid file for vnc server"
64-
while [ -f $pidfile ] && kill -0 $(cat $pidfile) ; do
79+
while kill -0 $_wait_pid ; do
6580
sleep 1
6681
done
6782

68-
6983
exit 1000 # exit unexpected

0 commit comments

Comments
 (0)