注册一个系统服务,开机自启动.
1 脚本编写
#vim test.sh
#!/bin/bash
#description: hello.sh
#chkconfig: 2345 20 81
exec_path=/usr/local/
exec=hello.sh
daemon=/usr/local/hello.sh
pid_file=/var/run/hello.sh.pid
. /etc/rc.d/init.d/functions
if [ ! -x $exec_path/$exec ] ; then
echo "error: $daemon not found"
exit 1
fi
stop()
{
echo "stoping $exec ..."
ps aux | grep "$daemon" | kill -9 `awk '{print $2}'` >/dev/null 2>&1
rm -f $pid_file
usleep 100
echo "shutting down $exec: [ ok ]"
}
start()
{
echo "starting $exec ..."
$daemon > /dev/null &
pidof $exec > $pid_file
usleep 100
echo "starting $exec: [ ok ]"
}
restart()
{
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status -p $pid_file $daemon
;;
*)
echo "usage: service $exec {start|stop|restart|status}"
exit 1
esac
exit $?
2注册服务
# chmod 700 test.sh
# cp test.sh /etc/init.d/
# chkconfig --add test.sh
# chkconfig --list
3.删除服务
# chkconfig --del test.sh
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
IT基础与云计算
软路由器(IPtable)iptable是Linux上常用的防火墙软件。负载均衡负载均衡是网络基础构架的关键组件...
[阅读全文]
-
-
嵌入式行业职位分析
嵌入式开发涵盖硬件软件,开发链条很长,要根据自己的实际情况选择适应的职位。嵌入式的职位大概有:1、硬件工程师:负...
[阅读全文]
-
-
-
-
-
运维面试题小总结
linux惊群效应 如何解决? 是什么情况导致发生惊群效应也有人叫做雷鸣群体效应,不过叫什么,简言之,惊群现象就...
[阅读全文]
-
-
网友评论