自定义linux服务并设置服务开机启动,也是开机自动执行自定义脚本的一种方法。
工具/原料
linux系统
方法/步骤
1
自定义脚本vi /etc/rc.d/init.d/hello#!/bin/bash# chkconfig: 2345 10 90# description: hello world ....echo 'Hello world!'
2
赋权限chmod 755 hello
3
添加服务[root@db1 init.d]# chkconfig --add helloservice hello does not support chkconfig
4
开机自启[root@db1 init.d]# chkconfig hello off[root@db1 init.d]# chkconfig --list|grep hellohello 0:off 1:off 2:off 3:off 4:off 5:off 6:off[root@db1 init.d]# chkconfig hello on [root@db1 init.d]# chkconfig --list|grep hellohello 0:off 1:off 2:on 3:on 4:on 5:on 6:off
注意事项
1
所有操作需要root权限
2
脚本最前端不添加# chkconfig: 2345 10 90,添加服务时会报错:service hello does not support chkconfig
上一篇:小猪佩奇之乔治怎么画-动态图解