Difference between revisions of "How to launch VNC with aMule at Linux boot"

From AMule Project FAQ
Jump to: navigation, search
(General)
 
(54 intermediate revisions by 23 users not shown)
Line 1: Line 1:
<h2>''By Frankk''</h2>
+
== 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 describes a very simple configuration to launch [http://www.redstonesoftware.com/vnc.html VNC] at [http://www.kernel.org Linux] startup (as a specified user). [[aMule]] will be launched automatically with [http://www.redstonesoftware.com/vnc.html 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.
+
This will work in [http://www.slackware.com 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''
 
Add the ''rc.vnc'' script to ''/etc/rc.d''
  
 
Modify user according to the user running [[aMule]].<br>
 
Modify user according to the user running [[aMule]].<br>
The ''rm /tmp/.X11-unix/X11'' is there in case the server crashes or your mother/wife removes the power plug cleaning the room... ;-)
+
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... ;-)
  
''<pre>
+
''#!/bin/sh''<br>
--------Start of rc.vnc--------
+
''#''<br>
#!/bin/sh
+
''# Startup/Stop script for vncserver.''<br>
#
+
''#''<br>
# Startup/Stop script for vncserver.
+
#
+
  
case "$1" in
+
''#Here, the choosen user to run amule''<br>
 +
''theUser=choosenuser''<br>
 +
''#And here, the choosen screen to run the vncserver''<br>
 +
''theScreen=1''
  
'start')
+
''case "$1" in''
rm /tmp/.X11-unix/X1
+
/bin/su - user -c "PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin /usr/bin/vncserver :1"
+
;;
+
  
'stop')
+
'' 'start')''<br>
/bin/su - user -c "PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin /usr/bin/vncserver -kill :1"
+
''if [ -f /tmp/.X11-unix/X$theScreen ]; then rm /tmp/.X11-unix/X$theScreen; fi''<br>
;;
+
''/bin/su - $theUser -c "PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin /usr/bin/vncserver :$theScreen"''<br>
 +
'';;''
  
*)
+
'' 'stop')''<br>
echo "Usage: /etc/init.d/rc.vnc { start | stop }"
+
''/bin/su - $theUser -c "/usr/bin/vncserver -kill :$theScreen"''<br>
;;
+
'';;''
  
esac
+
''*)''<br>
--------End of rc.vnc--------
+
''echo "Usage: /etc/rc.d/rc.vnc { start | stop }"''<br>
</pre>''
+
'';;''
 +
 
 +
''esac''
 +
 
 +
Make it executable with:
 +
 
 +
''<pre>chmod 755 /etc/rc.d/rc.vnc</pre>''
  
 
Modify the following files:
 
Modify the following files:
Line 39: Line 44:
 
In ''/etc/rc.d/rc.local'' add:
 
In ''/etc/rc.d/rc.local'' add:
  
''<pre>
+
''# Start VNC server''<br>
# Start VNC server
+
''if [ -x /etc/rc.d/rc.vnc ]; then''<br>
if [ -x /etc/rc.d/rc.vnc ]; then
+
''. /etc/rc.d/rc.vnc start''<br>
. /etc/rc.d/rc.vnc start
+
''fi''
fi
+
</pre>''
+
  
 
In ''/etc/rc.d/rc.6'' add:
 
In ''/etc/rc.d/rc.6'' add:
  
''<pre>
+
''# Shut down the VNC server''<br>
# Shut down the VNC server
+
''if [ -x /etc/rc.d/rc.vnc ]; then''<br>
if [ -x /etc/rc.d/rc.vnc ]; then
+
''/etc/rc.d/rc.vnc stop''<br>
/etc/rc.d/rc.vnc stop
+
''fi''
fi
+
 
</pre>''
+
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 [http://www.debian.org 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:<br>
 +
Login as the user who is going to run [[aMule]]<br>
 +
''mkdir ~/.vnc/''<br>
 +
Create the ''~/.vnc/xstartup'' file, with the next content<br>
 +
 
 +
''/usr/bin/flwm &''<br>
 +
''/usr/bin/amule &''<br>
 +
''/usr/bin/amule &''
 +
 
 +
With sone versions of [http://www.redstonesoftware.com/vnc.html vncserver], it's necessary to launch at least twice the [[aMule]]. The [http://flwm.sourceforge.net flwm] is an optional window manager.
 +
 
 +
Create the file ''~/.vncrc'' with the next content:<br>
 +
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";''<br>
 +
''$geometry ="800x600";''
 +
 
 +
(replace ''/home/amule'' for the home of the user running [http://www.redstonesoftware.com/vnc.html VNC])
 +
 
 +
To show the [[aMule]] window, run:
 +
''xvncviewer localhost:1''
 +
 
 +
If you want to autostart a [http://www.redstonesoftware.com/vnc.html 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 [http://www.ietf.org/rfc/rfc1321.txt 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...
 +
 
 +
== [http://www.mandrake.com Mandrake] 10.0 ==
 +
 
 +
The script from [[User:Frankk|Frankk]] is the one I use, but you can customize the size of the [http://www.redstonesoftware.com/vnc.html 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 ([http://www.icewm.org iceWM] is really nice and so CPU-cheap) :
 +
 
 +
''#!/bin/sh''<br>
 +
''starticewm&''<br>
 +
''amule''
 +
 
 +
To start [http://www.redstonesoftware.com/vnc.html VNC] at startup, I called the previous script ''/etc/init.d/amulevnc'' and chmod to 744 (''chmod 744 /etc/init.d/amulevnc'' as root).<br>
 +
Instead of modifying ''/etc/rc.d/rc.vnc'', I added links in the corresponding ''/etc/rc$RUNLEVEL.d'' directories.<br>
 +
It's quite simple to understand how it works:<br>
 +
Each directory represents a runlevel, and contains links to the scripts from ''/etc/init.d'' which need to be run/stop.<br>
 +
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.<br>
 +
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 [http://www.redstonesoftware.com/vnc.html 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 [http://www.mandrake.com Mandrake], give it a test.
 +
 
 +
Questions & comments: ''air_1 '''at''' libertysurtf.fr''
 +
 
 +
 
 +
== [http://www.gentoo.org Gentoo] ==
 +
 
 +
For [http://www.gentoo.org Gentoo]'ers follow these steps:
 +
 
 +
'''<font color="red">ATENTION: THE BOOT PROCESS NOW WORKS</font>'''
 +
 
 +
=== Install [http://www.realvnc.com VNC] ===
 +
 
 +
This is a how to for a server with no [http://www.x.org X] window manager at all. I only run web and mail services, and of course, [[aMule]]. Adapt to your situation.
 +
I use [http://www.tightvnc.com TightVNC], but should also work with other [http://www.realvnc.com VNC]'s.
 +
 
 +
# emerge tightvnc
 +
 
 +
=== Configuring [http://www.realvnc.com VNC] ===
 +
 
 +
==== Server Config ====
 +
 
 +
To configure the [http://www.realvnc.com VNC] server, execute:
 +
 
 +
<pre>
 +
# vncserver :0
 +
</pre>
 +
 
 +
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:
 +
 
 +
<pre>
 +
# vncviewer <host>
 +
</pre>
 +
 
 +
You'll be asked to answer some questions, such as password, answer accordingly. After you can kill it:
 +
 
 +
<pre>
 +
# vncserver -kill :0
 +
</pre>
 +
 
 +
==== Programs to Start ====
 +
 
 +
Now let's config what should be started with this [http://www.realvnc.com VNC] session. Edit ''~/.vnc/xstartup'':
 +
 
 +
<pre>
 +
# vi ~/.vnc/xstartup
 +
</pre>
 +
 
 +
You should see something like:
 +
 
 +
<pre>
 +
#!/bin/sh
 +
PATH="$PATH:/usr/bin"
 +
xrdb $HOME/.Xresources
 +
xsetroot -solid grey
 +
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
 +
exec wmaker
 +
</pre>
 +
 
 +
[http://www.x.org xterm] is a console, and [http://www.x.org twm] is the window manager. I now use [http://www.windowmaker.org/ WindowMaker], and don't want no terminal, just [[aMule]] so, it's like this:
 +
 
 +
<pre>
 +
#!/bin/sh
 +
PATH="$PATH:/usr/bin"
 +
xrdb $HOME/.Xresources
 +
xsetroot -solid grey
 +
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
 +
amule &
 +
exec wmaker
 +
</pre>
 +
 
 +
=== Starting [http://www.realvnc.com 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:
 +
<pre>
 +
#!/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
 +
}
 +
</pre>
 +
 
 +
Make it executable:
 +
 
 +
# chmod +x /etc/init.d/vncserver
 +
 
 +
 
 +
Now add it to boot:
 +
 
 +
 
 +
# rc-update add vncserver default
 +
 
  
In ''~/.vnc/xstartup'' (in home dir of the user specified above) add (change with your preferred aMule startup script):
+
And you should be ready to go, if not ''<ufs AT sapo DOT pt>''  
  
<pre>''amule &''</pre>
+
----

Latest revision as of 14:51, 16 June 2009

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>