在 `/etc/init.d/` 加入 `workerman` 文件(自定义服务,其实就是一个bash脚本),注意不要 `.sh` 后缀;
内部的 `start()` 这个函数会开机启动,配合 `chkconfig workerman on` 使用,注意引用绝对路径命令。
```
#!/bin/bash
#chkconfig: 2345 70 30
#description: workerman command #关于脚本的简短描述
#processname: workerman
start() {
cd /data/wwwroot/tzb/web/workman/http
/usr/local/php/bin/php http.php start -d
}
stop(){
cd /data/wwwroot/tzb/web/workman/http
/usr/local/php/bin/php http.php stop
}
case "$1" in
start)
cd /data/wwwroot/tzb/web/workman/http
/usr/local/php/bin/php http.php start -d
echo "Starting WorkMan..."
;;
stop)
cd /data/wwwroot/tzb/web/workman/http
/usr/local/php/bin/php http.php stop
echo "Shutting WorkMan..."
;;
restart)
cd /data/wwwroot/tzb/web/workman/http
/usr/local/php/bin/php http.php restart
echo "Restart WorkMan..."
;;
reload)
cd /data/wwwroot/tzb/web/workman/http
/usr/local/php/bin/php http.php reload
echo "Restart WorkMan..."
;;
*)
echo "Usage: #0 {start|stop|restart}"
;;
esac
```
然后:
```
chkconfig --add workerman
chkconfig workerman on
```
开机会自动执行`start()`函数,平时使用 `service workerman start | stop | restart | reload`
(责任编辑:最模板) |