# How to get VNC Server to start when Gentoo starts?

## raid517

Hi I have two VNC packages installaed net-isc/xf4vnc  net-misc/vnc (which I think is a variant of realvnc).

The question I have is I hope simple.

How do I get my vnc server to start when Gentoo starts?

I thought the obvious thing to do would of course be:

```
 rc-update add vnc default
```

But that didn't work - as it fails with the error:

```
/sbin/rc-update: /etc/init.d/vnc not found; aborting
```

I tried with various variations of this, using the term vncserver, tightvnc etc - but the bottom line is that I don't have anything at all in /etc/init.d called 'vnc' even anything similar to it.

I'm guessing therefore that I need some kind of script in there to start my vncserver. the question is, what is this script and where can I get it?

GJ

----------

## lesourbe

take a look at that

----------

## raid517

Thanks... But I don't think that's quite what I'm after. I am not asking how to get VNC server to work - it already works very well - all I am asking is how to get it to start when Gentoo starts. That's all. nothing more.

GJ

----------

## lesourbe

I think the name of the init script is vncserver and not vnc (I am not on a gentoo box right now).

If that's so, it would be 

```
rc-update add vncserver default
```

If not, you could check in /etc/init.d/ to find the init script corresponding to vnc server

----------

## raid517

Well yes, that would be the obvious thing to do as i said. However as I also pointed out, I don't have anything in init.d that relates to vnc, be that vnc. vnc server, tightvnc, or whatever. There is no reference to vnc in init.d at all.

GJ

----------

## lesourbe

 *raid517 wrote:*   

> Hi I have two VNC packages installaed net-isc/xf4vnc  net-misc/vnc (which I think is a variant of realvnc).
> 
> 

 

sorry I did not read carrefully enough your post

net-isc/xf4vnc : Description: VNC (remote desktop viewer) derived from tightvnc but cooler  :Smile: 

net-misc/vnc : Description: Remote desktop viewer display system

2 viewers but no server here.

----------

## raid517

Well i must have some kind of VNC server installed. Sorry I'm running from one of those (now increasingly avaiable) prebuilt Gentoo distros - so (after reading the docs) I am not exactly clear what it came with. All I do know is if I type vncserver at the command line, it gives me a default vnc name/address - and I can connect to it without difficulty. So the server part is there.

However as I said, you would expect that if it could be autostated normally, that there would be a reference to it in /etc/init.d - but as far as i can see, there is currently no reference to anything to do with vnc in init.d at all.

GJ

----------

## overkll

Try

```
emerge -s vnc
```

to determine which vnc package(s) you have installed.

 *lesourbe wrote:*   

> take a look at that

 

You may want to check out the xinetd section.  Some services DON'T use an init script.  Instead they use the xinetd superdaemon to start services.  You may want to check your /etc/xinet.d/ directory for some sort of existing vnc/xinetd config file.  Make sure that "disabled = no" to ensure it starts then issue /etc/init.d/xinetd start to start it.

----------

## raid517

No, sadly, again, there is nothing there.

```
# ls /etc/xinetd.d

cups-lpd cvsperver proftpd swat telenettd
```

Couldn't I just add a small script to my startup srcipts in /etc/init.d that would start it at boot?

If so, what would such a script look like?

GJ

----------

## Jfr0

equery list vnc 

will tell you what vnc you have installed. I am guessing realvnc.  

If you dont want to make an init script then you could just try /etc/conf.d/local.start

----------

## raid517

Thanks - that looks like a possible candiadate. unfortunately the syntax to enter in this script to start the vnc server is still confusing me slightly. (I do appologise I am in no way a programmer - and in reality I only have about one or two hours that I can set aside for learning linux each week).

At the moment all I do know is that the command to start the vnc server is simple enough, as it is just 'vncserver'. How would I add this to this script to ensure that the VNC server started automatically at each boot?

GJ

----------

## raid517

No takers?  :Sad: 

GJ

----------

## overkll

lesourbe posted a link to a nice gentoo specific howto - http://gentoo-wiki.com/HOWTO_Xvnc_terminal_server

Did you try that?

I don't use vnc.  I was only pointing out the xinetd issue.  You may need to create your own /etc/xinetd.d/vncserver file as suggested in the howto OR just put "vncserver" in your /etc/conf.d/local.start file...

```
# /etc/conf.d/local.start

# This is a good place to load any misc programs

# on startup ( use 1>&2 to hide output)

/usr/bin/vncserver
```

Make sure that /etc/init.d/local is set to startup at boot.

To restart the local service, just issue "/etc/init.d/local restart"

----------

## raid517

Cool, that's exactly what I have done! The thing that was confusing me is that there are quite a few other things put in there by the developer - and to the untrained eye such as mine, it didn't make much sense. But now hopefully, I have it figured out. Thanks!

GJ

----------

## raid517

Actually that didn't work. The system now just demands that I type a password before agreeing to startX - and I still have to type 'vncserver' at the rootprompt if I want my vncserver to start when my computer starts.

GJ

----------

## thedangerouscrew

How do you startx?

do you type 'startx' it in the prompt?

if so you need to add it to your .xinitrc file

example:

vncserver &

path to window manager

if you use kde just add it to your autostart dir

I hope this helps you.

edit: If you want to start Xvnc without starting a real Xsesion than let me know

        this is how I have mine

       check this link out  http://linuxgazette.net/issue72/chung.html

       replace startx with vncviewer in the .bash_profile section

----------

## armin76

I use this script:

```
#!/sbin/runscript

# Copyright 2003-2004 Gentoo Foundation

# Distributed under the terms of the GNU General Public License, v2

# $Header: /var/cvsroot/gentoo-x86/net-ftp/vsftpd/files/vsftpd.init.d,v 1.6 200$

start() {

        ebegin "Starting vnc"

        su - armin -c "vncserver :1"

        eend $?

}

stop() {

        ebegin "Stopping vnc"

        su - armin -c "vncserver -clean -kill :1"

        eend $?

}

```

The vncserver is started as username 'armin'. Stolen from the vsftpd script, of course  :Smile: 

----------

## raid517

Thanks

----------

## raid517

```
 #!/sbin/runscript 

 # Copyright 2003-2004 Gentoo Foundation 

 # Distributed under the terms of the GNU General Public License, v2 

 # $Header: /var/cvsroot/gentoo-x86/net-ftp/vsftpd/files/vsftpd.init.d,v 1.6 200$ 

 

 start() { 

         ebegin "Starting vnc" 

         su - raid517 -c "vncserver :1" 

         eend $? 

 } 

 

 stop() { 

         ebegin "Stopping vnc" 

         su - raid517 -c "vncserver -clean -kill :1" 

         eend $? 

 }
```

Hi as I said thanks. That would have been nice, if it had worked - unfortunately it didn't.

I can't add 'vncserver' to my xsession or x startup or xinitrc as if I do so this seems to cause some kind of infinite loop, where x never really fully starts up and my disk just goes crazy with the system swapping endlessly - so I think what I need really is some kind of start up script.

I have no idea why the above script didn't work.

Possibly I got the method for adding it wrong?

I moved it to my /etc/init.d and made it executable. I then opened a console and typed (as root): 

```
rc-update add vnc default
```

The system gave me a claen message about adding the script to the default run level. (as you can see I called the script vnc).

[/i]

As for what I wish to achieve, I simply wish to maintain the status quo. I am happy with whatever version of 'vncserver' I have installed and I don't really wnat to change it. [i] don't want vncserver to start in place of x, or to use a vncserver that allows me to share a desktop session.

All I really want is for it to start up when Gentoo starts, without my needing to always manually start it by typing 'vncserver' at a command line.

If anyone can help me achieve this, I would be extremely grateful.

GJ

----------

## thedangerouscrew

xdm, gdm, kdm

all of these graphical logins can listen for a vnc request

could be another alternative for you.

it sounds like the nusts and bolts method in this article is what you want

http://linuxgazette.net/issue72/chung.html

it lets you autologin your user and autostart X when logged in

this is how i tweaked it to my needs

I replaced:  if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then

                    startx

                  fi

With:  if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then

            vncserver

         fi

in the .bash_profile part of the howto

I hope this helps

----------

## raid517

Actually I retract that. The above script works great. There was an extra gap introduced by the straight copy and pasting I did into the bash script that I made and as soon as I eliminted this things worked as expected.

Thanks guys!

GJ

----------

