dotnetcore/install.sh

raw link view readme
1 semanage fcontext -at httpd_sys_rw_content_t "/srv(/.*)?"
2
3 yum install firewalld -y
4 systemctl start firewalld
5 systemctl enable firewalld
6 firewall-cmd --permanent --zone=public --add-interface=eth0
7 firewall-cmd --permanent --add-service=http --add-service=https --zone=public
8 firewall-cmd --reload
9
10 # Just for nginx testing...
11
12 cat > /srv/robots.txt << EOF
13 User-agent: ia_archiver
14 Disallow: /
15 EOF
16
17 yum install epel-release -y
18 yum install supervisor -y
19
20 cat > /etc/supervisord.d/sample.ini << EOF
21 [program:sample]
22 command=/usr/bin/dotnet /srv/sample/bin/Debug/netcoreapp1.0/publish/sample.dll
23 directory=/srv/sample
24 autostart=true
25 autorestart=true
26 stderr_logfile=/var/log/sample.err.log
27 stdout_logfile=/var/log/sample.out.log
28 environment=ASPNETCORE_ENVIRONMENT=Production
29 user=nginx
30 stopsignal=INT
31 EOF
32
33 # App
34
35 yum install libunwind libicu -y
36 curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131
37 mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
38 ln -s /opt/dotnet/dotnet /usr/bin
39
40 cd /srv
41 mkdir sample
42 cd sample
43
44 cat > project.json << EOF
45 {
46 "version": "1.0.0-*",
47 "buildOptions": {
48 "debugType": "portable",
49 "emitEntryPoint": true
50 },
51 "dependencies": {},
52 "frameworks": {
53 "netcoreapp1.0": {
54 "dependencies": {
55 "Microsoft.NETCore.App": {
56 "type": "platform",
57 "version": "1.0.0"
58 },
59 "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
60 },
61 "imports": "dnxcore50"
62 }
63 }
64 }
65 EOF
66
67 cat > Startup.cs << EOF
68 using System;
69 using Microsoft.AspNetCore.Builder;
70 using Microsoft.AspNetCore.Hosting;
71 using Microsoft.AspNetCore.Http;
72 namespace sample
73 {
74 public class Startup
75 {
76 public void Configure(IApplicationBuilder app)
77 {
78 app.Run(context =>
79 {
80 return context.Response.WriteAsync("This verbose monstrosity works.");
81 });
82 }
83 }
84 }
85 EOF
86
87 cat > Program.cs << EOF
88 using System;
89 using Microsoft.AspNetCore.Hosting;
90 namespace sample
91 {
92 public class Program
93 {
94 public static void Main(string[] args)
95 {
96 var host = new WebHostBuilder()
97 .UseUrls("http://unix:/srv/sample/run.sock")
98 .UseKestrel()
99 .UseStartup()
100 .Build();
101 host.Run();
102 }
103 }
104 }
105 EOF
106
107 dotnet restore
108 dotnet publish
109
110 #Nginx
111
112 cat > /etc/yum.repos.d/nginx.repo << EOF
113 [nginx]
114 name=nginx repo
115 baseurl=http://nginx.org/packages/mainline/centos/\$releasever/\$basearch/
116 gpgcheck=0
117 enabled=1
118 EOF
119
120 yum install -y nginx
121
122 export PUBLIC_IP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
123
124 mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disabled
125 cat > /etc/nginx/conf.d/webapi.conf << EOF
126 server {
127 listen $PUBLIC_IP:80;
128
129 location /robots.txt {
130 alias /srv/robots.txt;
131 }
132
133 location / {
134 proxy_pass http://unix:/srv/sample/run.sock;
135
136 proxy_redirect off;
137 proxy_set_header Host \$host;
138 proxy_set_header X-Real-IP \$remote_addr;
139 proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
140 proxy_set_header X-Forwarded-Host \$server_name;
141 }
142 }
143 EOF
144
145 chown -R nginx:nginx /srv
146 restorecon -R -v /srv
147
148 systemctl start supervisord
149 systemctl enable supervisord
150
151 systemctl start nginx
152 systemctl enable nginx
153