[Friendica] Worker cron job

Hello :slight_smile: I noticed that when I made a new post on my new Friendica instance, the worker in the background was very slow to run the notifier task (I assume this is to do with how it spreads messages through the various protocols to different servers on the Fediverse).
I found this was run by a cron job, and doing the below seems to have solved the issue.
I wanted to write it up here in case anyone else runs into the same issue.

# Use Yunohost's shell to travel to /var/www/friendica,
# Friendica's app directory, as `sudo cd` is disabled.
$ sudo yunohost app shell friendica

# Once the shell has loaded, `cd` into the directory,
# open the latest php and run worker.php
$ cd /var/www/friendica; /usr/bin/php  bin/worker.php

# Make a new crontab file. This is saved as a temp file
# in /tmp but is also copied to /var/spool/cron/crontabs
# and /etc/cron.d/
$ crontab -e

# Select your text editor of choice (I like nano), and then
# add at the bottom of the file:
*/10 * * * * /var/www/friendica; /usr/bin/php bin/worker.php

Then save with CTRL+O and exit with CTRL+X.
According to these instructions, this will make the worker run at most every 10 minutes.

Here is an explanation of how a crontab file is structured (what all those asterisks mean).

Before, the notifier tasks were going every 30-45 minutes. Now they go every ~5 minutes. :slight_smile:

1 Like

hi!

i implemented the deamon instead of the cron for the package: Daemon by OniriCorpe Ā· Pull Request #127 Ā· YunoHost-Apps/friendica_ynh Ā· GitHub

could you test it, once the automated tests are fine (all green!)?

1 Like

I would if I knew how :slight_smile:

I think Eolab said in their thread about the ā€œ//ā€ issue that they had to set up a manual cron job after updating to 2023.12, just like before. I had to do the same, and although Friendica mostly works as expected now (yay!), Iā€™m still having some unexpected problems with getting notifications to be sent to others when I @-mention them.

If you still want me to test things, let me know what I need to do :slight_smile:

Typically you need to

sudo yunohost app upgrade friendica -u https://github.com/YunoHost-Apps/friendica_ynh/tree/daemon

While it makes pre-upgrade backup make full backup just to make sure, especially if it would technically downgrade the version youā€™re running (dunno if thatā€™s the case).

It says Friendica is already up to date ā€“ I upgraded to the latest version earlier in the week.

Then you need to pass -F additionally to force the upgrade, even if manifest claims the same version.

It looks like the URL has changed, and now /tree/daemon is now /tree/Daemon.

I tried it with that, forced with -F, and the update went perfectly. :slight_smile:

Edit: Made a test post, and it got processed by the daemon in under 3 minutes. The worker queue still says it has processes pending, though, so Iā€™m not sure if thatā€™s intendedā€¦?
Iā€™ve turned the cron job back on for now, as it seems to work well alongside the daemon process.

Right.
I upgraded Friendica to the latest version using the ā€˜System updateā€™ feature in the Yunohost web admin panel, and now Iā€™m getting error emails saying that the Friendica service did not start.

journalctl:

Feb 22 19:53:27 systemd[1]: Started Friendica daemon.
Feb 22 19:53:28 systemd[1]: friendica.service: Succeeded.
Feb 22 19:53:28 systemd[1]: friendica.service: Scheduled restart job, restart counter is at 1.
Feb 22 19:53:28 systemd[1]: Stopped Friendica daemon.
Feb 22 19:53:28 systemd[1]: Started Friendica daemon.
Feb 22 19:53:28 systemd[1]: friendica.service: Succeeded.
Feb 22 19:53:28 systemd[1]: friendica.service: Scheduled restart job, restart counter is at 2.
Feb 22 19:53:28 systemd[1]: Stopped Friendica daemon.
Feb 22 19:53:28 systemd[1]: Started Friendica daemon.
Feb 22 19:53:28 systemd[1]: friendica.service: Succeeded.
Feb 22 19:53:29 systemd[1]: friendica.service: Scheduled restart job, restart counter is at 3.
Feb 22 19:53:29 systemd[1]: Stopped Friendica daemon.
Feb 22 19:53:29 systemd[1]: Started Friendica daemon.
Feb 22 19:53:29 systemd[1]: friendica.service: Succeeded.
Feb 22 19:53:29 systemd[1]: friendica.service: Scheduled restart job, restart counter is at 4.
Feb 22 19:53:29 systemd[1]: Stopped Friendica daemon.
Feb 22 19:53:29 systemd[1]: Started Friendica daemon.
Feb 22 19:53:29 systemd[1]: friendica.service: Succeeded.
Feb 22 19:53:30 systemd[1]: friendica.service: Scheduled restart job, restart counter is at 5.
Feb 22 19:53:30 systemd[1]: Stopped Friendica daemon.
Feb 22 19:53:30 systemd[1]: friendica.service: Start request repeated too quickly.
Feb 22 19:53:30 systemd[1]: friendica.service: Failed with result 'start-limit-hit'.
Feb 22 19:53:30 systemd[1]: Failed to start Friendica daemon.

/var/log/friendica/friendica.log:

Starting worker daemon.
Child process started with pid 1557.
Worker daemon process 1557 was killed.
Starting worker daemon.
Child process started with pid 1576.
Worker daemon process 1576 was killed.
Starting worker daemon.
Child process started with pid 1620.
Worker daemon process 1620 was killed.

The friendica-daemon service seems to be working correctly ā€“ just not the Friendica service.

but it should not be any friendica.service but only a friendica-daemon.service ughhh

on my test instance there is no friendica.service as it should be:

ls /etc/systemd/system/ | grep "friend"
friendica-daemon.service
1 Like

I still had the old cron job running in the background - donā€™t know if this had an effect? Iā€™ve now deleted it from the /var/spool/cron/crontabs folder.

1 Like

can you run this command and tell me the output?

ls /etc/systemd/system/ | grep "friend"

I get both friendica-daemon.service and friendica.service

Friendica seems to be working OK even with both in the list (edit: ā€œfriendica.serviceā€ is not running, and shouldnā€™t be!), and now that I have removed the cron manually I am no longer receiving error emails.

If thereā€™s a way just to remove friendica.service from systemd then it should all be OK.

you can do that:

systemctl stop friendica.service
systemctl disable friendica.service
rm -v /etc/systemd/system/friendica.service

i donā€™t know why you have a friendica.service and i found nothing in the package code
but since the app is working fine, i think itā€™s okay

but anyway the upgrade should have removed the old cron :confused:
where was your cron file? and what name did he have?

It was in /var/spool/cron/crontabs/ ā€“ there was a plain text file called friendica in there that I deleted with rm.
Iā€™ve also checked in /tmp and /etc/cron.d/ and there are no other cron jobs still lurking around. I think creating crontabs with crontab -e copies the file into those three locations.

I removed the friendica.service following your steps above, and although the entry is still showing in Services (in web admin), it says it has been ā€œUnknown since about 54 years agoā€ :laughing: I guess if I reboot my server, it will vanish.

Edit: It doesnā€™t vanish. -.- Perhaps updating to a newer Yunohost version will do it?

You need to instruct YunoHost to forget the service by issuing

sudo yunohost service remove friendica