搬运之前的笔记,记不清具体细节,实际遇到了再完善吧

安装

sudo apt-get update
sudo apt-get install systemd

创建服务

sudo vim /etc/systemd/system/test.service

WebApi

安装donet6
sudo apt-get update 
sudo apt upgrade
sudo apt-get install -y dotnet-sdk-6.0
创建服务
sudo vim /etc/systemd/system/webapi.service
[Service]
WorkingDirectory=/home/tim/webapi
ExecStart=/usr/bin/dotnet /home/tim/webapi/WebApplication1.dll
#自动重启当前服务间隔秒
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=webapi-service
User=tim

[Install]
WantedBy=multi-user.target
#该服务所在的Target

CS1.6服务器

sudo vim /etc/systemd/system/cs.service
[Unit]
Description=cs 1.6 server

[Service]
Type=simple
User=tim
WorkingDirectory=/data/amuse/steam/cs16
ExecStart=/usr/bin/bash hlds_run -game cstrike +port 27015 +map de_dust2 +maxplayers 16
Restart=always

[Install]
WantedBy=multi-user.target

基本操作

开机启动

sudo systemctl enable test.service

sudo systemctl disable test.service

启动

sudo systemctl start test.service

关闭

sudo systemctl stop test.service

??

作用没弄清

sudo systemctl daemon-reload

状态

sudo systemctl status test.service

日志

查看日志

journalctl -fu test.service

日志大小

journalctl --disk-usage

日志管理

配置路径 /etc/systemd/journald.conf

SystemMaxUse

指定日志在持久性存储中可使用的最大磁盘空间

SystemMaxUse=500M

SystemKeepFree

指定在将日志条目添加到持久性存储时,日志应留出的空间量

SystemKeepFree=100M

SystemMaxFileSize

控制单个日志文件在被轮换之前在持久性存储中可以增长到多大

SystemMaxFileSize=100M

RuntimeMaxUse

指定在易失性存储中可以使用的最大磁盘空间(在 /run 文件系统内)

RuntimeMaxUse=100M

RuntimeKeepFree

指定将数据写入易失性存储(在 /run 文件系统内)时为其他用途预留的空间数量

RuntimeMaxUse=100M

RuntimeMaxFileSize

指定单个日志文件在被轮换之前在易失性存储(在 /run 文件系统内)所能占用的空间量

RuntimeMaxFileSize=200M

重启日志

日志配置修改后需要重启

sudo systemctl restart systemd-journald