guysoft / OctoPi

Scripts to build OctoPi, a Raspberry PI distro for controlling 3D printers over the web
GNU General Public License v3.0
2.48k stars 367 forks source link

Set systemd Type to simple instead of forking #764

Closed fliphess closed 2 years ago

fliphess commented 2 years ago

Hello :)

I've seen several issues related to webcamd restarting very frequently and ran in the same issue:

The unit webcamd.service completed and consumed the indicated resources.
Feb 08 20:34:56 octopi systemd[1]: webcamd.service: Scheduled restart job, restart counter is at 5.

This mention in the community fixed it for me and as I didn't see it in this branch yet, a PR to change this behaviour.

Hope you are willing to merge this.

Thanks a lot for maintaining this repository :) Keep up the good work!

cp2004 commented 2 years ago

Is this still required with the changes that were made in #741?

Have you tested a recent nightly build to see if you still have a restarting issue?

fliphess commented 2 years ago

hey @cp2004,

Thanks for your reply!

Is this still required with the changes that were made in #741? Have you tested a recent nightly build to see if you still have a restarting issue?

I'm not using the latest version, it's a bullseye nightly build from november so it's from after #741 , but I can test it tomorrow with the most recent ones to verify if you want

guysoft commented 2 years ago

It would help if you can test and confirm. It looks though like its a good idea in general.

fliphess commented 2 years ago

I'm printing atm and my job is about to be ongoing for a few hours but right after that I'll give it a try with the latest nightly build to verify.

To be continued :)

cp2004 commented 2 years ago

hey @cp2004,

Thanks for your reply!

Is this still required with the changes that were made in #741? Have you tested a recent nightly build to see if you still have a restarting issue?

I'm not using the latest version, it's a bullseye nightly build from november so it's from after #741 , but I can test it tomorrow with the most recent ones to verify if you want

The way I read #741 / #740 was that it was fixing a regular restarting issue, so it is interesting to see that doesn't work.

fliphess commented 2 years ago

The way I read #741 / #740 was that it was fixing a regular restarting issue, so it is interesting to see that doesn't work.

@cp2004: Looking at the commits in #741 those are changes to fix restarts caused by issues at daemon level (IE the webcamd script itself to fix crashes of mjpg_streamer)... The change I suggest is not: It's on another level to fix a restart that is caused by systemd after a certain time if the script did not fork (I think its 1 minute by default).

When I run:

LD_LIBRARY_PATH=/opt/mjpg-streamer /opt/mjpg-streamer/mjpg_streamer

... And when I run /root/bin/webcamd itself, the script runs in the foreground because the --background or -b argument is not used when starting mjpg_streamer.

We could leave it at forking, but in that case we should start mjpg_streamer with the --background argument to make sure it forks as expected by systemd.

(Although personally I think setting it so Simple is an easier change as forking daemons are not so common anymore since sysv-init has been replaced by systemd)

btw: I've tested with the latest nightly and I still see the same behaviour: My camera runs for around a minute until the streams stops shortly and if I refresh my page it's working again (iow: the restart by systemd completed and it keeps running for the next minute)

guysoft commented 2 years ago

Hey, @foosel tested, merging this