从命令行运行脚本while循环工作正常.但是当systemd运行它时,当netcat超时时它会立即退出,所以它再也没有机会再试一次.
有没有办法让systemd在退出脚本时不那么积极?
systemd输出,永远不会到“睡觉netcat”
Jul 23 22:26:21 core-01 systemd[1]: Starting Push journal logs to logentrIEs.com...Jul 23 22:26:21 core-01 systemd[1]: Started Push journal logs to logentrIEs.com.Jul 23 22:26:21 core-01 bash[880]: trying netcatJul 23 22:26:31 core-01 bash[880]: Ncat: Connection timed out.
journal2logentrIEs.sh
#!/usr/bin/env bashtoken=logentrIEstokenwhile truedo echo 'trying netcat' journalctl -o short -f | awk -v token=$token '{ print token,[Unit] Description=Push journal logs to logentrIEs.com After=systemd-journald.serviceAfter=systemd-networkd.service[Service]Restart=alwaysExecStart=/bin/bash /home/core/journal2logentrIEs.sh[Install]WantedBy=multi-user.target; fflush(); }' | ncat --ssl --ssl-verify data.logentrIEs.com 20000 echo 'sleePing netcat' sleep 30sdone
logentrIEs.service
logentrIEs.service - Push journal logs to logentrIEs.com Loaded: loaded (/etc/systemd/system/logentrIEs.service; Disabled) Active: active (running) since Mon 2014-07-28 17:12:04 UTC; 1min 48s ago Main PID: 16305 (sh) CGroup: /system.slice/logentrIEs.service ├─16305 /bin/sh -c journalctl -o short -f | awk -v token=token_here '{ print token,[Unit]Description=Push journal logs to logentrIEs.comAfter=systemd-journald.serviceAfter=systemd-networkd.service[Service]Restart=alwaysRestartSec=30sExecStart=/bin/bash -c "ncat --ssl --ssl-verify data.logentrIEs.com 20000 < <(awk -v token=token_here '{ print token,; fflush(); }' < <(journalctl -o short -f))"[Install]WantedBy=multi-user.target; fflush(); }' | ncat --ssl --ssl-verify -vv ogentrIEs.com 20000 ├─16306 journalctl -o short -f └─16307 awk -v token=80b4b3b6-1315-4b76-ac69-f530c1dec47f { print token,; fflush(); }Jul 28 17:12:04 ip-172-31-19-155.us-west-2.compute.internal systemd[1]: logentrIEs.service holdoff time over,scheduling restart.Jul 28 17:12:04 ip-172-31-19-155.us-west-2.compute.internal systemd[1]: StopPing Push journal logs to logentrIEs.com...Jul 28 17:12:04 ip-172-31-19-155.us-west-2.compute.internal systemd[1]: Starting Push journal logs to logentrIEs.com...Jul 28 17:12:04 ip-172-31-19-155.us-west-2.compute.internal systemd[1]: Started Push journal logs to logentrIEs.com.Jul 28 17:12:04 ip-172-31-19-155.us-west-2.compute.internal sh[16305]: Ncat: Version 6.40 ( http://nmap.org/ncat )Jul 28 17:12:04 ip-172-31-19-155.us-west-2.compute.internal sh[16305]: Ncat: Could not resolve hostname "ogentrIEs.com": name or service not kNown. QUITTING.
更新:
似乎真正的问题是,当netcat死掉系统时,/ bin / sh进程仍在运行.注意:url故意不正确测试
解决方法 从管道切换到处理替换.http://paraf.in/abs-guide/process-sub.html
https://stackoverflow.com/a/18360260/136408
这是我提出的单元文件:
logentrIEs.service
总结以上是内存溢出为你收集整理的linux – Systemd退出bash脚本,执行导致失败的命令,而不是继续全部内容,希望文章能够帮你解决linux – Systemd退出bash脚本,执行导致失败的命令,而不是继续所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)