linux常用命令: systemctl

linux系统结构/lib/systemd/system​目录

根据 Linux 惯例,字母d​是守护进程(daemon)的缩写。 Systemd 这个名字的含义,就是它要守护整个系统。

该目录自动存放启动文件的配置位置,里面一般包含有XXXXX.service

可以新建自定义服务,存放路径:/etc/systemd/system

命令使用:

systemctl enable xxx.service #加入开机自启动
systemctl disable xxx.service #移除开机自启动
systemctl start xxx.service #启动
systemctl daemon-reload #修改了文件后重新加载
systemctl status xxx.service #查看服务状态

如果需要自己创建unit​文件(​XXXXX.service​),参考以下内容

必需内容:

[Unit]
Description=xxxxxxx Service
After=network.target

[Service]
Type=simple
ExecStart=/home/user/install/xxxxxxx -c /home/user/install/config.yml

[Install]
WantedBy=multi-user.target

其他:

[Unit]
Description=xxxxxxx Service
ConditionPathExists=/home/nvidia/install/xxxxxxx
After=network.target

[Service]
Type=simple
User=root
EnvironmentFile=/home/user/install/env // 注入环境变量
WorkingDirectory=/home/user/install
ExecStart=/home/user/install/xxxxxxx -c /home/user/install/config.yml
Restart=on-failure
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=xxxxxxx
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target

示例创建了一个frp服务:


[Unit]
Description=frp server Service
After=network.target

[Service]
Type=simple
ExecStart=/etc/frp/frps -c /etc/frp/frps.ini
Restart=on-failure
RestartSec=10
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target
© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容