in reply to Systemd socket activated service in perl
Check out Systemd::Daemon.
However since I am familiar with xinetd and not systemd, I did your server in xinetd instead.
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11157093 use warnings; $| = 1; # NOTE # slightly reformatted from your code - $sock not needed while( my $cmd = <> ) { if( $cmd =~ m/^sleep (\d+)/ ) { my $snooze_time = $1; printf "Will sleep for $snooze_time seconds\n"; sleep $snooze_time; print "... ZZZ ... Yawn ... What next oh master?\n"; } # NB: In real life there are lots of other commands and many take some + time to process. else { print "I did not understand that. What next oh master?\n"; } } __END__ # # unlisted service # (goes in /etc/xinetd.d) NOTE change user, server, and only_from # if this file changed, use 'systemctl reload xinetd' so prev still ru +n # using 'restart' will kill running servers, 'reload' will not # service unlisted-pm11157093 { type = UNLISTED socket_type = stream protocol = tcp wait = no user = rick log_type = FILE /dev/null server = /home/rick/code/pm11157093.pl port = 1234 disable = no only_from = 127.0.0.1 192.168.1.0/24 }
Note that xinetd does listening and forking for you, runs your child with the data socket connected to STDIN and STDOUT,
and even has an 'only_from' parameter to verify remote machines.
Leaves very little to do in your server :)
UPDATE: corrected spelling of 'xinitd' to 'xinetd'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Systemd socket activated service in perl
by tybalt89 (Monsignor) on Jan 20, 2024 at 12:30 UTC | |
Re^2: Systemd socket activated service in perl
by hippo (Archbishop) on Jan 19, 2024 at 23:07 UTC | |
Re^2: Systemd socket activated service in perl
by chrestomanci (Priest) on Jan 20, 2024 at 11:20 UTC | |
by tybalt89 (Monsignor) on Jan 20, 2024 at 12:14 UTC | |
by chrestomanci (Priest) on Jan 20, 2024 at 20:56 UTC | |
by tybalt89 (Monsignor) on Jan 20, 2024 at 21:21 UTC |