New service under Linux

Source: Internet
Author: User
Tags php script

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.