【Ubuntu20.04】使用 systemd 进行服务部署

1、服务文件

  • ExecStart,改成自己脚本的路径,比如程序启动脚本

  • Restart,异常重启

  • RestartSec,异常后多少秒后重启

  • StartLimitInterval,异常后重试多少次,0 一直重试

    [Unit]
    Description=your_app

    [Service]
    Type=your_app
    ExecStart=/root/your_app.sh
    Restart=always
    RestartSec=5
    StartLimitInterval=0

    [Install]
    WantedBy=default.target

2. 配置

将上述文件命名为 your_app.serivce ,放入/etc/systemd/system 目录下

比如,你的服务名称叫 your_app

服务启用

sudo systemctl enable your_app

服务启动

sudo systemctl start your_app

服务重新启动

sudo systemctl restart your_app

服务停止

sudo systemctl stop your_app

服务禁用

sudo systemctl disable your_app

服务配置更新

sudo systemctl daemon-reload

服务状态

sudo systemctl status your_app
相关推荐
C++忠实粉丝30 分钟前
Linux环境基础开发工具使用(2)
linux·运维·服务器
康熙38bdc1 小时前
Linux 环境变量
linux·运维·服务器
存储服务专家StorageExpert1 小时前
DELL SC compellent存储的四种访问方式
运维·服务器·存储维护·emc存储
hakesashou2 小时前
python如何比较字符串
linux·开发语言·python
Ljubim.te2 小时前
Linux基于CentOS学习【进程状态】【进程优先级】【调度与切换】【进程挂起】【进程饥饿】
linux·学习·centos
cooldream20092 小时前
Linux性能调优技巧
linux
大G哥2 小时前
记一次K8S 环境应用nginx stable-alpine 解析内部域名失败排查思路
运维·nginx·云原生·容器·kubernetes
长天一色2 小时前
【ECMAScript 从入门到进阶教程】第三部分:高级主题(高级函数与范式,元编程,正则表达式,性能优化)
服务器·开发语言·前端·javascript·性能优化·ecmascript
醉颜凉2 小时前
银河麒麟桌面操作系统修改默认Shell为Bash
运维·服务器·开发语言·bash·kylin·国产化·银河麒麟操作系统
QMCY_jason3 小时前
Ubuntu 安装RUST
linux·ubuntu·rust