내 스크립트(소켓)를 실행하기 위해 init-script를 데몬으로 사용합니다.
#!/bin/bash
### BEGIN INIT INFO
# Provides: sock_serv
# Required-Start: $local_fs $syslog $remote_fs
# Required-Stop: $local_fs $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: sock_servservice
# Description: Run sock_serv service
### END INIT INFO
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting sock_serv..."
if sudo -u root bash -c 'cd ~/mypath/ && python3 sock_serv.py &> /dev/null &' ; then
echo "OK"
else
echo "Error: can't start "
fi
;;
stop)
echo "Stopping sock_serv..."
if sudo -u root bash -c 'cd ~/mypath/ && python3 stop_sock_serv.py &>/dev/null &'; then
# sleep 2
echo "OK"
else
echo "Error: can't stop "
fi
;;
*)
echo "Usage: /etc/init.d/sock_serv {start|stop}"
exit 1
;;
esac
저는 다른 클라이언트로부터 메시지를 받기 위해 sock_serv
모듈의 루프를 사용하고 있습니다 .Select
내 것을 실행할 수 있지만 sock_serv
몇 시간 후에 sock_serv
는 모든 포트를 수신합니다(중지).
bevor를 실행 service sock_serv status
하고 sock_serv가 중지된 후 다음을 얻습니다.
sock_serv.service - LSB: sock_serv service
Loaded: loaded (/etc/init.d/sock_serv; generated)
Active: active (exited) since Sat 2019-10-12 16:06:56 CEST; 23h ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 2301)
Memory: 0B
CGroup: /system.slice/sock_serv.service
Oct 12 18:08:10 sam sudo[1042]: pam_unix(sudo:session): session closed for user root
Oct 12 18:08:10 sam sudo[1045]: root : TTY=unknown ; PWD=/root/mypath; USER=root ; COMMAND=/root/mypath/otherScript.py
Oct 12 18:08:10 sam sudo[1045]: pam_unix(sudo:session): session opened for user root by (uid=0)
Oct 12 18:08:10 sam sudo[1045]: pam_unix(sudo:session): session closed for user root
나는 sock_serv가 계속 실행되기를 원합니다. 감사해요