VNC-Server mit Autostart unter Mandriva: Unterschied zwischen den Versionen

Aus Linupedia.org
Wechseln zu: Navigation, Suche
 
Zeile 7: Zeile 7:
 
Quelltext:  
 
Quelltext:  
 
-------------  
 
-------------  
#!/bin/bash  
+
<br />#!/bin/bash  
#  
+
<br />#  
# chkconfig: - 91 35
 
# description: Starts and stops vncserver. \
 
# used to provide remote X administration services.
 
  
# Source function library.  
+
<br /># chkconfig&#58; - 91 35
. /etc/init.d/functions  
+
<br /># description&#58; Starts and stops vncserver. \
 +
<br /># used to provide remote X administration services.
 +
<br />
 +
<br /># Source function library.  
 +
<br />. /etc/init.d/functions  
 +
<br />
 +
<br /># Source networking configuration.
 +
<br />. /etc/sysconfig/network
 +
<br />
 +
<br /># Check that networking is up.
 +
<br />&#91; $&#123;NETWORKING&#125; = &quot;no&quot; &#93; &amp;&amp; exit 0
  
# Source networking configuration.
+
<br />
. /etc/sysconfig/network
+
<br />VNCSERVERS=&quot;&quot;
 +
<br />&#91; -f /etc/sysconfig/vncservers &#93; &amp;&amp; . /etc/sysconfig/vncservers
 +
<br />
 +
<br />prog=$&quot;VNC server&quot;
 +
<br />
 +
<br />start&#40;&#41; &#123;
 +
<br />echo -n $&quot;Starting $prog&#58; &quot;
  
# Check that networking is up.  
+
<br />ulimit -S -c 0 &gt;/dev/null 2&gt;&amp;1
[ ${NETWORKING} = "no" ] && exit 0
+
<br />RETVAL=0
 +
<br />for display in $&#123;VNCSERVERS&#125;
 +
<br />do
 +
<br />echo -n &quot;$&#123;display&#125; &quot;
 +
<br />unset BASH_ENV ENV
 +
<br />initlog $INITLOG_ARGS -c \
 +
<br />&quot;su $&#123;display##*&#58;&#125; -l -c \&quot;cd ~$&#123;display##*&#58;&#125; &amp;&amp; &#91; -f .vnc/passwd &#93; &amp;&amp; vncserver &#58;$&#123;display%%&#58;*&#125;\&quot;&quot;
  
VNCSERVERS=""
+
<br />RETVAL=$?
[ -f /etc/sysconfig/vncservers ] && . /etc/sysconfig/vncservers
+
<br />&#91; &quot;$RETVAL&quot; -ne 0 &#93; &amp;&amp; break
 +
<br />done
 +
<br />&#91; &quot;$RETVAL&quot; -eq 0 &#93; &amp;&amp; success $&quot;vncserver startup&quot; || \
  
prog=$"VNC server"
+
<br />failure $&quot;vncserver start&quot;
 +
<br />echo
 +
<br />&#91; &quot;$RETVAL&quot; -eq 0 &#93; &amp;&amp; touch /var/lock/subsys/vncserver
 +
<br />&#125;
 +
<br />
 +
<br />stop&#40;&#41; &#123;
 +
<br />echo -n $&quot;Shutting down $prog&#58; &quot;
  
start() {
+
<br />for display in $&#123;VNCSERVERS&#125;
echo -n $"Starting $prog: "
+
<br />do  
ulimit -S -c 0 >/dev/null 2>&1
+
<br />echo -n &quot;$&#123;display&#125; &quot;
RETVAL=0
+
<br />unset BASH_ENV ENV  
for display in ${VNCSERVERS}
+
<br />initlog $INITLOG_ARGS -c \  
do  
+
<br />&quot;su $&#123;display##*&#58;&#125; -c \&quot;vncserver -kill &#58;$&#123;display%%&#58;*&#125;\&quot; &gt;/dev/null 2&gt;&amp;1&quot;
echo -n "${display} "
 
unset BASH_ENV ENV  
 
initlog $INITLOG_ARGS -c \  
 
"su ${display##*:} -l -c \"cd ~${display##*:} && [ -f .vnc/passwd ] && vncserver :${display%%:*}\""
 
RETVAL=$?
 
[ "$RETVAL" -ne 0 ] && break
 
done
 
[ "$RETVAL" -eq 0 ] && success $"vncserver startup" || \
 
failure $"vncserver start"
 
echo
 
[ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/vncserver
 
}
 
  
stop() {
+
<br />done  
echo -n $"Shutting down $prog: "
+
<br />RETVAL=$?  
for display in ${VNCSERVERS}
+
<br />&#91; &quot;$RETVAL&quot; -eq 0 &#93; &amp;&amp; success $&quot;vncserver shutdown&quot; || \  
do
+
<br />failure $&quot;vncserver shutdown&quot;
echo -n "${display} "
+
<br />echo  
unset BASH_ENV ENV
+
<br />&#91; &quot;$RETVAL&quot; -eq 0 &#93; &amp;&amp; rm -f /var/lock/subsys/vncserver  
initlog $INITLOG_ARGS -c \
+
 
"su ${display##*:} -c \"vncserver -kill :${display%%:*}\" >/dev/null 2>&1"
+
<br />&#125;
done  
+
<br />
RETVAL=$?  
+
<br /># See how we were called.
[ "$RETVAL" -eq 0 ] && success $"vncserver shutdown" || \  
+
<br />case &quot;$1&quot; in
failure $"vncserver shutdown"
+
<br />start&#41;
echo  
+
<br />start
[ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/vncserver  
+
<br />;;
}
+
<br />stop&#41;
 +
<br />stop
 +
<br />;;
 +
<br />restart|reload&#41;
 +
 
 +
<br />stop
 +
<br />sleep 1
 +
<br />start
 +
<br />;;
 +
<br />condrestart&#41;
 +
<br />if &#91; -f /var/lock/subsys/vncserver &#93;; then
 +
<br />stop
 +
<br />start
 +
<br />fi
 +
<br />;;
 +
<br />status&#41;
 +
<br />status Xvnc
 +
 
 +
<br />;;
 +
<br />*&#41;
 +
<br />echo $&quot;Usage&#58; $0 &#123;start|stop|restart|condrestart|status&#125;&quot;
 +
<br />exit 1
 +
<br />esac
  
# See how we were called.
 
case "$1" in
 
start)
 
start
 
;;
 
stop)
 
stop
 
;;
 
restart|reload)
 
stop
 
sleep 1
 
start
 
;;
 
condrestart)
 
if [ -f /var/lock/subsys/vncserver ]; then
 
stop
 
start
 
fi
 
;;
 
status)
 
status Xvnc
 
;;
 
*)
 
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
 
exit 1
 
esac
 
 
-----------------------------------------------------------------------------------  
 
-----------------------------------------------------------------------------------  
  

Version vom 15. August 2006, 19:26 Uhr

Mit bestem Dank an id3pr.

0) Allg: Man muss als erstes normal einen Vncserver über die Konsole starten und ein Passwort festlegen. Dann den vncserver wieder schließen.

1) Man schreibe sich ein Skript (einfach folgenden Quelltext in eine leere Datei kopieren und sie "vncserver" nennen)

Quelltext:



#!/bin/bash
#


# chkconfig: - 91 35
# description: Starts and stops vncserver. \
# used to provide remote X administration services.

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0



VNCSERVERS=""
[ -f /etc/sysconfig/vncservers ] && . /etc/sysconfig/vncservers

prog=$"VNC server"

start() {
echo -n $"Starting $prog: "


ulimit -S -c 0 >/dev/null 2>&1
RETVAL=0
for display in ${VNCSERVERS}
do
echo -n "${display} "
unset BASH_ENV ENV
initlog $INITLOG_ARGS -c \
"su ${display##*:} -l -c \"cd ~${display##*:} && [ -f .vnc/passwd ] && vncserver :${display%%:*}\""


RETVAL=$?
[ "$RETVAL" -ne 0 ] && break
done
[ "$RETVAL" -eq 0 ] && success $"vncserver startup" || \


failure $"vncserver start"
echo
[ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/vncserver
}

stop() {
echo -n $"Shutting down $prog: "


for display in ${VNCSERVERS}
do
echo -n "${display} "
unset BASH_ENV ENV
initlog $INITLOG_ARGS -c \
"su ${display##*:} -c \"vncserver -kill :${display%%:*}\" >/dev/null 2>&1"


done
RETVAL=$?
[ "$RETVAL" -eq 0 ] && success $"vncserver shutdown" || \
failure $"vncserver shutdown"
echo
[ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/vncserver


}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)


stop
sleep 1
start
;;
condrestart)
if [ -f /var/lock/subsys/vncserver ]; then
stop
start
fi
;;
status)
status Xvnc


;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac


2) diese Datei speichert man im Verzeichnis "/etc/init.d/"

3) die Datei, genauergesagt das Script, muss ausfühbar sein. Also:

"chmod +x /etc/init.d/vncserver"

4) das script soll in den richtigen runlevel um automatisch zu starten. Also:

"chkconfig --level 5 vncserver on" "chkconfig --add vncserver"

5) Man editiert die Datei "/etc/sysconfig/vncservers"

Quelltext:


Contents of /etc/sysconfig/vncservers:

  1. The VNCSERVERS variable is a list of display:user pairs.
  2. Uncomment the line below to start a VNC server on display :1
  3. as my 'myusername' (adjust this to your own). You will also
  4. need to set a VNC password; run 'man vncpasswd' to see how
  5. to do that.
  6. DO NOT RUN THIS SERVICE if your local area network is
  7. untrusted! For a secure way of using VNC, see
  8. URL:http://www.uk.research.att.com/vnc/sshvnc.html.
  1. VNCSERVERS="1:myusername"

VNCSERVERS="1:bob 2:sally 3:jim"


Logischer Weise muss man anstatt "bob", "sally" und "jim" den Namen des eigenen Nutzers oder der Nutzerin angeben.

6) rebooten

7) have a lot of fun