mirror of
https://github.com/Evidlo/remarkable_printer.git
synced 2024-10-20 03:27:37 -04:00
socket-activate printer
Previous to this commit, 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.
This commit is contained in:
parent
1e2627c837
commit
d1fe37662a
7
Makefile
7
Makefile
|
@ -24,14 +24,15 @@ install: printer.arm
|
||||||
ssh -o AddKeysToAgent=yes root@$(host) systemctl stop printer || true
|
ssh -o AddKeysToAgent=yes root@$(host) systemctl stop printer || true
|
||||||
scp printer.arm root@$(host):
|
scp printer.arm root@$(host):
|
||||||
scp printer.service root@$(host):/etc/systemd/system
|
scp printer.service root@$(host):/etc/systemd/system
|
||||||
|
scp printer.socket root@$(host):/etc/systemd/system
|
||||||
ssh root@$(host) systemctl daemon-reload
|
ssh root@$(host) systemctl daemon-reload
|
||||||
ssh root@$(host) systemctl enable printer
|
ssh root@$(host) systemctl enable printer.socket
|
||||||
ssh root@$(host) systemctl restart printer
|
ssh root@$(host) systemctl restart printer.socket
|
||||||
|
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
release: printer.arm printer.x86
|
release: printer.arm printer.x86
|
||||||
rm -f release.zip
|
rm -f release.zip
|
||||||
zip release.zip printer.arm printer.x86 printer.service -r
|
zip release.zip printer.arm printer.x86 printer.service printer.socket -r
|
||||||
|
|
||||||
.PHONY: install_config
|
.PHONY: install_config
|
||||||
install_config:
|
install_config:
|
||||||
|
|
|
@ -3,6 +3,7 @@ cd /home/root/bin
|
||||||
wget -O release.zip http://github.com/evidlo/remarkable_printer/releases/latest/download/release.zip
|
wget -O release.zip http://github.com/evidlo/remarkable_printer/releases/latest/download/release.zip
|
||||||
unzip -o release.zip
|
unzip -o release.zip
|
||||||
mv printer.service /etc/systemd/system
|
mv printer.service /etc/systemd/system
|
||||||
|
mv printer.socket /etc/systemd/system
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable --now printer.service
|
systemctl enable --now printer.socket
|
||||||
rm printer.x86 release.zip
|
rm printer.x86 release.zip
|
||||||
|
|
6
main.go
6
main.go
|
@ -60,13 +60,13 @@ func main() {
|
||||||
// ----- Listen for connections -----
|
// ----- Listen for connections -----
|
||||||
|
|
||||||
// Listen for incoming connections.
|
// Listen for incoming connections.
|
||||||
l, err := net.Listen("tcp", *CONN_HOST + ":" + *CONN_PORT)
|
l, err := net.FileListener(os.NewFile(3, "systemd-socket"))
|
||||||
check(err)
|
check(err)
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
// Close the listener when the application closes.
|
// Close the listener when the application closes.
|
||||||
fmt.Println("Listening on " + *CONN_HOST + ":" + *CONN_PORT)
|
fmt.Println("Listening on " + *CONN_HOST + ":" + *CONN_PORT)
|
||||||
for {
|
|
||||||
// Listen for an incoming connection.
|
// Listen for an incoming connection.
|
||||||
conn, err := l.Accept()
|
conn, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -84,8 +84,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func debug(msg ...string) {
|
func debug(msg ...string) {
|
||||||
if LOG_LEVEL == "debug" {
|
if LOG_LEVEL == "debug" {
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Native printing to reMarkable
|
Description=Native printing to reMarkable
|
||||||
|
Requires=printer.socket
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/home/root/printer.arm -restart -debug
|
ExecStart=/home/root/printer.arm -restart -debug
|
||||||
Restart=always
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
9
printer.socket
Normal file
9
printer.socket
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Socket for native printing to reMarkable
|
||||||
|
After=multi-user.target
|
||||||
|
|
||||||
|
[Socket]
|
||||||
|
ListenStream=10.11.99.1:9100
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
Reference in a new issue