標籤:time stop div load proc 功能 line desc linux
1 首先在/etc/rc.d/init.d/下添加指令碼 asr_cron
#!/bin/bash# $Id: rc.redhat.asterisk 67061 2007-06-04 17:11:43Z tilghman $## asterisk Starts, Stops and Reloads Asterisk.## chkconfig: 345 95 65# description: Asterisk PBX and telephony daemon.AST_SBIN=/var/www/html/test.php. /etc/rc.d/init.d/functionsif ! [ -x $AST_SBIN ] ; thenecho "ERROR: test not found"exit 0fiDAEMON=$AST_SBINstart() {# Start daemons. echo -n $"Starting test: " $AST_SBIN >> /var/www/html/test.log & sleep 1 proc=$(ps -fe | grep $AST_SBIN|grep -v grep|awk ‘{print $2}‘) if [ -z $proc ] then echo_failure else echo_success fi RETVAL=$? echo return $RETVAL}stop() {# Stop daemons. RETVAL=1 echo -n $"Shutting down test: " ps -fe | grep $AST_SBIN|grep -v grep|awk ‘{print $2}‘|while read line do kill $line RETVAL=$? echo -n "kill $line " done sleep 1 proc=$(ps -fe | grep $AST_SBIN|grep -v grep|awk ‘{print $2}‘) if [ -z $proc ] then echo_success else echo_failure fi echo return $RETVAL}restart() { stop start}status() { proc=$(ps -fe | grep $AST_SBIN|grep -v grep|awk ‘{print $2}‘) if [ -z $proc ] then echo "teset: test is stoped" else echo "test: test is starting" fi RETVAL=$? return RETVAL}# See how we were called.case "$1" instart)start;;stop)stop;;restart)restart;;status)status;;*)echo "Usage: service test {start|stop|restart|status}"exit 1esacexit $?
這個指令碼執行一個PHP指令碼,功能有啟動、停止、重啟等功能。
test.php
#!/usr/bin/php -q<?phpset_time_limit(0);$file = ‘test.txt‘;while(true){@file_put_contents($file,date(‘Y-m-d H:i:s‘,time())."\n",FILE_APPEND);sleep(10);}
2 把上面的指令碼加到服務裡:
chkconfig --add asr_cron
3 需要把asr_cron指令碼、以及PHP指令碼賦予可執行許可權
然後就可以如下的命令控制服務的啟動、停止、重啟了:
/etc/rc.d/init.d/asr_cron start
/etc/rc.d/init.d/asr_cron stop
/etc/rc.d/init.d/asr_cron restart
Linux下建立服務