linux+supervisor+.net core / tornado+nginx 开机自动启

一、supervisor是进程管理,可以让某些应用随机自动启
二、nginx是让外面的用户可以通过端口访问到服务。
三、.net core和tornado分别是.net应用和pythony应用。

在此需总结几点

1.systemctl的使用

显示系统状态

$ systemctl status

显示单个 Unit 的状态
$ sysystemctl status bluetooth.service

显示远程主机的某个 Unit 的状态
$ systemctl -H example.com status httpd.service

应用开机自动启**

systemctl enable mvc.service
systemctl start mvc.service
systemctl status mvc.service

2.supervisor应用

supervisord -c /etc/supervisor/supervisord.conf

conf.d文件夹下的文件编辑

tornado.conf文件

[group:sockets]
programs=socket-0
[program:socket-0]
command=python /home/.py --port=8xxxx
director=/home/pi/web/
user=www-data
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/tornado/socket-0.log
loglevel=info

testapi.conf(.net)

[program:testapi]
command=/usr/local/bin/dotnet /home/pi/.dll
directory=/home/pi/web
autorestart=true
autostart=true
startsecs=3
stderr_logfile=/var/log/testapi.error.log
stdout_logfile=/var/log/testasp.stdout.log
environment=Aspnetcore_environment=Production
user=root
stopsignal=INT

supervisor的用法

开启:supervisor -c /etc/supervisor/supervisord.conf
进入管理:supervisorctl
在提示符下:reload,update,shutdown
退出管理:quit
重启前用:ps -ef | grep supervisor
kill 掉有关的线程
此时重启会成功

3.nginx应用

包含配置文件
include /usr/nginx/conf/vhost/*.conf;
如果是tcp协议
在其中加入
upstream tornados{
server 192.x.x.x:8;
}
proxy_next_upstream error;
在应用的.conf设置样例 如下:

tonardo.conf

server{
listen 80;
server_name a.com;
location /static/{
alias /home/pi/web/img;
expires 24h;
}
location /{
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://tornados;(与在supervisor中所设的group同);
}
}

testapi.conf(.net)

server{
listen 8;
server_name localhost;
root /home/pi/netweb/publish;
index index.html index.htm;
location /{
proxy_pass http://localhost:5000;
}
}
当以上都设置停当后,无论是.net 或是 python的应用都可以随机启动,做到这一点看似简单,其实真的很曲折。涉及的知识点太多了。需要记下来,否则会忘记.

你可能感兴趣的:(物联网开发)