Version 13 (modified by Cas, 11 years ago) (diff)

update scripts and reword

Ubuntu Upstart Job

User Management

This guide assumes you have a user and group account specifically for running Deluge as. If not, you may need to create them using something like the following command:

# sudo adduser --system --group --home /var/lib/deluge deluge
  • Assuming the user and group didn't already exist, this creates a new system user and group named deluge with no login access and /var/lib/deluge as the home directory.

Add any users you wish to be able to easily manage or access files downloaded through Deluge to the group deluge will run as, for example:

# sudo adduser <username> deluge

Deluge Daemon (deluged) Upstart Script

Create the file /etc/init/deluged.conf with the following code and set uid and gid to the user and group you wish to run deluged as:

start on filesystem and stopped networking
stop on runlevel [016]

respawn
respawn limit 5 30

env uid=deluge
env gid=deluge
env umask=007

exec start-stop-daemon -S -c $uid:$gid -k $umask -x /usr/bin/deluged -- -d
  • You may wish to modify the above umask as it applies to any files downloaded by deluged.
    • 007 grants full access to the user and members of the group deluged is running as (in this case deluge) and prevents access from all other accounts.
    • 022 grants full access to the user deluged is running as and only read access to other accounts.
    • 000 grants full access to all accounts.

Refer to Wikipedia for details of possible values and their effects. Deluged must be stopped and started instead of just restarted after changes. If you enable logging, as described later in this page, the umasks specified here also affect the permissions of newly created logs.

Deluge Web UI (deluge-web) Upstart Script

Put this in /etc/init/deluge-web.conf, remember to set uid and gid to your preference:

start on started deluged
stop on stopping deluged

respawn
respawn limit 5 30

env uid=deluge
env gid=deluge
env umask=027

exec start-stop-daemon -S -c $uid:$gid -k $umask -x /usr/bin/deluge-web
  • Note: The use of a umask with deluge-web is believed to only affect the permissions of plugin scripts installed through the web UI and, if you enable logging, deluge-web logs.
    • 027 grants full access to the user deluge is running as, read access to members of the group that deluge is running as and prevents access from all other accounts.
      Group permission was restricted to read only in order to prevent the possibility that compromised member accounts could inject malicious code in to plugins or modify the log.

Migration from init.d script

If you followed the old guide to make an init script, remove it:

# sudo /etc/init.d/deluge-daemon stop
# sudo rm /etc/init.d/deluge-daemon
# sudo update-rc.d deluge-daemon remove

Starting (and stopping) Upstart Scripts

Deluge Daemon

# sudo start deluged
and stopping:
# sudo stop deluged

Web UI

Although the Web UI will start/stop automatically when deluged starts/stops it can be manually controlled with:

# sudo start deluge-web
and stopped with:
# sudo stop deluge-web
  • To prevent the web UI starting automatically comment out the start on line in deluge-web.conf by prefixing with #.

Logging

Create a structure for Deluge to log to and give the user that Deluge is running as (in this case deluge) full access to that directory:

# sudo mkdir -p /var/log/deluge
# sudo chown -R deluge:deluge /var/log/deluge
# sudo chmod -R 750 /var/log/deluge
  • Note: The previous commands affect the log directory and all files within it.
    However, as already mentioned, the umask specified in the upstart jobs at the top of this page affect the permissions new logs are created with.
    • 750 grants full access to the deluge user, only recurse tree and read access to members of the deluge group and prevents access from all other accounts.
      Refer to Wikipedia for details of possible values and their effects.

Edit the upstart job confs like so:

exec start-stop-daemon -S -c $uid:$gid -k $umask -x /usr/bin/deluged -- -d -l /var/log/deluge/daemon.log -L warning
exec start-stop-daemon -S -c $uid:$gid -k $umask -x /usr/bin/deluge-web -- -l /var/log/deluge/web.log -L warning
  • Refer to the FAQ for possible log-levels.

Restart the daemon:

# sudo restart deluge

Tell logrotate to rotate the logs by putting this in /etc/logrotate.d/deluge:

/var/log/deluge/*.log {
        rotate 4
        weekly
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                initctl restart deluge >/dev/null 2>&1 || true
                initctl restart deluge-web >/dev/null 2>&1 || true
        endscript
}