Jump to content

An init script for Ubuntu


simonbcn

Recommended Posts

  • 2 weeks later...

Hi.

1st: I'm a linux noob :P

For those who want to load utserver on boot, just copy the script to the folder where utserver is( gui will only run if utserver is called from the own dir) and then create a symlink(utserver) in rc2.d:

cd /etc/rc2.d/

sudo ln -sf <path to script> S99utserver

Link to comment
Share on other sites

Hi.

1st: I'm a linux noob :P

For those who want to load utserver on boot, just copy the script to the folder where utserver is( gui will only run if utserver is called from the own dir) and then create a symlink(utserver) in rc2.d:

cd /etc/rc2.d/

sudo ln -sf <path to script> S99utserver

@ultravox, the init script already uses an option to change to the utserver dir.

Edit the init script and change these values:

....
CHDIR=<dir containing utserver program>
....
USER=<username>
....

After, in linux distros like Ubuntu (and similar), you should do:

1) Copy the init script to "/etc/init.d/":

sudo cp <downloaded-filename> /etc/init.d/utserver-daemon

2) Execute this:

sudo chmod +x /etc/init.d/utserver-daemon

2) And this:

sudo update-rc.d utserver-daemon defaults

And go on!

Link to comment
Share on other sites

  • 3 weeks later...
Hi.

1st: I'm a linux noob :P

For those who want to load utserver on boot' date=' just copy the script to the folder where utserver is( gui will only run if utserver is called from the own dir) and then create a symlink(utserver) in rc2.d:

cd /etc/rc2.d/

sudo ln -sf <path to script> S99utserver[/quote']

@ultravox, the init script already uses an option to change to the utserver dir.

Edit the init script and change these values:

....
CHDIR=<dir containing utserver program>
....
USER=<username>
....

After, in linux distros like Ubuntu (and similar), you should do:

1) Copy the init script to "/etc/init.d/":

sudo cp <downloaded-filename> /etc/init.d/utserver-daemon

2) Execute this:

sudo chmod +x /etc/init.d/utserver-daemon

2) And this:

sudo update-rc.d utserver-daemon defaults

And go on!

Hi! I tried @simonbcn instructions but utorrent server didnt run on startup... when i tried running it directly

/etc/init.d/utserver-daemon

i got the following error -

/bin/sh: Illegal option -

any idea on what i am doing wrong?

the config on the script looks like this -

CHDIR=/home/aunlead/uTorrent/bittorrent-server-v3_0

NAME=utserver

OPTIONS="-LOGFILE"

DAEMON=$CHDIR/$NAME

USER=aunlead

PIDFILE=/var/run/$NAME.pid

STOP_TIMEOUT=5

Link to comment
Share on other sites

Hi! I tried @simonbcn instructions but utorrent server didnt run on startup... when i tried running it directly

/etc/init.d/utserver-daemon

i got the following error -

/bin/sh: Illegal option -

any idea on what i am doing wrong?

What distro?

The init script must be executed as root and you have to indicate the action: start, stop or restart.

Execute the script with:

sh -x /etc/init.d/utserver-daemon

And you'll see the line that produces this error.

Link to comment
Share on other sites

  • 1 month later...
Hi,

I use Ubuntu 10.04 32 bits on my server and I'm testing the µTorrent Server.

I've created a init script (between "<>" are the values to change in your case): http://pastebin.com/UE3kDg00

Here http://pastebin.com/pRpmA7sV I put your script a little optimised (/etc/init.d/utserver) working correctly on Ubuntu 10.10

For anyone who don't know yet: use http://127.0.0.1:8080/gui/ to access µTorrent Server web GUI

Link to comment
Share on other sites

Here http://pastebin.com/pRpmA7sV I put your script a little optimised (/etc/init.d/utserver) working correctly on Ubuntu 10.10

Which is the optimization? Do you execute µTorrent like "root"!!? :o I wouldn't say that is an optimization.

These scripts should be changed, µTServer creates its own pid file now with "-pidfile" argument in command-line.

Link to comment
Share on other sites

Here http://pastebin.com/pRpmA7sV I put your script a little optimised (/etc/init.d/utserver) working correctly on Ubuntu 10.10

Which is the optimization? Do you execute µTorrent like "root"!!? :o I wouldn't say that is an optimization.

These scripts should be changed' date=' µTServer creates its own pid file now with "[i']-pidfile" argument in command-line.

1st.

I call my script file name /etc/init.d/utserver so your line:

grep -U $USER $NAME >/dev/null

works not as I expect, so I change it to:

pgrep -f $DAEMON >/dev/null

2nd.

For some reasons during running tests of utserver I had run another instances of utserver and your line:

start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry $STOP_TIMEOUT

doesn't close them, so I change it to:

start-stop-daemon --stop --quiet --exec $DAEMON --retry $STOP_TIMEOUT

3th.

I change USER to 'root' but it's of course not so important.

Please don't take it personally. :)

Regards

Link to comment
Share on other sites

1st.

I call my script file name /etc/init.d/utserver so your line:

grep -U $USER $NAME >/dev/null

works not as I expect, so I change it to:

pgrep -f $DAEMON >/dev/null

It's the same name and the same path like previous init script... :rolleyes:

Probably the cause of your problem is by running it as root.

Moreover, you has forgotten to correct the line 38 too.

2nd.

For some reasons during running tests of utserver I had run another instances of utserver and your line:

start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON --retry $STOP_TIMEOUT

doesn't close them, so I change it to:

start-stop-daemon --stop --quiet --exec $DAEMON --retry $STOP_TIMEOUT

Why do you create the pid file then?

3th.

I change USER to 'root' but it's of course not so important.

It's important by security.

Please don't take it personally. :)

Well, it isn't personal. It's my opinion about your supposed "optimizations".

You have adapted the previous script to work in your case, but these aren't optimizations.

Regards.

Link to comment
Share on other sites

  • 1 month later...

I got this error after run the script, please help

+

: not found/utserver: 1:

+ CHDIR=/etc/utserver

+ NAME=utserver

+ OPTIONS=-LOGFILE

/utserver/etc/utserver

+ USER=madj

.pidDFILE=/var/run/utserver

+ STOP_TIMEOUT=5

+

: not found/utserver: 1:

]tservertc/utserver

+ exit 1

thanks

Link to comment
Share on other sites

"sudo sed -i 's/\r//g' /etc/init.d/utserver" solves the problems:

- "illegal option -"

- ": not found"

Works for me now.

And yes, running as root is a terrible idea.

Although the correct thing would be to create a nologin user for utorrent..

or create a Makefile to "make install" to do everything in an elegant way...

or create distro-centric install packages...

or give up since utorrent does not really give system based user access so it should just be run individually and not really as a init.d server, even though it is 'utserver' ...

ah, whatever...

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

Thanks for this script, I've found it to be a very useful quick reference. I'd just add one thing, if you want to multiple daemons you have to have two scripts, maintain two copies of utorrent(or separate and specify where the config files are), and comment out this line in your scripts:

pgrep -U $USER $NAME >/dev/null && echo "$NAME is already running" && log_end_msg 1

Apart from that you also don't want to start the same script twice, as that can be a mess.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...