Version 8 (modified by Cas, 9 years ago) (diff)

--

systemd Scripts

Note: Improvements to propagate from Upstart still: deluge-web starting upon deluged starting and filesystems are mounted e.g. local-fs.target and remote-fs.target.

Verify Deluge Installion

Ensure Deluge daemon deluged and Web UI deluge-web are installed.

Use which deluged or which deluge-web to check installation path.

If they are not installed in the usual /usr/bin modify the service file ExecStart? lines to point to the correct location (e.g. /usr/local/bin/deluged).

User Management

For security it is best to run a service with a specific user and group. You can create one using the following command:

sudo adduser --system  --gecos "Deluge Service" --disabled-password --group --home /var/lib/deluge deluge
  • This creates a new system user and group named deluge with no login access and home directory: /var/lib/deluge

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

sudo adduser <username> deluge

Migration from init.d or Upstart scripts

Remove any old init.d files named deluge in /etc/init.d/ like this:

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

Remove old upstart scripts like this:

sudo stop deluged
sudo stop deluge-web
sudo rm /etc/init/deluge-web.conf
sudo rm /etc/init/deluged.conf

Deluge Daemon (deluged) Service

Create the file /etc/systemd/system/deluged.service containing the following:

[Unit]
Description=Deluge Bittorrent Client Daemon
After=network-online.target

[Service]
Type=simple
User=deluge
Group=deluge
UMask=007

ExecStart=/usr/bin/deluged -d

Restart=on-failure

# Configures the time to wait before service is stopped forcefully.
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target
  • 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.

Now start the service, verify it is running and enable it to start up on boot:

systemctl start deluged
systemctl status deluged
systemctl enable deluged

Deluge Web UI (deluge-web) Service

Create the file /etc/systemd/system/deluge-web.service containing the following:

[Unit]
Description=Deluge Bittorrent Client Web Interface
After=network-online.target

[Service]
Type=simple

User=deluge
Group=deluge
UMask=027

ExecStart=/usr/bin/deluge-web

Restart=on-failure

[Install]
WantedBy=multi-user.target

Now start the service, verify it is running and enable it to start up on boot:

systemctl start deluge-web
systemctl status deluge-web
systemctl enable deluge-web

Logging

Create a log directory for Deluge and give the service user (e.g. deluge), full access:

sudo mkdir -p /var/log/deluge
sudo chown -R deluge:deluge /var/log/deluge
sudo chmod -R 750 /var/log/deluge
  • The deluge log directory is now configured so that user deluge has full access, group deluge read only and everyone else denied access. The umask specified in the services sets the permission of new log files.

Enable logging in the service files by editing the ExecStart line, appending -l and -L options:

ExecStart=/usr/bin/deluged -d -l /var/log/deluge/daemon.log -L warning
ExecStart=/usr/bin/deluge-web -l /var/log/deluge/web.log -L warning

Restart the services:

systemctl restart deluged
systemctl restart deluge-web

Log Rotation

To enable log rotation create /etc/logrotate.d/deluge with the following code:

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