您现在的位置是:首页 > 文章详情

Centos7 安装系统服务、开机自启动

日期:2019-08-15点击:614

Centos7 安装系统服务、开机自启动

编写可执行程序

  • 任意编程语言(C、C++、Java、PHP、Python、Perl ...)编写的程序;
  • 当前假设此程序的路径为:/myservice/bin/myprogram

编写服务脚本

#! /bin/bash

# chkconfig: 2345 80 90
# description: this is your auto run program.

start() {
echo "starting service ..."
cd /myservice/bin
./start.sh
echo "ok"
}

stop() {
echo "stop service ..."
cd /myservice/bin
./stop.sh
echo "ok"
}

case "$1" in
"start")
start
;;
"stop")
stop
;;
"restart")
stop
start
;;
*)

echo $"Usage: $0 {start|stop|restart}"
exit 0
esac

添加到服务和开机启动项

chkconfig --add myservice
chkconfig --level 2345 myservice on

chkconfig 参考命令

chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name <on|off|reset>
chkconfig [--level levels] name
原文链接:https://yq.aliyun.com/articles/714543
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章