- Effective DevOps with AWS
- Yogesh Raheja Giuseppe Borgese Nathaniel Felsen
- 303字
- 2021-07-23 16:27:30
Turning our simple code into a service using upstart
Since we started the node application manually in the Terminal, closing the SSH connection or hitting Ctrl + C on the keyboard will stop the node process, and therefore our Hello World application will not work anymore. Amazon Linux, unlike a standard Red Hat-based distribution, comes with a system called upstart.
This is fairly easy to use and provides a couple of extra features that traditional System-V bootup scripts don't have, such as the ability to respawn a process that died unexpectedly. To add an upstart configuration, you need to create a file inside /etc/init on the EC2 instance.
Here is the code to insert it in /etc/init/helloworld.conf:
description "Hello world Daemon"
# Start when the system is ready to do networking. Start on started elastic-network-interfaces
# Stop when the system is on its way down. Stop on shutdown
respawn script
exec su --session-command="/usr/bin/node /home/ec2-user/helloworld.js" ec2-user
end script
[ec2-user@ip-172-31-22-52 ~]$
sudo wget https://raw.githubusercontent.com/yogeshraheja/Effective-DevOps-with-AWS/master/Chapter02/helloworld.conf -O /etc/init/helloworld.conf
--2018-08-19 13:09:39-- https://raw.githubusercontent.com/yogeshraheja/Effective-DevOps-with-AWS/master/Chapter02/helloworld.conf
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.200.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.200.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 301 [text/plain]
Saving to: ‘/etc/init/helloworld.conf’
/etc/init/helloworld.conf 100%[=====================================================================================>] 301 --.-KB/s in 0s
2018-08-19 13:09:39 (54.0 MB/s) - ‘/etc/init/helloworld.conf’ saved [301/301]
[ec2-user@ip-172-31-22-52 ~]$
We can now simply start our application, as follows:
[ec2-user@ip-172-31-22-52 ~]$ sudo start helloworld
helloworld start/running, process 2872
[ec2-user@ip-172-31-22-52 ~]$
As expected, http://your-public-dns-name:3000 still works, and this time we can safely close our SSH connection.
- 工業(yè)機(jī)器人虛擬仿真實(shí)例教程:KUKA.Sim Pro(全彩版)
- 大學(xué)計(jì)算機(jī)基礎(chǔ):基礎(chǔ)理論篇
- 控制與決策系統(tǒng)仿真
- Learning Apache Spark 2
- Learning Apache Cassandra(Second Edition)
- Windows XP中文版應(yīng)用基礎(chǔ)
- Expert AWS Development
- 西門子S7-200 SMART PLC實(shí)例指導(dǎo)學(xué)與用
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)
- Pig Design Patterns
- Visual C++編程全能詞典
- Mastering Ceph
- WOW!Photoshop CS6完全自學(xué)寶典
- 電氣控制及Micro800 PLC程序設(shè)計(jì)
- 軟件質(zhì)量管理實(shí)踐