将应用注册为Linux的服务

主流的Linux大多使用init.d或systemd来注册服务。下面以centos6.6演示init.d注册服务;以centos7.1演示systemd注册服务。

 1. 基于Linux的init.d部署

sudo ln -s /var/apps/xxxx.jar  /etc/init.d/test

其中 test就是服务名

service test start    启动服务

service test stop   停止服务

service test status  服务状态

chkconfig test on       开机启动

 

  2.  基于Linux的systemd部署

在/etc/systemd/system/目录下新建文件test.service,填入下面内容:

[Unit]

Description=test

After=syslog.target

[Serive]

ExecStart=/usr/bin/java -jar  /var/app/XXX.jar

[Install]

WantedBy=multi-user.target

注意,在实际使用中修改Description和ExecStart后面的内容

systemctl start test 或  systemctl start test.service           启动服务

systemctl stop test 或  systemctl stop test.service           停止服务

systemctl status test 或  systemctl status test.service       服务状态

systemctl enable test 或  systemctl enable test.service       开机启动

journalctl -u test 或  journalctl -u test.service           启动服务

 

posted @ 2017-04-26 00:01  kevin_shen  阅读(6128)  评论(0编辑  收藏  举报