1、/etc/systemd/system/?目錄下創建service文件
如:/etc/systemd/system/testDemoSer.service
2、文件內容示例:
[Unit]
Description=testDemoSer running on CentOS
[Service]
WorkingDirectory=/usr/project/iis
Type=simple
User=root
Group=root
ExecStart=dotnet /usr/project/iis/xxxx.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
SyslogIdentifier=dotnet-example
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
3、?保存文件并啟用服務
systemctl enable testDemoSer.service
4、啟用服務
systemctl start testDemoSer.service
5、查看運行狀態
systemctl status testDemoSer.service
6、systemctl
Systemctl是一個systemd工具,主要負責控制systemd系統和服務管理器。
Systemd是一個系統管理守護進程、工具和庫的集合,用于取代System V初始進程。Systemd的功能是用于集中管理和配置類UNIX系統。
6.1查看是否安裝
systemctl --version
6.2查看安裝目錄
whereis systemd
whereis systemctl
6.3檢測是否運行
ps -eaf | grep [s]ystemd
6.4?分析systemd啟動進程
systemd-analyze
6.5分析啟動時各個進程花費時間
systemd-analyze blame