Shell脚本注册到Linux系统服务实例
注册一个系统服务,开机自启动.
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
栏 目:其它服务器
本文地址:https://zz.feitang.co/server/34939.html
您可能感兴趣的文章
- 01-06nginx从安装到配置详细说明(安装,安全配置,防盗链,动静分离,配置 HTTPS,性能优化)
- 01-06Nginx性能优化之Gzip压缩设置详解(最大程度提高页面打开速度)
- 01-06Linux系统 Centos7.4手动在线升级到Centos7.7
- 01-06详解nginx安装过程并代理下载服务器文件
- 01-06shell脚本根据进程查找指定容器的方法
- 01-06微服务架构拆分策略详解
- 01-06使用 Apache Dubbo 实现远程通信(微服务架构)
- 01-06微服务架构之服务注册与发现功能详解
- 01-06使用Zabbix 5.4.3监控IPMI的方法
- 01-06微服务架构之服务注册与发现实践示例详解






