Asp. Create daemons for donet under ENT Core Linux (reprint)

Source: Internet
Author: User
Tags dot net dotnet

Objective

In the previous article, we described how to deploy our ASP. NET core application in a Docker container, this article is about how to create a daemon for the dotnet program we deploy in Linux or macOs, to ensure that our program remains in an abnormal or a computer restart can be accessed normally.

If you are going to use ASP. NET core to develop the project, the program and deployment to Linux, then this article you are worth collecting.
If you feel that it is helpful to you, you may wish to order a "recommendation".

Directory
    • What is a daemon process
    • Supervisor Introduction
    • Supervisor Installation
    • Supervisor configuration, common commands
    • Supervisor UI Management Console
What is a daemon process

In Linux or Unix operating systems, the daemon (Daemon) is a special process that runs in the background, independent of the control terminal and periodically performs some sort of task or waits for certain occurrences to be handled. Because in Linux, each system communicates with the user interface called the terminal, every process that starts from this terminal is attached to this terminal, this terminal is called the control terminal of these processes, when the control terminal is closed, the corresponding process will automatically shut down. However, the daemon can break this limit, it is out of the terminal and runs in the background, and it is out of the terminal to avoid the process of information in the process of running in any terminal and the process will not be interrupted by terminal information generated by any terminal. It starts running from the time it was executed until the entire system shuts down before exiting.

The creation daemon here refers to the host process that publishes the commands for the ASP. NET core program on Linux to dotnet xxx.dll create a daemon.

There are a lot of tools on Linux that can manage processes, and we use Supervisor to do it.
There are two reasons:
1, it is the official Microsoft document recommended, reduce the cost of learning.
2, it is not necessarily the best, but it must be the most complete document.

Supervisor Introduction

Supervisor, developed in Python (2.4+), is a client/server system that allows users to manage Unix-based system processes, providing a number of features to manage processes.

Official Document: http://supervisord.org/

Supervisor Installation

Use the tool directly in Masos brew to install:
brew install supervisor

Install in Linux using the following command:

Ubuntusudo apt-get  install Supervisorcentosyum install SUPERVISORPYTHONPIP Install Supervosoreasy_install Supervisor

After the installation is complete:

mac:~ yangxiaodong$ brew install supervisorWarning: supervisor-3.2.1 already installed
Supervisor configuration, common commands

After the installation is complete, /ect/supervisor/confg.d/ create a new profile () in the directory touch HelloWebApp.conf namedHelloWebApp.conf

Open hellowebapp.conf ( vim HelloWebApp.conf ) and write the following command:

[Program:hellowebapp]command=dotnet HelloWebApp.dll  #要执行的命令directory=/home/yxd/workspace/ publish #命令执行的目录environment=aspnetcore__environment=Production #环境变量user=www-Data  # User identity for Process execution stopsignal=Intautostart=true  #是否自动启动autorestart=true  # Whether to restart automatically startsecs=1  #自动重启间隔stderr_logfile=/var/log/  HelloWebApp.err.log #标准错误日志stdout_logfile=/var/log/hellowebapp. out. Log #标准输出日志

After configuration ( :wq save exit), you need to reload the configuration

sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisord.conf

Or you can restart Supervisor directly:

stop
sudo service supervisor start

If the error is started, you can open the /etc/log/supervisor/supervisord.log file to view the specific log.

Where the dotnet command output log files are located in the

/var/log/HelloWebApp.err.log
/var/log/HelloWebApp.out.log

In these files you can view the exception information or the running information in the program.

Open the browser, enter http://localhost:5000 The discovery can already browse.

Supervisor Common Commands

shutdown #关闭所有任务
supervisorctl stop|start program_name
supervisorctl status #查看所有任务状态
Supervisor UI Management Console

Supervisor default gives us a graphical interface for managing processes and tasks that are configured by default in MacOS, but we need to open them manually in Linux.

Open in /etc/supervisor/supervisord.conf file, add inet_http_server node

You can then view the running process through the interface:

Test it.

Finally, we test whether it will automatically restart, boot automatically run?

1, process management to kill dot net, the discovery can be restarted. The following are the logs:

 .- -- the  A: -: -,626INFO spawned:'Hellowebapp'With PID1774 .- -- the  A: -: +,766INFO Success:hellowebapp entered RUNNING state, process have stayed up for> Than1seconds (startsecs) .- -- the  A: -: +,208INFO Exited:hellowebapp (Exit status0; expected) .- -- the  A: -: -,223INFO spawned:'Hellowebapp'With PID3687 .- -- the  A: -: $,243INFO Success:hellowebapp entered RUNNING state, process have stayed up for> Than1Seconds (Startsecs)

2. Restart the machine and find that it can run automatically.

 

Asp. Create daemons for donet under ENT Core Linux (reprint)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.