[For 1.8] Enable Systemd Timers to Handle MyBB Task System
#1
Create the following two files in your /etc/systemd/system/ directory:

/etc/systemd/system/mybb.service
[Unit]
Description=MyBB Tasks

[Service]
User=www-data
ExecStart=/usr/bin/php /var/www/mybb/task.php

/etc/systemd/system/mybb.timer
[Unit]
Description=Runs MyBB tasks every minute

[Timer]
OnBootSec=5min
OnUnitActiveSec=1min
Unit=mybb.service

[Install]
WantedBy=multi-user.target

Now, run the following commands in your terminal:
systemctl daemon-reload
systemctl enable mybb.timer
systemctl start mybb.timer
Reply
#2
I am not familiar with systemd tasks, I want to know will it not require any admin authentication to run tasks ?
Reply
#3
No authentication needed at all, the /task.php file is executed as the system user you specify in the mybb.service file (User=www-data).
Reply
#4
don't forget to remove this from the footer template or adjust the comment so it comments out {$task_image} as well:

<!-- The following piece of code allows MyBB to run scheduled tasks. DO NOT REMOVE -->{$task_image}<!-- End task image code -->
Reply
#5
This is working well. thanks, kawaii!
Reply
#6
Nicely done, should probably explain why this may be preferred over MyBB's Crons Toungue
Plugin Count: I lost count.
Public Plugins are available here.
Official GitHub.
Please do not PM me for support unless asked to.
Reply
#7
Bumping this to say that I finally got around to doing this and I should've done it long ago.

@kawaii is the best! Smile
[retired]
Reply
#8
We could use

php7.3 instead of PHP?
For those who have php7.3 running?
[Unit]
Description=MyBB Tasks

[Service]
User=www-data
ExecStart=/usr/bin/php7.3 /var/www/mybb/task.php
Reply
#9
Hi, nice tutorial.

Any insight into what the code would be for running multiple MyBB instances in a single server? I suppose only the first file would need modification.
Reply
#10
(2021-07-22, 12:30 AM)Omar G. Wrote: Hi, nice tutorial.

Any insight into what the code would be for running multiple MyBB instances in a single server? I suppose only the first file would need modification.

We can simply add Type=oneshot to the [Service] section of the mybb.service file, and then specify multiple ExecStart like this;
[Unit]
Description=MyBB Tasks

[Service]
Type=oneshot
User=www-data
ExecStart=/usr/bin/php /var/www/mybb/task.php
ExecStart=/usr/bin/php /var/www/another_forum/task.php
ExecStart=/usr/bin/php /var/www/secret_mybb/task.php

I didn't test this though, it may be better to specify many different service/timer files instead of my idea here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)