You are not logged in.

#1 2006-09-14 04:17:45

briancurtin
Member
From: Chicago, IL
Registered: 2006-02-11
Posts: 132
Website

run vncserver on startup?

is there a preferred way to run vncserver (from tightVNC) on startup?
id like to be able to reboot/logout of my other machine while in a VNC session and not have to go over to it and login to it to get back in.

any tips?

Offline

#2 2006-09-14 05:50:57

scarecrow
Member
From: Greece
Registered: 2004-11-18
Posts: 715

Re: run vncserver on startup?

Excuse me if I haven't properly understood, but it seems you want to get access to a real desktop, and not a virtual one.
vncserver from tightvnc package is good for running virtual desktops from remote users. For having access to a real, local xdisplay you must run the server from the "x11vnc" package instead.


Microshaft delenda est

Offline

#3 2006-09-14 06:06:28

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: run vncserver on startup?

I could not follow the red liner in the question, but ... A clean and nice way would be to create script to /etc/rc.d/ that starts vncserver as a user or xvnc. Then vncserver or xvnc would be killed on shutdown/reboot.

#!/bin/bash

# general config
. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting vncserver for vncuser"
      su vncuser -c "/usr/bin/vncserver :8 &>/dev/null"
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon vncserver_vncuser
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping vncserver for vncuser"
    /usr/bin/vncserver -kill :8 &>/dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon vncserver_vncuser
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"  
esac

link to the script

If you need xvnc then modify the script.

Offline

#4 2007-09-20 21:07:22

Klas
Member
Registered: 2007-09-18
Posts: 13

Re: run vncserver on startup?

Purch :
I tried your script and it dont function as a Daemon. You need to login as regular user with su.

Offline

#5 2007-09-20 21:51:48

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: run vncserver on startup?

Klas wrote:

Purch :
I tried your script and it dont function as a Daemon. You need to login as regular user with su.

Here the working one (I did not try reboot, only $ sudo vncserever_script)

#!/bin/bash

# general config
. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting vncserver for puke"
      /bin/su - puke -c "/usr/bin/vncserver :5 &>/dev/null"
    if [ $? -gt 0 ]; then                                  
      stat_fail          
    else       
      add_daemon vncserver_script
      stat_done                  
    fi         
    ;;
  stop)
    stat_busy "Stopping vncserver for puke"
    /usr/bin/vncserver -kill :5 &>/dev/null
    if [ $? -gt 0 ]; then                  
      stat_fail          
    else       
      rm_daemon vncserver_script
      stat_done                 
    fi         
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;      
  *)
    echo "usage: $0 {start|stop|restart}"
esac

link to the script

edit: hmm, some PATH variables are missing and java wont work in vnc window if I use the script. Have to look at it.

Last edited by Purch (2007-09-20 22:02:45)

Offline

#6 2007-09-20 21:59:29

Klas
Member
Registered: 2007-09-18
Posts: 13

Re: run vncserver on startup?

That was a fast answere! Thank you,  I will try it out emediatly (been strugling with this a bit for some time know).

(excuse my bad english)

Offline

#7 2007-09-20 22:34:07

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: run vncserver on startup?

I dont know if this is the proper way to get PATH environments set up, but hey now java works too. Use the "profile" files to get what you need. Here is the command with my profile files.

/bin/su - puke -c "source /etc/profile && source /home/puke/.bashrc && /usr/bin/vncserver :5 &>/dev/null"

Last edited by Purch (2007-09-20 22:35:55)

Offline

#8 2007-09-20 22:53:36

Klas
Member
Registered: 2007-09-18
Posts: 13

Re: run vncserver on startup?

Your new script dont funtion at start as a daemon and I dont undestand how it could. If you tun "/bin/su" then yuo need to login. You dont get any login prompt when you run it as a daemon.  Have you manipulated with su in some way?

The only thing I have got to funtion is to set up "sudo /usr/bin/vncserver :1" in "/etc/rc.local" (and in sudoers no password for  some users to run vncserver).
My supose later is to make a script that sets up Tightvnserver for more then one user, at boot. Is it posible?

Last edited by Klas (2007-09-20 22:55:14)

Offline

#9 2007-09-20 23:20:48

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: run vncserver on startup?

Just rebooted my server and it works perfectly. Remember to change puke to your_user and choose proper display number ( I use :5) to the script.

$ cat /etc/rc.d/vncserver_script
#!/bin/bash

# general config
. /etc/rc.conf
. /etc/rc.d/functions

case "$1" in
  start)
    stat_busy "Starting vncserver for puke"
      /bin/su - puke -c "source /etc/profile && source /home/puke/.bashrc && /usr/bin/vncserver :5 &>/dev/null"
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon vncserver_script
      stat_done
    fi
    ;;
  stop)
    stat_busy "Stopping vncserver for puke"
    /usr/bin/vncserver -kill :5 &>/dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon vncserver_script
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac

$ tail /etc/rc.conf
# DAEMONS
# -----------------------------------------------------------------------
#
# Daemons to start at boot-up (in this order)
#   - prefix a daemon with a ! to disable it
#   - prefix a daemon with a @ to start it up in the background
#
DAEMONS=(syslog-ng  ...cut... vncserver_script kdm)

# End of file

PS: The dash (-) before user in /bin/su equals -l and --login (man su)

Last edited by Purch (2007-09-20 23:23:57)

Offline

#10 2007-09-20 23:49:19

Klas
Member
Registered: 2007-09-18
Posts: 13

Re: run vncserver on startup?

Ok, I understund that. I also changed " **_daemon vncserver_script" to the name of the scriptfile I have :  **_daemon vncserver_user. Mybee I start some dameon in wrong order. I try again!

Last edited by Klas (2007-09-20 23:50:02)

Offline

#11 2007-09-21 00:49:53

Klas
Member
Registered: 2007-09-18
Posts: 13

Re: run vncserver on startup?

Sorry, I was to fast, dont funtion, I get wrong type of accessmode know.

Offline

#12 2007-09-21 01:36:41

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: run vncserver on startup?

Klas wrote:

Sorry, I was to fast, dont funtion, I get wrong type of accessmode know.

What do you mean by accessmode? The script is not executable? Can you post console outputs here?

Offline

#13 2007-09-21 02:00:12

Klas
Member
Registered: 2007-09-18
Posts: 13

Re: run vncserver on startup?

The script is executeble and Ive got it to function know!

Thing that I did wrong was that the first time I was executing the command vncserver I did it as sudo! Then I got al wrong permission for the files in .vnc!
I deletede the map .vnc and did a new first start of vncserver! I even did that with your script!

Thank you for your help, I am greatfull!

Last edited by Klas (2007-09-21 02:03:43)

Offline

#14 2007-09-21 18:16:07

Klas
Member
Registered: 2007-09-18
Posts: 13

Re: run vncserver on startup?

Heres my Tightvnc start script. change usernr1 usernr2 usernr3 to the username you whant to have access through vncserver. You need to have -coresponding lines of VNCSERVERARGS[X]="-geometry 1152x864 -depth 24" under (three user three lines and so on):

A dont give any garanty for the security issues and I would bee glad if people would like to test it and give me feedback on it!

I have change the status command so that it shows the PID process running from Xvnc (the processes for th vncserver). You may comment out that so not every one can check who ' s running a vnc server.

#!/bin/bash
# /etc/rc.d/vncserver_user
#TIGHTVNC SERVER START - STOP -STATUS SCRIPT as Daemon 
#Only for regular user in HOME folder (not root)
# general config
. /etc/rc.conf
. /etc/rc.d/functions

unset VNCSERVERARGS
VNCSERVERS="1:usernr1 2:usenr2 3:usernr3"
VNCSERVERARGS[1]="-geometry 1152x864 -depth 24"
VNCSERVERARGS[2]="-geometry 1152x864 -depth 24"
VNCSERVERARGS[3]="-geometry 1152x864 -depth 24"


start() {
    echo -n $"Starting VNC server:"
    ulimit -S -c 0 >/dev/null 2>&1

    if [ ! -d /tmp/.X11-linux ]
    then
        mkdir -m 1777 /tmp/.X11-linux || :
    fi
    for display in ${VNCSERVERS}
    do
        echo -n "${display} "
    unset BASH_ENV ENV
    DISP="${display%%:*}"
    export USER="${display##*:}"
    export VNCUSERARGS="${VNCSERVERARGS[${DISP}]}"
        su - ${USER} -c "cd /home/${USER} && [ -f .vnc/passwd ] && source /etc/profile && source /home/${USER}/.bashrc && vncserver -name ${USER} :${DISP} ${VNCUSERARGS}" >/dev/null 2>&1
    done
    if [ $? -gt 0 ]; then                  
      stat_fail 
      echo "vncserver failed to start!"
      sleep 3         
    else       
      add_daemon vncserver_user
      stat_done 
      echo "vncserver started"
      sleep 3                
    fi  
}

stop() {
    echo -n $"Shutting down VNC server: "
    for display in ${VNCSERVERS}
    do
        echo -n "${display} "
    unset BASH_ENV ENV
    export USER="${display##*:}"
    su ${USER} -c "vncserver -kill :${display%%:*}" >/dev/null 2>&1
    done
    if [ $? -gt 0 ]; then                  
      stat_fail 
      echo "vncserver failed to stop!"
      sleep 3         
    else       
      rm_daemon vncserver_user
      stat_done 
      echo "vncserver stoped"
      sleep 3               
    fi 
}

# See how we were called.
case "$1" in
  start)
    start
  ;;
  stop)
    stop
  ;;
  restart|reload)
    stop
    start
   ;;
  condrestart)
     if [ -f /var/lock/subsys/vncserver ]; then
      stop      
     start
    fi
  ;;
  status)
echo "VNC SERVER status:"
   status Xvnc 
#
#You may comment out this two lines for security resons:
#
echo "Process up and running is:"
ps -o user,pid,ppid,command ax | grep Xvnc
  ;;
  *)
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    exit 1
esac

cool ?!

Last edited by Klas (2007-09-21 18:22:40)

Offline

Board footer

Powered by FluxBB