Evidlo / remarkable_printer

Native printing to reMarkable.
GNU General Public License v3.0
261 stars 21 forks source link

socket-activate printer #13

Closed cherti closed 7 months ago

cherti commented 3 years ago

Previous to this PR, the printer needs to continuously run in the background, even if it doesn't do much most of the time, to keep the socket open and handle incoming connections. This commit hands over handling the open socket to systemd and the printer-code gets started by systemd only when there is something incoming on the socket. The printer itself then takes over the socket from systemd, handles the incoming data and exits afterwards, returning socket management to systemd again.

This reduces running processes as well as the memory footprint of the running system. Both seems not strictly necessary, given the performance characteristics at least of the reMarkable 2, but if every single software takes the "but I'm so small"-approach, the effect cumulates, so I do see a clear benefit in everyone being a good citizen and not clogging resources that are not required for operation. After all, the remarkable has systemd, so I don't see a reason why we shoudn't leverage its features.

The disadvantage of the current code is that you are no longer able to run the code standalone. If you prefer, though, I can change that so that both socket activation as well as standalone-operation is supported. I have abstained to do so in the current state of the code to save that one conditional as well as even simplifying the code by removing one loop that we no longer need when using systemd socket activation.

cherti commented 2 years ago

Is there gonna be any activity on this PR, i.e. does it make sense to resolve the merge conflict at hand or would that go nowhere anyways?

Evidlo commented 2 years ago

Sorry I let this languish for two whole years. If you still want to implement this I can accept the PR.

Keeping standalone support is a must, though.

cherti commented 2 years ago

I can take a look if you are interested in merging this, although I don't have time right now to clear out the merge conflict. But I can put it back onto my list for when I have some more time.

Evidlo commented 9 months ago

Maybe control standalone behavior with -test

cherti commented 9 months ago

Maybe control standalone behavior with -test

That's not necessary, the printer automatically detects if it is started via socket or manually and just does the right thing™.

cherti commented 9 months ago

The code is done and works both ways now, you can test it if you want. I'm still looking if I can get it to terminate if it is on socket activation, because there is no real reason to keep the process around if it is automatically started anyways.

Evidlo commented 9 months ago

Restart=Always needs to be removed from the service so that it stays stopped after being triggered.

Also systemctl disable printer.service should be added to install.sh and the Makefile to disable the service on systems with old versions already installed.

I've tested this on my end. Other than the above, everything seems to be working. Good work!

cherti commented 9 months ago

You are absolutely right. That of course makes it difficult to have one service file as the repo currently has it. Should I migrate the service file to the socket activated flavor or do you prefer having two service files, one for perma-running and one for socket activation?

Evidlo commented 9 months ago

Just have one service file and remove the restart directive.

On January 14, 2024 8:29:49 AM CST, "Jonas Große Sundrup" @.***> wrote:

You are absolutely right. That of course makes it difficult to have one service file as the repo currently has it. Should I migrate the service file to the socket activated flavor or do you prefer having two service files, one for permanency and one for socket activation?

-- Reply to this email directly or view it on GitHub: https://github.com/Evidlo/remarkable_printer/pull/13#issuecomment-1890968432 You are receiving this because you commented.

Message ID: @.***>

cherti commented 9 months ago

Done, should be mergeable now. Do you want to keep the -debug flag in the service file or shall I remove it before merging?

cherti commented 9 months ago

I can keep the "WantedBy=" to make it enableable, but given that we removed the Restart-directive, I can also clean that up and remove the WantedBy alltogether, what do you think?

cherti commented 7 months ago

any update on this? :)

Evidlo commented 7 months ago

Thanks for the contribution! I've changed the host back to 0.0.0.0 so it can work over WiFi as well.

Only took 4.25 years!