第一种方式
一般是系统服务:
systemctl enable nginx
第二种方式

命令行中输入ntsysv,然后选择系统服务
第三种方式
配置到 /etc/systemd/system/
1)创建service文件
vim /etc/systemd/system/ServiceName.service
[Unit]
Description=ServiceName
After=syslog.target
[Service]
User=myapp
ExecStart=/var/myapp/myapp.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
2)重载守护进程
systemctl daemon-reload
3)设置开机自启动服务
systemctl enable ServiceName.service
systemctl disable ServiceName.service 取销开机启动
4)验证:

本文介绍了三种在Linux系统中管理服务的方法,包括使用systemctl命令启用或禁用服务,通过ntsysv交互式界面调整服务设置,以及手动创建和配置systemd服务单元文件以实现开机自启动。详细步骤包括编写service文件、重载守护进程、启用或禁用服务以及验证设置。
1752





