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>