1 First add the script under/etc/rc.d/init.d/Asr_cron
#!/bin/bash# $Id: Rc.redhat.asterisk67061 -- .-Geneva -: One: 43Z Tilghman $## asterisk starts, Stops and reloads asterisk.## chkconfig:345 the $# 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"Exit0fiDAEMON=$AST _sbinstart () {# Start daemons. Echo-N $"Starting test:"$AST _sbin>>/var/www/html/test.log &Sleep 1proc=$(PS-fe |grep$AST _sbin|grep-Vgrep|awk '{print $}') if[ -Z $proc] Thenecho_failureElseecho_successfiRETVAL=$?Echoreturn $RETVAL}stop () {# Stop daemons. RETVAL=1 Echo-N $"shutting down test:" PS-fe |grep$AST _sbin|grep-Vgrep|awk '{print $}'| whileRead Line Do Kill$line RETVAL=$?Echo-N"Kill $line" Done Sleep 1proc=$(PS-fe |grep$AST _sbin|grep-Vgrep|awk '{print $}') if[ -Z $proc] Thenecho_successElseecho_failurefi Echoreturn $RETVAL}restart () {Stop start}status () {proc=$(PS-fe |grep$AST _sbin|grep-Vgrep|awk '{print $}') if[ -Z $proc] Then Echo "Teset:test is stoped" Else Echo "Test:test is starting" fiRETVAL=$?return retval}# See how we were called. Case " $" inchstart) Start; stop) stop;; restart) restart;; status) status;*)Echo "usage:service Test {start|stop|restart|status}"Exit1EsacExit $?
This script executes a PHP script with functions such as Start, stop, restart, and so on.
test.php
# !/usr/bin/php-q<? PHP Set_time_limit (0); $file = ' test.txt '; while (true) {@file_put_contents($file,date(' y-m-d h:i:s ', Time ())." \ n ",file_append); Sleep (Ten);}
2 Add the above script to the service:
Chkconfig--add Asr_cron
3 You need to give executable permissions to Asr_cron scripts and PHP scripts
The following commands can then be used to control the start, stop, and restart of the service:
/etc/rc.d/init.d/asr_cron start
/etc/rc.d/init.d/asr_cron stop
/etc/rc.d/init.d/asr_cron restart
New service under Linux