-   Linux - Software (
-   -   VNCServer on startup: What am I doing wrong? (

MikeOfAustin 05-29-2007 04:53 PM

VNCServer on startup: What am I doing wrong?
I've created a symbolic link inside init.d/

/etc/init.d/vncserver -> /usr/bin/vncserver
(one did not already exist).

and created a symbolic link in rc3.d/

/etc/rc3.d/S99vncserver -> /etc/init.d/vncserver

But it won't start automatically. It works if I manually start it. What else do I need to do?

acid_kewpie 05-29-2007 05:05 PM

/etc/init.d/vncserver is *NOT* a symlink to a binary, it is a service script which controls the startup processes. just read any other script to see how they work. there is often a very basic one you can customize.

MikeOfAustin 05-29-2007 05:58 PM

Correct, but 'vncserver' did not already exist under init.d (I had manually created the link).

So, I out of curiosity, I removed the link and copied the real thing over. vncserver from /usr/bin/ to the init.d directory, and it still won't start automatically. I would assume it's the correct script because about a dozen lines down it says

" # vncserver - wrapper script to start an X VNC server. "

So now I have


/etc/rc3.d/S99vncserver -> /etc/init.d/vncserver


(not a link)

The permissions are all fine for both files.

Phil-B 05-29-2007 06:17 PM

Hi there,

If you have a look at any of the other files in /etc/init.d you will be able to see the correct format of file you want in there.

You aren't supposed to simply link the binaries or startup scripts of whatever you're trying to run. I'm surprised there isn't already a script for this on your system: would have expected it to install one by default.

Nevertheless, try this:

Remove the vncserver file you copied into /etc/init.d and ensure it's back in it's original place (/usr/bin/vncserver as you said). At this point there should be no file named vncserver in your /etc/init.d.



vi /etc/init.d/vncserver
Press i

Paste the following in:


# 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

[ -f /etc/sysconfig/vncservers ] && . /etc/sysconfig/vncservers

prog=$"VNC server"

start() {
    echo -n $"Starting $prog: "
    ulimit -S -c 0 >/dev/null 2>&1
    for display in ${VNCSERVERS}
        echo -n "${display} "
        unset BASH_ENV ENV
        export USER="${display##*:}"
        export VNCUSERARGS="${VNCSERVERARGS[${DISP}]} -localhost" # -localhost
        initlog $INITLOG_ARGS -c \
            "su ${USER} -c \"cd ~${USER} && [ -f .vnc/passwd ] && vncserver :${DISP} ${VNCUSERARGS}\""
        [ "$RETVAL" -ne 0 ] && break
    [ "$RETVAL" -eq 0 ] && success $"vncserver startup" || \
        failure $"vncserver start"
    [ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/vncserver

stop() {
    echo -n $"Shutting down $prog: "
    for display in ${VNCSERVERS}
        echo -n "${display} "
        unset BASH_ENV ENV
        export USER="${display##*:}"
        initlog $INITLOG_ARGS -c \
            "su ${USER} -c \"vncserver -kill :${display%%:*}\" >/dev/null 2>&1"
    [ "$RETVAL" -eq 0 ] && success $"vncserver shutdown" || \
        failure $"vncserver shutdown"
    [ "$RETVAL" -eq 0 ] && rm -f /var/lock/subsys/vncserver

# See how we were called.
case "$1" in

(Script taken from an old Fedora installation that works for me)

Press ESC, then type :wq and press Enter.

You should be left at a command prompt.

As root, do:


chmod 755 /etc/init.d/vncserver
chkconfig vncserver on

Assuming the script works, your VNC server should now run at boot time.

Hope this is of some help!

MikeOfAustin 05-29-2007 07:02 PM

Unfortunitly, the cut-n-paste you provided (for fedora) choked as I'm on edgy. This is what I have for a script under init.d/
I can start and stop the vncserver just fine using this ( etc/init.d/vncserver stop <or start>).


#! /bin/sh
# /etc/init.d/vncserver

# Some things that run always

# none

# main
case "$1" in
/usr/bin/vncserver -kill :1
echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1

exit 0
I've ran the ' sudo update-rc.d vncserver defaults ' (ubuntu's version of chkconfig).
I've verified that /etc/rc#.d/ has the S##vncserver in the directories with the right permissions.
This is just strange. I can start and stop it all day, but it won't start on boot.

Also, FWIW, I'm currently editing this remotely and issuing a 'sudo reboot' everytime I make some changes to test it out. I can tell if it's working by ' ps x | grep vnc ' or just by vncviewer remotely.

Phil-B 05-29-2007 07:30 PM

Ah right sorry for the presumptuous Fedora spam - call it first post nerves ;)

It's a bit weird that "update-rc.d defaults" doesnt just work.

Perhaps you're booting into a runlevel for which vncserver has not been configured to run? I can't see why this would be the case though, because update-rc.d defaults should create a startup link for runlevels 2,3,4,5.

I take it theres nothing in the logs that's helpful?

MikeOfAustin 05-29-2007 08:12 PM

Yep. It's got me stumped!

I've got 'S20vncserver' in rc2.d, rc3.d and rc5.d . (these were created with 'update-rc.d vncserver defaults').

In /etc/init.d/ I have vncserver. This has all permissions granted and is executable.
While in terminal window under non-root user, I type '/etc/init.d/vncserver start' and I get a new X session on :1.
Manually starting it works great. No errors, etc.

...and, other than the usuall logs under /var/logs, I wouldn't know where to look for error messages. Do you???

Really weird. It's something small, I know it.

acid_kewpie 05-30-2007 02:44 AM

you're not paying attention to what we're saying ehh? /etc/init.d/vncserver is *NOT* *NOT* *NOT* the same as /usr/bin/vncserver. they do DIFFERENT things. copying that binary file to there will not work (unless sheer luck of command line options and default config files happen to line up) just read an existing script and modify it to suit your needs if you can't find an existing init.d script on google.

tredegar 05-30-2007 04:45 AM

I don't understand why you want to make this so complicated.
I start a vncserver at boot with this line in rc.local:

su - tredegar -c "cd /home/tredegar/ && vncserver :1 -geometry 1024x768 -depth 24"
It works just fine.
Edit: I forgot the final '"'

Phil-B 05-30-2007 05:20 AM


When I start my vncserver it puts logs into /var/log/messages, but nothing particularly useful.

There are also more specific logs in /home/myvncuser/.vnc/myhostname:1.log (man vncserver).

But obviously logs will only be helpful if the script is being run and failing, not if the script isnt running at all.

Like Chris says, the file at /etc/init.d/vncserver should be a SysV style init script. That's what your distribution expects to be there and if what you posted earlier is your /etc/init.d/vncserver then it looks alright.

One further thing though - your script doesnt start with any arguments and by default vncserver tries to start as the current user on display number 1. If your script were to run during boot it would try to set up a VNC session for root I would imagine. Try editing your command line in your script to something like what tredegar posted. If you look at the script I posted earlier, you can see it does the same as tredegars simple command line, albeit in a long winded but more general way (it will read a file and set up multiple VNC sessions depending on usernames and display numbers that I specify).

Something simple such as the following may work in your script as a replacement for your /usr/bin/vncserver line:


su - yourusername -c /usr/bin/vncserver
But you might want to specify some further options as tredegar has.


MikeOfAustin 05-30-2007 01:49 PM

Phil, that did it. Thanks very much to you and everyone that helped.

I had never setup the root password for vncserver, so it was choking when it tried to run as root. Giving it a su - myusername worked like a charm. I've learned quite a bit about scripting over this little exercise. One less whiny noob in the world...

All times are GMT -5. The time now is 03:00 AM.