= systemd Scripts = '''Note:''' Improvements to propagate from [wiki:UserGuide/Service/Upstart/ 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 [wiki:Installing/Linux 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 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: [[Include(http://git.deluge-torrent.org/deluge/plain/packaging/systemd/deluged.service?h=develop, text/plain)]] * 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 [http://en.wikipedia.org/wiki/Umask#Octal_umasks 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 enable it to start up on boot, start the service and verify it is running: {{{ systemctl enable /etc/systemd/system/deluged.service systemctl start deluged systemctl status deluged }}} == Deluge Web UI (deluge-web) Service == Create the file `/etc/systemd/system/deluge-web.service` containing the following: [[Include(http://git.deluge-torrent.org/deluge/plain/packaging/systemd/deluge-web.service?h=develop, text/plain)]] Now enable it to start up on boot, start the service and verify it is running: {{{ systemctl enable /etc/systemd/system/deluge-web.service systemctl start deluge-web systemctl status 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 }}} * See [wiki:Troubleshooting#EnableDelugeLogging Deluge Logging] for all available log-levels. 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 } }}} == Start `deluged` only if mount exists == If you have a usb disk drive or network drive that may not be immediately available to the `deluged`. The following additions wait for those mountpoints before starting `deluged`. Ensure you have added the correct drive details to `fstab` or equivalent so they are mounted at boot. List the available drive mounts like so: {{{ systemctl -t mount }}} Modify the `[Unit]` section of the `deluged.service` script. Changing `xyz.mount` for the mount from the above command: {{{ [Unit] Description=Deluge Bittorrent Client Daemon # Unit starts after network and specified mounts are available. After=network-online.target xyz.mount Requires=xyz.mount # Unit is stopped when any of these mounts disappear. BindsTo=xyz.mount }}} Reference: [https://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresMountsFor= systemd.unit]