YunoHost-Apps / friendica_ynh

Friendica package for YunoHost
http://friendi.ca/
Other
11 stars 12 forks source link

Service friendica-daemon is auto-restart #133

Open tio-trom opened 3 months ago

tio-trom commented 3 months ago

Recently the daemon was implemented here https://github.com/YunoHost-Apps/friendica_ynh/pull/127 - but I am unsure if it really works. I had it setup before via https://nequalsonelifestyle.com/2022/08/04/setting-up-friendica-daemon-systemd-service/ tutorial but everytime I would update Friendica (before the daemon merge) it would revert back most of the Daemon changes I did manually following that tutorial.

That being said, now I have updated to the latest Friendica and all works well. No need to do any other changes. But it may not be a good measure if the Daemon works or not via that merge since I may have had some files created manually before and such.

But anyway now I see the Friendica Daemon restarting every minute. Logs here https://paste.yunohost.org/kisigucewe

PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.

The 166 line is if (!file_put_contents($pidfile, $pid)) {

Context:

// Fork a daemon process
    $pid = pcntl_fork();
    if ($pid == -1) {
        echo "Daemon couldn't be forked.\n";
        Logger::warning('Could not fork daemon');
        exit(1);
    } elseif ($pid) {
        // The parent process continues here
        if (!file_put_contents($pidfile, $pid)) {
            echo "Pid file wasn't written.\n";
            Logger::warning('Could not store pid file');
            posix_kill($pid, SIGTERM);
            exit(1);
        }
        echo 'Child process started with pid ' . $pid . ".\n";
        Logger::notice('Child process started', ['pid' => $pid]);
        exit(0);
    }
aarontrom commented 3 months ago

I have the exact same issue.

friendica-daemon.service - Friendica daemon
     Loaded: loaded (/etc/systemd/system/friendica-daemon.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Wed 2024-03-20 23:36:24 CET; 3s ago
    Process: 6917 ExecStart=/usr/bin/php8.2 /var/www/friendica/bin/daemon.php start (code=exited, status=1/FAILURE)
   Main PID: 6917 (code=exited, status=1/FAILURE)
        CPU: 223ms

Mar 20 23:37:05 tromdienste.de systemd[1]: friendica-daemon.service: Main process exited, code=exited, status=1/FAILURE
Mar 20 23:37:05 tromdienste.de systemd[1]: friendica-daemon.service: Failed with result 'exit-code'.
Mar 20 23:37:15 tromdienste.de systemd[1]: friendica-daemon.service: Scheduled restart job, restart counter is at 144.
Mar 20 23:37:15 tromdienste.de systemd[1]: Stopped Friendica daemon.
Mar 20 23:37:15 tromdienste.de systemd[1]: Started Friendica daemon.
Mar 20 23:37:15 tromdienste.de systemd[1]: friendica-daemon.service: Main process exited, code=exited, status=1/FAILURE
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
aarontrom commented 3 months ago

with

echo exec('whoami'); echo "\n";
echo $pidfile; echo "\n";

we could find out that the permissions for friendica were wrong and the user friendica could not write into /run/friendica to create that pid file. We were able to change that via "chown friendica /run/friendica/"

tio-trom commented 1 month ago

Service friendica-daemon is auto-restart

I always get this btw. Maybe we can fix it? I have to start the daemon processes manually everytime I reboot the server.

MrPetovan commented 3 weeks ago

Were you able to fix the permission issue manually?

tio-trom commented 3 weeks ago

Yes but that only changes the permissionsfor the /run/friendica folder and not the .pid file iside that folder, which is owned by root. Thus the error still persists: PHP Warning: file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166 Pid file wasn't written.

If I apply the same permissions to the .pid file too, then I get this:

Child process started with pid 3712110.
Worker daemon process 3712110 was killed.
Starting worker daemon.
Child process started with pid 3712261.
Worker daemon process 3712261 was killed.
Starting worker daemon.
Child process started with pid 3712531.
Worker daemon process 3712531 was killed.
Starting worker daemon.
Child process started with pid 3712743.
Worker daemon process 3712743 was killed.
Starting worker daemon.
Child process started with pid 3712821.
Worker daemon process 3712821 was killed.
Starting worker daemon.
Child process started with pid 3712952.
Worker daemon process 3712952 was killed.
Starting worker daemon.
Child process started with pid 3713018.
Worker daemon process 3713018 was killed.
Starting worker daemon.
Child process started with pid 3713086.
Worker daemon process 3713086 was killed.
Starting worker daemon.
Child process started with pid 3713146.
Worker daemon process 3713146 was killed.
Starting worker daemon.
Child process started with pid 3713234.
Worker daemon process 3713234 was killed.
Starting worker daemon.
Child process started with pid 3713473.
Worker daemon process 3713473 was killed.
Starting worker daemon.
Child process started with pid 3713592.
Worker daemon process 3713592 was killed.

And basically the .pid file disappeared from the /run/friendica folder and the service cannot start....

tio-trom commented 3 weeks ago

Now if I reboot the server the ownership for the run/friendica switches back to www-data. image And no .pid file will be created inside of it. The daemon process is auto-restart with these errors:

Jun 15 23:10:43 systemd[1]: friendica-daemon.service: Main process exited, code=exited, status=1/FAILURE
Jun 15 23:10:43 systemd[1]: friendica-daemon.service: Failed with result 'exit-code'.
Jun 15 23:10:53 systemd[1]: friendica-daemon.service: Scheduled restart job, restart counter is at 16.
Jun 15 23:10:53 systemd[1]: Stopped Friendica daemon.
Jun 15 23:10:53 systemd[1]: Started Friendica daemon.
Jun 15 23:10:53 systemd[1]: friendica-daemon.service: Main process exited, code=exited, status=1/FAILURE
Jun 15 23:10:53 systemd[1]: friendica-daemon.service: Failed with result 'exit-code'.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.
Starting worker daemon.
PHP Warning:  file_put_contents(/run/friendica/daemon.pid): Failed to open stream: Permission denied in /var/www/friendica/bin/daemon.php on line 166
Pid file wasn't written.

But seems like Friendica works correctly....and that makes me confused....is there a daemon working now or what?

image

I can see those processes. I am confused...

tio-trom commented 3 weeks ago

EDIT: No Friendica does not work properly without the .pid file and I have to start a daemon manually from the /var/www/friendica folder....that gets us back to the same issue of ownerships of the .pid file.