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 @ 2024-05-29 10:34  金虹巴巴  阅读(22)  评论(0编辑  收藏  举报