If the EC2 startup time is set during business hours, it is troublesome to hit the command every morning, so This time, the API (Flask) made with python is used to automatically start the shell. It is a summary so as not to forget the method of the reference site.
I didn't have enough privileges so sudo
# sudo vim /usr/local/start_api.sh
----------------------------------
#!/bin/bash
nohup python3 /usr/local/api.py &
exit 0
Again, I didn't have enough privileges, so I sudoed it.
# sudo vim /etc/init.d/api_start
-------------------------------
#!/bin/sh
# chkconfig: 345 99 10
# description: start_api shell
case "$1" in
start)
bash /usr/local/start_api.sh
;;
stop)
/usr/bin/kill python
echo "stop!"
;;
*) break ;;
esac
Again sudo
$ cd /etc/init.d
$ sudo chmod 775 api_start
$ chkconfig --add api_start
##Turn on auto-start
$ chkconfig app_start on
##Check if it is set
$ chkconfig --list app_start
api_start 0:off 1:off 2:on 3:on 4:on 5:on 6:off
This is the end.
By the way, in the case of the command prompt of win10, the color of the file changes. (White → green)
Reboot the instance, make sure it's started, and you're done.
https://hit.hateblo.jp/entry/aws/ec/initd https://dev.classmethod.jp/articles/ec2shell/
Recommended Posts