Gracefull shutdown doesn't work for processes started from user data script on ec2

0

Steps to reproduce

  1. I started an EC2 instance with a user data script.
  2. This script initiates my application.
  3. A graceful shutdown is implemented in the application (an HTTP request is sent upon receiving SIGTERM).
  4. I stop/reboot/terminate the EC2 instance. Expected: The application receives a SIGTERM signal and makes a request. Actual: The application does not receive any SIGTERM signal.

It seems like processes started from the user data script do not receive a SIGTERM signal on system shutdown.

What I've tried:

  1. Starting the process in the foreground (python3 /app.py).
  2. Starting the process in the background (python3 /app.py &).
  3. Starting the process in the background with nohup (nohup python3 /app.py > /dev/null 2>&1 &). None of these methods work.

What worked:

  1. Starting the process in the background via SSH (ssh <ec2 instance> 'nohup python3 /app.py > /dev/null 2>&1 &').
질문됨 10달 전199회 조회
1개 답변
0

I think you will need to have your application running in a daemon mode.. Then you will need to place a K Script in the RC3.d folder so that when the instance recieves a SIGHUP, it can stop the application

OR/AND

I would have S script in RC3.d to start your application too on boot up which executes your 'nohup python3 /app.py > /dev/null 2>&1 &'

profile picture
전문가
답변함 10달 전
profile picture
전문가
검토됨 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠