systemctl常用命令

 

注册服务

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

[Unit]
Description=test Java Application
After=network.target
[Service]
User=root
WorkingDirectory=/data/javaApps
#这里主要使用的是绝对路径,包括java命令和jar包位置,最后的
# --spring.profiles.active=dev代表的是使用jar里的哪个配置文件启动,这里写的是
# dev,就是使用dev的配置文件启动该项目。若不配置则按照默认配置进行启动
ExecStart=/usr/bin/java -jar /data/javaApps/test.jar --spring.profiles.active=dev &
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target

 

启动服务:systemctl start 服务名.service  如: systemctl start test.service 
停止服务:systemctl stop 服务名.service
重启服务:systemctl restart 服务名.service
查看服务状态:systemctl status 服务名.service
使服务在启动时自动运行:systemctl enable 服务名.service
禁止服务在启动时自动运行:systemctl disable 服务名.service
重新加载服务配置:systemctl reload 服务名.service
查看所有已启动的服务:systemctl list-units --type=service
查看日志:journalctl -u 服务名.service
在使用 systemctl 命令时,通常需要管理员权限,因此你可能需要在命令前加上 sudo。

 

 

posted @   金虹巴巴  阅读(62)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示