keep server running on EC2 instance after ssh is terminated

前端 未结 5 1806
忘了有多久
忘了有多久 2020-12-23 12:09

Currently, I have two servers running on an EC2 instance (MongoDB and bottlepy). Everything works when I SSHed to the instance and sta

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 12:39

    It would be nice if you provided more info about your environment but assuming it's Ubuntu Linux you can start the services in the background or as daemons.

    sudo service mongodb start
    nohup python yourbottlepyapp.py &
    

    (Use nohup if you want are in a ssh session and want to prevent it from closing file descriptors)

    You can also run your bottle.py app using Apache mod_wsgi. (Running under the apache service) More info here: http://bottlepy.org/docs/dev/deployment.html

    Hope this helps.

    Addition: (your process still runs after you exit the ssh session)

    Take this example time.py

     import time
     time.sleep(3600)
    

    Then run:

     $ python3 time.py &
     [1] 3027
     $ ps -Af | grep -v grep | grep  time.py
     ubuntu    3027  2986  0 18:50 pts/3    00:00:00 python3 time.py
     $ exit
    

    Then ssh back to the server

     $ ps -Af | grep -v grep | grep  time.py
     ubuntu    3027     1  0 18:50 ?        00:00:00 python3 time.py
    

    Process still running (notice with no tty)

提交回复
热议问题