采用chkconfig 方式设置程序开机启动
编写启动脚本,路径 cd /etc/init.d/名称 eg: test
#!/etc/init.d/
# chkconfig: - 85 15
# description: rc.local is a local customized. It is used to serve
# @Author: zyzhan
# @Date: 2023-03-01 17:44:45
# @Last Modified by: zyzhan
# @Last Modified time: 2023-03-01 17:44:45
start(){
cd //home/wwwroot/default/
nohup ./TjServer_linux &
echo "服务已启动..."
sleep 1
}
stop(){
killall TjServer_linux
echo "服务已停止..."
sleep 1
}
case "$1" in
start) start;;
stop) stop;;
restart) start;;
reload) start;;
status) start;;
*)
echo "$0 {start|stop|restart|reload|status}"
exit 4
;;
esac
命令执行
chkconfig
chkconfig add test
chkconfig test on
-
使用chmod 777 名称 脚本文件和授权文件有执行权限
-
服务添加到服务列表 chkconfig --add 名称
-
查询服务列表确认添加成功 chkconfig --list
-
开启服务 chkconfig 名称 on
-
启动服务 service 名称 start
-
重启服务器程序即可开机启动