@@ -23,8 +23,6 @@ touch $HOME/.vnc/passwd
23
23
echo " $VNC_PW " | vncpasswd -f >> $HOME /.vnc/passwd
24
24
chmod 600 $HOME /.vnc/passwd
25
25
26
- # Setting pidfile + command to execute
27
- pidfile=" $HOME /.vnc/*:1.pid"
28
26
config_file=$HOME /.vnc/config
29
27
touch $config_file
30
28
printf " geometry=$VNC_RESOLUTION \ndepth=$VNC_COL_DEPTH \ndesktop=Desktop-GUI\nsession=xfce" > ~ /.vnc/config
@@ -33,16 +31,28 @@ command="/usr/libexec/vncserver $DISPLAY"
33
31
# Proxy signals
34
32
function kill_app(){
35
33
# correct forwarding of shutdown signal
36
- kill -s SIGTERM $!
34
+ _wait_pid=$!
35
+ kill -s SIGTERM $_wait_pid
37
36
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
39
41
exit 0 # exit okay
40
42
}
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
42
54
43
55
# cleanup tmp from previous run
44
- # run vncserver kill in background
45
- /usr/libexec/vncserver -kill $DISPLAY &
46
56
rm -rfv /tmp/.X* -lock /tmp/.x* -lock /tmp/.X11-unix
47
57
# Delete existing logs
48
58
find $HOME /.vnc/ -name ' *.log' -delete
@@ -51,19 +61,23 @@ find $HOME/.vnc/ -name '*.log' -delete
51
61
# Launch daemon
52
62
53
63
sleep 1
54
- $command
55
- sleep 4
64
+ $command & > " $HOME /.vnc/vnc.log" &
65
+ sleep 5
66
+
67
+ _wait_pid=$!
56
68
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 &
58
72
59
73
# 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 &&
61
76
62
77
# Loop while the pidfile and the process exist
63
78
echo " Starting monitoring pid file for vnc server"
64
- while [ -f $pidfile ] && kill -0 $( cat $pidfile ) ; do
79
+ while kill -0 $_wait_pid ; do
65
80
sleep 1
66
81
done
67
82
68
-
69
83
exit 1000 # exit unexpected
0 commit comments