Supervisorをインストールしてdotnetを動かす
■ 環境
- Ubuntu20.04(vagrant+virtualBox)
- dotnet version3.1
- すでにnginxでhttpsリバースプロキシを構築し.Net Coreアプリを動かすでnginxでリバースプロキシが構築されていること。
There’s an tool called Supervisor that is good at that so I’ll add it.
WebサーバーSupervisorをインストール
$ sudo apt-get install supervisor
DotnetアプリをRelease Buildする
$ sudo mkdir -p /var/aspnetcore $ cd ~/hellomvc $ sudo dotnet publish --configuration Release Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core Copyright (C) Microsoft Corporation. All rights reserved. Determining projects to restore... Restored /home/vagrant/data/hellomvc/hellomvc.csproj (in 2.47 sec). hellomvc -> /home/vagrant/data/hellomvc/bin/Release/netcoreapp3.1/hellomvc.dll hellomvc -> /home/vagrant/data/hellomvc/bin/Release/netcoreapp3.1/publish/
アプリケーションの公開ディレクトリへコピーする
$ sudo cp -R ./bin/Release/netcoreapp3.1/publish/* /var/aspnetcore/ $ ls /var/aspnetcore/ appsettings.Development.json appsettings.json hellomvc hellomvc.deps.json hellomvc.dll hellomvc.pdb hellomvc.runtimeconfig.json web.config
SupervisorのConfigファイルを生成する(/etc/supervisor/conf.d/hellomvc.conf)
$ sudo vim /etc/supervisor/conf.d/hellomvc.conf [program:dotnettest] command=/usr/bin/dotnet /var/aspnetcore/hellomvc.dll --urls "http://*:5000" directory=/var/aspnetcore/ autostart=true autorestart=true stderr_logfile=/var/log/hellomvc.err.log stdout_logfile=/var/log/hellomvc.out.log environment=ASPNETCORE_ENVIRONMENT=Production user=www-data stopsignal=INT※dotnetコマンドをたたいて、公開ディレクトリのdllと、5000ポートを指定していますね。
いよいよ、supervisor起動
$ sudo service supervisor stop $ sudo service supervisor start $ sudo tail -f /var/log/supervisor/supervisord.log 2020-06-06 09:06:46,625 INFO RPC interface 'supervisor' initialized 2020-06-06 09:06:46,627 CRIT Server 'unix_http_server' running without any HTTP authentication checking 2020-06-06 09:06:46,627 INFO supervisord started with pid 7391 2020-06-06 11:49:16,948 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message. 2020-06-06 11:49:16,948 INFO Included extra file "/etc/supervisor/conf.d/hellomvc.conf" during parsing 2020-06-06 11:49:16,951 INFO RPC interface 'supervisor' initialized 2020-06-06 11:49:16,951 CRIT Server 'unix_http_server' running without any HTTP authentication checking 2020-06-06 11:49:16,952 INFO supervisord started with pid 8276 2020-06-06 11:49:17,954 INFO spawned: 'dotnettest' with pid 8292 2020-06-06 11:49:19,179 INFO success: dotnettest entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
https://192.168.33.10:10443/ にアクセスすると、無事"Hello World!"が表示された!!
参考:
コメント
コメントを投稿