自定义服务

linux自定义服务并设置开机自启动

【init.d】

服务脚本

#!/bin/sh
#chkconfig: 2345 80 05
#description: api-server

start() {
	nohup java -jar ./
}

stop() {
		
}

status() {
	`ps -ef|grep `
}

case $1 in 
start)
	start
	;;
stop)
	stop
	;;
restart)
	stop
	sleep 1
	start
	;;
*) 
	echo "api-server Usage:"
	echo "service api-server start | stop | restart | status"
	;;

服务添加

mv api-server /etc/init.id/

chkconfig --list //查看服务
chkconfig --add api-server //添加服务

服务启动

service api-server status
service api-server start
service api-server stop
原文地址:https://www.cnblogs.com/pengsn/p/13278636.html