Share the Memcached shell startup and stop script, memcachedshell

Source: Internet
Author: User
Tags stop script

Share the Memcached shell startup and stop script, memcachedshell

Note: To use this shell, you must first successfully create the memcache environment 1 and create the memcached file and permission [root @ luozhonghua ~] # Touch/etc/init. d/memcached [root @ luozhonghua ~] # Chmod + x/etc/init. d/memcached2 write the Memcached shell management script vi/etc/init. d/memcached #! /Bin/bash # memcached-This shell script takes care of starting and stopping memcached. # chkconfig:-90 10 # description: Memcache provides fast memory based storage. # processname: memcachedmemcached_path = "/usr/local/bin/memcached" memcached_pid = "/var/run/memcached. pid & quot; memcached_memory = & quot; 1024 & quot; # Source function library .. /etc/rc. d/init. d/functions [-x $ memcached_path] | exit 0 RETVAL = 0 prog = "memcache D "# Start daemons. start () {if [-e $ memcached_pid-! -Z $ memcached_pid]; then echo $ prog "already running .... "exit 1 fi echo-n $" Starting $ prog "# Single instance for all caches $ memcached_path-m $ memcached_memory-l 0.0.0.0-p 11211-u root-d-P $ memcached_pid RETVAL =$? [$ RETVAL-eq 0] & {touch/var/lock/subsys/$ prog success $ "$ prog"} echo return $ RETVAL} # Stop daemons. stop () {echo-n $ "Stopping $ prog" killproc-d 10 $ memcached_path echo [$ RETVAL = 0] & rm-f $ memcached_pid/var/lock/subsys/$ prog RETVAL = $? Return $ RETVAL} # See how we were called. case "$1" in start) start; stop) stop; status) status $ prog RETVAL = $?; Restart) stop start; *) echo $ "Usage: $0 {start | stop | status | restart} "exit 1 esacexit $ RETVAL ############## the following two configurations in this script can be used according actual configuration ############# memcached_path = "/usr/local/bin/memcached" # memcached_memory = "1024" 3 "system Service chkconfig -- add memcached chkconfig memcached on
 
4 test (try it)
<p>service memcached start|stop|status|restart </p>


Run the shell script to start and stop apache. Check the running status of apache. If apache is started, stop it. If it is stopped, start apach.

Ps-fe | grep "/usr/sbin/httpd"
If [$? -Eq 1]
Then
Service httpd restart
Else
Service httpd stop
Fi
The content in the previous grep is modified based on the local conditions.

I want to write a shell script in linux to control the startup and stop of jar, which is similar to a background service.

The following is the startup script.

#! /Bin/sh
# Renewal #-------------------------------------------------------------------------------------------------------------
# Use this script --> [sh startup. sh]
# This script can be executed in any directory on the server without affecting the log output location.
# Renewal #-------------------------------------------------------------------------------------------------------------
# JAVA_HOME = "/usr/java/jdk1.6.0 _ 31"
JAVA_OPTS = "-Duser. timezone = GMT + 8-server-Xms2048m-Xmx2048m-Xloggc:/app/code/CucPayTradePortalLog/gc. log"
APP_LOG =/app/code/CucPayTradePortalLog
APP_HOME =/app/code/CucPayTradePortal
APP_MAIN = com. cucpay. tradeportal. MainApp
CLASSPATH = $ APP_HOME/classes
For tradePortalJar in "$ APP_HOME"/lib/*. jar;
Do
CLASSPATH = "$ CLASSPATH": "$ tradePortalJar"
Done
TradePortalPID = 0
GetTradeProtalPID (){
Javaps = '$ JAVA_HOME/bin/jps-l | grep $ APP_MAIN'
If [-n "$ javaps"]; then
TradePortalPID = 'echo $ javaps | awk '{print $1 }''
Else
TradePortalPID = 0
Fi
}
Startup (){
GetTradeProtalPID
Echo "============================================== ========================================================== ======================================"
If [$ tradePortalPID-ne 0]; then
Echo "$ APP_MAIN already started (PID = $ tradePortalPID )"
Echo "============================================== ========================================================== ======================================"
Else
Echo-n ...... the remaining full text>

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.