所以在我拿起斧头摧毁我的桌面之前,我会试着在这里问:-)
我有一个名为commander.service 的套接字激活服务。由于简单,我只想将裸字符串或字符推送到此服务。
所以我有一个commander.socket文件:
[Socket]
ListenFIFO=/run/commander.sk
[Install]
WantedBy=sockets.target
Run Code Online (Sandbox Code Playgroud)
然后我有一个commander.service文件:
[Unit]
Description=A service reading commands from the given socket
[Service]
ExecStart=/usr/bin/perl /root/commander.pl
StandardInput=socket
User=root
Group=root
Restart=no
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
现在我希望我在那里运行的脚本通过标准输入接收这些字符串或字符。
脚本的代码是:
#!/usr/bin/env perl
my $in = *STDIN;
my $out = *STDOUT;
$out->print("My printing reaches the outside world\n");
while($_ = <$in>) {
$out->print("Received: ");
$out->print($_);
$out->print("\n");
if($_ == "1") {
$out->print("I should run the command associated with 1 ;-) \n");
} elsif($_ == "2") {
$out->print("I should run the command associated with 2 …Run Code Online (Sandbox Code Playgroud)