我需要运行一个脚本,在运行socat的许多事情中。从命令行运行脚本很好,现在我想要的是这个脚本作为一个服务运行。
这是我的剧本:
#!/usr/bin/env sh
set -e
TTY=${AQM_TTY:-/dev/ttyUSB0}
/reg_sesion/create
DESTINOS=(http://127.0.0.1)
LOG_DIR=./logs-aqm
mkdir -p "${LOG_DIR}"
###ADDED####
echo $$ > /var/run/colector.pid
socat -b 115200 ${TTY},echo=0,crnl - |
grep --line-buffered "^rs" |
while read post; do
for destino in ${DESTINOS[@]}; do
wget --post-data="$(echo "${post}" | tr -d "\n")" \
-O /dev/null \
--no-verbose \
--background \
--append-output="${LOG_DIR}/${destino//\/}.log" \
"${destino}/reg_sesion/create"
done
echo "${post}" | tee -a "${LOG_DIR}/aqm.log"
done以及服务文件:
[Unit]
Description=colector
[Service]
Type=simple
PIDFile=/var/run/colector.pid
User=root
Group=root
#ExecStart=/root/socat.sh
ExecStart=/bin/sh -c '/root/socat.sh'
[Install]
WantedBy=multi-user.target 当我启动服务时,流程会很快启动和结束。
有什么想法吗?
耽误您时间,实在对不起
发布于 2014-09-29 02:56:25
从服务文件中删除PIDFile=,并查看它是否有效。
PIDFile=主要用于Type=forking,您的启动程序将分叉一个子进程,因此您告诉SYSTEMD (通过PIDFile)监视该进程。对于Type=simple,使用长期运行的服务,SYSTEMD将创建一个子进程来启动您的服务,因此它确切地知道PID是什么。
https://stackoverflow.com/questions/23255631
复制相似问题