How to launch VNC with aMule at Linux boot

From AMule Project FAQ
Jump to: navigation, search

General

This describes a very simple configuration to launch VNC at Linux startup (as a specified user). aMule will be launched automatically with VNC. This will work in Slackware and distro based on the same init method. If someone knows how to modify it to make it work under other distros you are welcome to add it to this page. Thanks.

Add the rc.vnc script to /etc/rc.d

Modify user according to the user running aMule.
The rm /tmp/.X11-unix/X$theScreen is there in case the server crashes or your mother/wife/husband removes the power plug cleaning the room... ;-)

#!/bin/sh
#
# Startup/Stop script for vncserver.
#

#Here, the choosen user to run amule
theUser=choosenuser
#And here, the choosen screen to run the vncserver
theScreen=1

case "$1" in

'start')
if [ -f /tmp/.X11-unix/X$theScreen ]; then rm /tmp/.X11-unix/X$theScreen; fi
/bin/su - $theUser -c "PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin /usr/bin/vncserver :$theScreen"
;;

'stop')
/bin/su - $theUser -c "/usr/bin/vncserver -kill :$theScreen"
;;

*)
echo "Usage: /etc/rc.d/rc.vnc { start | stop }"
;;

esac

Make it executable with:

chmod 755 /etc/rc.d/rc.vnc

Modify the following files:

In /etc/rc.d/rc.local add:

# Start VNC server
if [ -x /etc/rc.d/rc.vnc ]; then
. /etc/rc.d/rc.vnc start
fi

In /etc/rc.d/rc.6 add:

# Shut down the VNC server
if [ -x /etc/rc.d/rc.vnc ]; then
/etc/rc.d/rc.vnc stop
fi

In ~/.vnc/xstartup (in home directory of the user specified above) add (change with your preferred aMule startup script):

amule &

By Aleksy: Note for Slackware: if you use kde as X with vncserver, please add one more env variable to PATH=.....:/opt/kde/bin. in other case you will get gray screen after launching vncviewer. OR you can add to xstartup (before startkde) PATH="/opt/kde/bin:"$PATH.

On Debian Woody

Run (as root):

apt-get install vncserver xvncviewer flwm

There is no support for ~/.vnc/xstartup so, instead, use $vncStartup in .vncrc to determine a xstartup-script (this replaces your ~/.xsession file).

For more information, read man vnc.conf

For example, in a Woody/Sarge/Sid:
Login as the user who is going to run aMule
mkdir ~/.vnc/
Create the ~/.vnc/xstartup file, with the next content

/usr/bin/flwm &
/usr/bin/amule &
/usr/bin/amule &

With sone versions of vncserver, it's necessary to launch at least twice the aMule. The flwm is an optional window manager.

Create the file ~/.vncrc with the next content:
Login as the user and run xvncviewer :1 to create the password file and debug possible problems (the logs are under the ~/.vnc/ dir

$vncStartup = "/home/amule/.vnc/xstartup";
$geometry ="800x600";

(replace /home/amule for the home of the user running VNC)

To show the aMule window, run: xvncviewer localhost:1

If you want to autostart a VNC session on system startup, you can put a line in /etc/init.d/bootmisc.sh like this:

su username -c vncserver

Replace username with the name of the user that you want to launch vnc. (Added by ghent)

To start aMuleWeb also at startup:

This is probably the most unelegant way to do this, but it seems to work.

The problem is that you have to supply user input when starting aMuleWeb (the password).

You can circumvent this with supplying a password with the -pw option: amuleweb -pw "" (this is for no password, you have to remove the MD5 sum from the ECPassword entry in your ~/.eMule file for this to work).

Now aMuleWeb starts without any user input, but unfortunately it wouldn't work when we would just add it to the xstartup-file, because aMule needs a few seconds more to start up.

Therefor we have to start aMuleWeb a few seconds after aMule.

To achieve this, we add a line similar to this one:

/bin/sh /home/aMule/amuleweb-start.sh &

to the xstartup-file.

And in the home-directory, we create a file called amuleweb-start.sh, with the following content:

 #! /bin/sh
 sleep 30;
 /usr/bin/amuleweb -pw "";

That's all.

Like I said, probably extremely amateurish, but it should work...

Mandrake 10.0

The script from Frankk is the one I use, but you can customize the size of the VNC server : /bin/su - $theUser -c "PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin /usr/bin/vncserver :$theScreen"

add

/bin/su - $theUser -c "PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin /usr/bin/vncserver :$theScreen -geometry 1240x980"

or whatever value.

Personaly, I use as xstartup script (iceWM is really nice and so CPU-cheap) :

#!/bin/sh
starticewm&
amule

To start VNC at startup, I called the previous script /etc/init.d/amulevnc and chmod to 744 (chmod 744 /etc/init.d/amulevnc as root).
Instead of modifying /etc/rc.d/rc.vnc, I added links in the corresponding /etc/rc$RUNLEVEL.d directories.
It's quite simple to understand how it works:
Each directory represents a runlevel, and contains links to the scripts from /etc/init.d which need to be run/stop.
For instance, the link /etc/rc5.d/S55sshd to /etc/init.d/sshd will start sshd on runlevel 5, whereas /etc/rc6.d/K25sshd linked to /etc/init.d/sshd will stop it in runlevel 6.
You get it? Links starting with 'KXX' will stop a service, and those starting with 'SXX' will start them. The number will define the order.

So to run VNC on startup, just do (as root :-) ) re>ln -s /etc/init.d/amulevnc /etc/rc5.d/S99amule ln -s /etc/init.d/amulevnc /etc/rc6.d/K02amule and you're all set!

PS: This method should work on systems other than Mandrake, give it a test.

Questions & comments: air_1 at libertysurtf.fr


Gentoo

For Gentoo'ers follow these steps:

ATENTION: THE BOOT PROCESS NOW WORKS

Install VNC

This is a how to for a server with no X window manager at all. I only run web and mail services, and of course, aMule. Adapt to your situation. I use TightVNC, but should also work with other VNC's.

# emerge tightvnc

Configuring VNC

Server Config

To configure the VNC server, execute:

 # vncserver :0

I'm using :0 because there is no window manager running, so no need to use :1 , plus, it will be simpler to connect to it like this, simply:

 # vncviewer <host>

You'll be asked to answer some questions, such as password, answer accordingly. After you can kill it:

 # vncserver -kill :0

Programs to Start

Now let's config what should be started with this VNC session. Edit ~/.vnc/xstartup:

 # vi ~/.vnc/xstartup

You should see something like:

#!/bin/sh
PATH="$PATH:/usr/bin"
xrdb $HOME/.Xresources
xsetroot -solid grey
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
exec wmaker

xterm is a console, and twm is the window manager. I now use WindowMaker, and don't want no terminal, just aMule so, it's like this:

#!/bin/sh
PATH="$PATH:/usr/bin"
xrdb $HOME/.Xresources
xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
amule &
exec wmaker

Starting VNC at boot

Since I won't be starting no Window Manager at boot, but still want aMule started with the user interface(you could just run aMuled), I'll need an init script:

# vi /etc/init.d/vncserver

Make it look like:

#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

depend() {
	need net
}

checkconfig() {
        ebegin "Load config"
	PATH="$PATH:/usr/X11R6/bin/"
	
	# The Username:Group that will run VNC
	export USER="vampas"
	#${RUNAS}

	# The display that VNC will use
	DISPLAY="0"

	# Color depth (between 8 and 32)
	DEPTH="16"
	
	# The Desktop geometry to use.
	#GEOMETRY="<WIDTH>x<HEIGHT>"
	#GEOMETRY="800x600"
	GEOMETRY="1024x780"
	#GEOMETRY="1280x1024"

	# The name that the VNC Desktop will have.
	NAME="aMule"

	OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
	eend $? "Config not Loaded"
} 
	
start() {
        checkconfig
	ebegin "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
	su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
	eend $?
}

stop() {
	checkconfig
	ebegin "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
	su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
	eend $?
}

restart() {
	svc_stop
	sleep 3
	svc_start
}

Make it executable:

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


Now add it to boot:


# rc-update add vncserver default


And you should be ready to go, if not <ufs AT sapo DOT pt>