1 | | = systemd Scripts = |
2 | | |
3 | | '''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`. |
4 | | |
5 | | |
6 | | == Verify Deluge Installion == |
7 | | |
8 | | Ensure Deluge daemon `deluged` and Web UI `deluge-web` are [wiki:Installing/Linux installed]. |
9 | | |
10 | | Use `which deluged` or `which deluge-web` to check installation path. |
11 | | |
12 | | 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`). |
13 | | |
14 | | == User Management == |
15 | | |
16 | | For security it is best to run a service with a specific user and group. You can create one using the following command: |
17 | | |
18 | | {{{ |
19 | | sudo adduser --system --gecos "Deluge Service" --disabled-password --group --home /var/lib/deluge deluge |
20 | | }}} |
21 | | |
22 | | * This creates a new system user and group named `deluge` with no login access and home directory: `/var/lib/deluge` |
23 | | |
24 | | Add to the `deluge` group any users you wish to be able to easily manage or access files downloaded through Deluge, for example: |
25 | | |
26 | | {{{ |
27 | | sudo adduser <username> deluge |
28 | | }}} |
29 | | |
30 | | |
31 | | == Migration from init.d or Upstart scripts == |
32 | | Remove any old init.d files named deluge in `/etc/init.d/` like this: |
33 | | {{{ |
34 | | sudo /etc/init.d/deluge-daemon stop |
35 | | sudo rm /etc/init.d/deluge-daemon |
36 | | sudo update-rc.d deluge-daemon remove |
37 | | }}} |
38 | | |
39 | | Remove old upstart scripts like this: |
40 | | {{{ |
41 | | sudo stop deluged |
42 | | sudo stop deluge-web |
43 | | sudo rm /etc/init/deluge-web.conf |
44 | | sudo rm /etc/init/deluged.conf |
45 | | }}} |
46 | | |
47 | | == Deluge Daemon (deluged) Service == |
48 | | Create the file `/etc/systemd/system/deluged.service` containing the following: |
49 | | |
50 | | [[Include(http://git.deluge-torrent.org/deluge/plain/packaging/systemd/deluged.service?h=develop, text/plain)]] |
51 | | |
52 | | |
53 | | * You may wish to modify the above `umask` as it applies to any files downloaded by deluged. |
54 | | * 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. |
55 | | * 022 grants full access to the user deluged is running as and only read access to other accounts. |
56 | | * 002 grants full access to the user and group deluged is running as and only read access to other accounts. |
57 | | * 000 grants full access to all accounts. |
58 | | 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. |
59 | | |
60 | | Now enable it to start up on boot, start the service and verify it is running: |
61 | | {{{ |
62 | | sudo systemctl enable /etc/systemd/system/deluged.service |
63 | | sudo systemctl start deluged |
64 | | sudo systemctl status deluged |
65 | | }}} |
66 | | |
67 | | == Deluge Web UI (deluge-web) Service == |
68 | | |
69 | | Create the file `/etc/systemd/system/deluge-web.service` containing the following: |
70 | | {{{ |
71 | | #!comment |
72 | | Don't link develop web service until 2.0 is released |
73 | | [[Include(http://git.deluge-torrent.org/deluge/plain/packaging/systemd/deluge-web.service?h=develop, text/plain)]] |
74 | | }}} |
75 | | |
76 | | {{{ |
77 | | [Unit] |
78 | | Description=Deluge Bittorrent Client Web Interface |
79 | | Documentation=man:deluge-web |
80 | | After=network-online.target deluged.service |
81 | | Wants=deluged.service |
82 | | [Service] |
83 | | Type=simple |
84 | | User=deluge |
85 | | Group=deluge |
86 | | UMask=027 |
87 | | # This 5 second delay is necessary on some systems |
88 | | # to ensure deluged has been fully started |
89 | | ExecStartPre=/bin/sleep 5 |
90 | | ExecStart=/usr/bin/deluge-web |
91 | | Restart=on-failure |
92 | | [Install] |
93 | | WantedBy=multi-user.target |
94 | | }}} |
95 | | |
96 | | Now enable it to start up on boot, start the service and verify it is running: |
97 | | {{{ |
98 | | sudo systemctl enable /etc/systemd/system/deluge-web.service |
99 | | sudo systemctl start deluge-web |
100 | | sudo systemctl status deluge-web |
101 | | }}} |
102 | | |
103 | | == Logging == |
104 | | Create a log directory for Deluge and give the service user (e.g. `deluge`), full access: |
105 | | {{{ |
106 | | sudo mkdir -p /var/log/deluge |
107 | | sudo chown -R deluge:deluge /var/log/deluge |
108 | | sudo chmod -R 750 /var/log/deluge |
109 | | }}} |
110 | | * 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. |
111 | | |
112 | | Enable logging in the service files by editing the `ExecStart` line, appending `-l` and `-L` options: |
113 | | {{{ |
114 | | ExecStart=/usr/bin/deluged -d -l /var/log/deluge/daemon.log -L warning |
115 | | }}} |
116 | | {{{ |
117 | | ExecStart=/usr/bin/deluge-web -l /var/log/deluge/web.log -L warning |
118 | | }}} |
119 | | * See [wiki:Troubleshooting#EnableDelugeLogging Deluge Logging] for all available log-levels. |
120 | | |
121 | | Restart the services: |
122 | | {{{ |
123 | | sudo systemctl daemon-reload |
124 | | sudo systemctl restart deluged |
125 | | sudo systemctl restart deluge-web |
126 | | }}} |
127 | | |
128 | | === Log Rotation === |
129 | | To enable log rotation create `/etc/logrotate.d/deluge` with the following code: |
130 | | {{{ |
131 | | /var/log/deluge/*.log { |
132 | | rotate 4 |
133 | | weekly |
134 | | missingok |
135 | | notifempty |
136 | | compress |
137 | | delaycompress |
138 | | sharedscripts |
139 | | postrotate |
140 | | systemctl restart deluged >/dev/null 2>&1 || true |
141 | | systemctl restart deluge-web >/dev/null 2>&1 || true |
142 | | endscript |
143 | | } |
144 | | }}} |
145 | | |
146 | | == Start `deluged` only if mount exists == |
147 | | Use this if you have a usb disk drive or network drive that may not be immediately available on boot or disconnected at random. |
148 | | |
149 | | The following additions wait for those mountpoints before starting `deluged`. If they are unmounted or disconnected then `deluged` is stopped. When they become available again `deluged` is started. |
150 | | |
151 | | Ensure you have added the correct drive details to `fstab` or equivalent so they are mounted at boot. |
152 | | |
153 | | List the available drive mounts: |
154 | | {{{ |
155 | | sudo systemctl -t mount |
156 | | }}} |
157 | | |
158 | | Look for your mount point in the Description column. Mounts are formatted similar to the mount point with - substituted for / in the path. Eg: `media-xyz.mount` |
159 | | |
160 | | Modify the `[Unit]` section of the `deluged.service` script. Substitute `xyz.mount` for the mount you want the service to depend on: |
161 | | {{{ |
162 | | [Unit] |
163 | | Description=Deluge Bittorrent Client Daemon |
164 | | # Start after network and specified mounts are available. |
165 | | After=network-online.target xyz.mount |
166 | | Requires=xyz.mount |
167 | | # Stops deluged if mount points disconnect |
168 | | BindsTo=xyz.mount |
169 | | }}} |
170 | | |
171 | | For multiple mount points add a space between additional entries. Eg: `After=network-online.target xyz.mount abc.mount def.mount` |
172 | | |
173 | | Modify the `[Install]` section to ensure the deluged service is started when the mount point comes back online: |
174 | | {{{ |
175 | | [Install] |
176 | | WantedBy=multi-user.target xyz.mount |
177 | | }}} |
178 | | Note: `WantedBy` seems to work on some distros and not others. Possibly different versions of systemd? |
179 | | |
180 | | Reference: [https://www.freedesktop.org/software/systemd/man/systemd.unit.html#RequiresMountsFor= systemd.unit] |
| 1 | Moved to: https://deluge.readthedocs.io/en/latest/how-to/systemd-service.html |