Skip to content

Commit a45cfce

Browse files
committed
docs: Better systemd unit file for AI workers
The original method added complexity of a script file which requires `chmod +x`, runs sudo on each invocation (which can spam logs), and does not invoke `systemctl daemon-reload` before starting the units leading to warnings (though not fatal). This new flow uses systemd's own execution environment (including handling the user) and simplifies the dependencies. Activation is also streamlined since systemctl can handle multiple units in one command, avoiding shell `for` loops. Signed-off-by: Liam Dennehy <liam@wiemax.net>
1 parent 3e9ed80 commit a45cfce

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

admin_manual/ai/overview.rst

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -364,51 +364,55 @@ The logs of the worker can be checked by attaching to the screen or tmux session
364364
Systemd service
365365
^^^^^^^^^^^^^^^
366366

367-
1. Create a systemd service file in ``/etc/systemd/system/nextcloud-ai-worker@.service`` with the following content:
367+
This section assumes four workers are to be run simultaneously, the suggested default.
368+
369+
1. Note the location of your php executable, and create a systemd service file for the AI workers:
370+
371+
.. code-block:: console
372+
373+
$ which php
374+
/usr/bin/php
375+
$ sudo systemctl edit --full --force nextcloud-ai-worker@.service
376+
377+
Paste the following content into the editor:
368378

369379
.. code-block::
370380
371381
[Unit]
372382
Description=Nextcloud AI worker %i
373-
After=network.target
374-
383+
375384
[Service]
376-
ExecStart=/opt/nextcloud-ai-worker/taskprocessing.sh %i
385+
WorkingDirectory=/path/to/nextcloud
386+
User=www-data
387+
ExecStart=/usr/bin/php occ taskprocessing:worker -v -t 60
377388
Restart=always
378389
StartLimitInterval=60
379390
StartLimitBurst=10
380391
381392
[Install]
382393
WantedBy=multi-user.target
383394
384-
2. Create a shell script in ``/opt/nextcloud-ai-worker/taskprocessing.sh`` with the following content and make sure to make it executable:
385-
386-
.. code-block::
387-
388-
#!/bin/sh
389-
echo "Starting Nextcloud AI Worker $1"
390-
cd /path/to/nextcloud
391-
sudo -E -u www-data php occ taskprocessing:worker -v -t 60
395+
Make sure the ``ExecStart=`` line above points to your php execuatable file location
392396

393-
You may want to adjust the timeout to your needs (in seconds).
397+
You may want to adjust the timeout (``-t 60`` above) to your needs (in seconds).
394398

395-
3. Enable and start the service 4 or more times:
399+
2. Enable and start 4 instances of the service (the command can be safely re-run with a higher value if more instances are needed):
396400

397401
.. code-block::
398402
399-
for i in {1..4}; do systemctl enable --now nextcloud-ai-worker@$i.service; done
403+
systemctl enable --now nextcloud-ai-worker@{1..4}.service
400404
401-
The status of the workers can be checked with (replace 1 with the worker number):
405+
The status of the workers can be checked with:
402406

403407
.. code-block::
404408
405-
systemctl status nextcloud-ai-worker@1.service
409+
systemctl status nextcloud-ai-worker@{1..4}.service
406410
407411
The list of workers can be checked with:
408412

409413
.. code-block::
410414
411-
systemctl list-units --type=service | grep nextcloud-ai-worker
415+
systemctl list-units --type=service | grep nextcloud-ai-worker@
412416
413417
The complete logs of the workers can be checked with (replace 1 with the worker number):
414418

0 commit comments

Comments
 (0)