In Linux, general software is started as a service.

Source: Internet
Author: User
In Linux, the general software startup method is used as a service method. the openmeeting installed this time is used as an example: www.2cto.com directory structure:/root/openmeeting_dirnary/admin. batadmin. sh... red5.shred5-shutdown. batred5-shutdown.sh... if you want to start it .. in Linux, general software is started as a service.

Take the openmeeting installed this time as an example:
Www.2cto.com
Directory structure:/root/openmeeting_dirnary/admin. bat
Admin. sh
...
Red5.sh
Red5-shutdown.bat
Red5-shutdown.sh
...
If you want to start it, we usually go to this/root/openmeeting_dirnary/directory,
Run:./red5.sh & (of course, you must have the execution permission)
Now we have to do the following: www.2cto.com
It can be started or closed to form a service... stop | start | restart | status | restart method.
Cd/etc/init. d/
Touch openmeetingd ....)
Paste the code of the file and explain it in detail:
# Start Red5 demon
Start () {# There is nothing to say about this step. it is to enter the Directory, change the permission, and start...
Echo "starting red5 ..."
Cd/root/openmeeting_binary/
Chmod 755 red5.sh
./Red5.sh &
Echo "Red5 started successful ..."
}

# Stop red5 demon
Stop () {# explain in detail below
Pid = 'PS-ef | grep "java" | grep-v "grep" | awk '{print $2 }''
If ["$ pid" = ""]; then
Echo "No red5 pid alive ..."
Else
Echo "now, kill pid $ pid ..."
Kill $ pid
Echo "Red5 stopped successful ..."
Fi
}

# Show the status of red5
Status () {# identify the status by determining whether the process is started, that is, whether the pid exists
Pid = 'PS-ef | grep "java" | grep-v "grep" | awk '{print $2 }''
If ["$ pid" = ""]; then
Echo "red5 is stopped ..."
Else
Echo "red5 is running ..."
Fi
}

# Restart red5 demo
Restart () {# call the previous function. it's easy...
Stop
Start
}

# Execute by input command # determine what to execute based on the input command
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Status)
Status
;;
Restart)
Restart
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart }"
Exit 1
Esac next we will focus on the script executed during stop:
Pid = 'PS-ef | grep "java" | grep-v "grep" | awk '{print $2} ''to obtain the pid of the process.
Execute ps-ef | grep "java:


This statement mainly finds out the running process of red5, which is java. we can also see that the second process is the grep java we just executed,
To obtain only the preceding row, execute:
Ps-ef | grep "java" | grep-v "grep"

 
Here we can see that there is only one line left, which is the ID of the red5 survival we want.
The-v parameter of grep indicates that all rows without text are displayed, and the second row is removed.
 
Run: ps-ef | grep "java" | grep-v "grep" | awk '{print $2 }'
 

 
We can see that there is only one digit left, namely the pid, which is the final value we want.
Okay, let's just kill it. it's a bit violent ..
.
Related Article

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.