Memcached启停脚本小结
编写配置文件
vim/etc/memcached.conf
内容如下:
-m128-d-p11211-c1024
编写启动脚本
vim /etc/rc.d/init.d/memcached
#!/bin/bash
#
# memcached This shell script takes care of starting and stopping
# standalone memcached.
# . /etc/rc.d/init.d/functions PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/bin/memcached DAEMONBOOTSTRAP=/usr/local/bin/start-memcached DAEMONCONF=/etc/memcached.conf NAME=memcached DESC=memcached PIDFILE=/var/run/$NAME.pid [-x$DAEMON]||exit0[-x$DAEMONBOOTSTRAP]||exit0RETVAL=0 start(){echo-n $"Starting $DESC: " daemon $DAEMONBOOTSTRAP$DAEMONCONFRETVAL=$?[$RETVAL-eq0]&&touch$PIDFILEechoreturn$RETVAL} stop(){echo-n $"Shutting down $DESC: " killproc $NAMERETVAL=$?echo[$RETVAL-eq0]&&rm-f$PIDFILEreturn$RETVAL}# See how we were called.case"$1"in start) start ;; stop) stop ;; restart|reload) stop start RETVAL=$?;; status) status $progRETVAL=$?;;*)echo $"Usage: $0 {start|stop|restart|status}"exit1esacexit$RETVAL
[编辑]编写start-memcached脚本
vim /usr/local/bin/start-memcached
#!/usr/bin/perl -w# start-memcached use strict; if($>!= 0 and $<!= 0){ print STDERR "Only root wants to run start-memcached.\n"; exit; } my $etcfile = shift||"/etc/memcached.conf"; my $params = []; my $etchandle; # This script assumes that memcached is located at /usr/bin/memcached, and# that the pidfile is writable at /var/run/memcached.pid my $memcached = "/usr/local/bin/memcached"; my $pidfile = "/var/run/memcached.pid"; # If we don't get a valid logfile parameter in the /etc/memcached.conf file,# we'll just throw away all of our in-daemon output. We need to re-tie it so# that non-bash shells will not hang on logout. Thanks to Michael Renner for# the tip my $fd_reopened = "/dev/null"; sub handle_logfile { my ($logfile) = @_; $fd_reopened = $logfile; } sub reopen_logfile { my ($logfile) = @_; open *STDERR, ">>$logfile"; open *STDOUT, ">>$logfile"; open *STDIN, ">>/dev/null"; $fd_reopened = $logfile; }# This is set up in place here to support other non -[a-z] directives my $conf_directives = {"logfile" => \&handle_logfile }; if(open $etchandle, $etcfile){ foreach my $line(<$etchandle>){$line =~ s/\#.*//go;$line = join' ', split' ', $line; next unless $line; next if$line =~ /^\-[dh]/o; if($line =~ /^[^\-]/o){ my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/; $conf_directives->{$directive}->($arg); next; } push @$params, $line; }} unshift @$params, "-u root" unless (grep$_ eq '-u', @$params); $params = join" ", @$params; if(-e $pidfile){ open PIDHANDLE, "$pidfile"; my $localpid = <PIDHANDLE>; close PIDHANDLE; chomp $localpid; if(-d "/proc/$localpid"){ print STDERR "memcached is already running.\n"; exit; }else{`rm-f$localpid`; }} my $pid = fork(); if($pid == 0){ reopen_logfile($fd_reopened); exec"$memcached$params"; exit(0); } elsif (open PIDHANDLE,">$pidfile"){ print PIDHANDLE $pid; close PIDHANDLE; }else{ print STDERR "Can't write pidfile to $pidfile.\n"; }
修改权限
chmod 755 /etc/rc.d/init.d/memcached chmod 755 /usr/local/bin/start-memcached
启动
service memcached start
[编辑]艺搜参考
http://forums.eukhost.com/f15/memcached-best-caching-option-linux-web-servers-5269/
http://duntuk.com/how-install-memcached-centos-memcached-php-extension-centos
Memcached启停脚本小结的更多相关文章
- Linux 程序启停脚本
start.sh #!/bin/sh java -jar ./program.jar & echo $! > /var/run/program.pid stop.sh #!/bin/sh ...
- linux下的启停脚本
linux下的根据项目名称,进行进程的启停脚本 #!/bin/bash JAVA=/usr/bin/java APP_HOME=/opt/program/qa/wechat APP_NAME=prog ...
- case编写的httpd简单启停脚本
case编写的httpd简单启停脚本 #!/bin/bash HTTPD="/etc/init.d/httpd" . /etc/init.d/functions case &quo ...
- Oracle EBS R12的启停脚本
以下脚本用root用户登录执行: 一.DB启停使用EBS提供的脚本ebs_start.shsu - oraprod -c "/d01/oracle/PROD/db/tech_st/10.2. ...
- Oracle BIEE启停脚本
作为BI的开发人员,经常启停BI服务在所难免,启动的过程又比较长,命令需要不同目录切换,简直烦死人呢, 特意整理了linux中的启动脚本,将以下脚本存成biee.sh,后面的过程就相当简单了, 启动: ...
- python启停脚本的编写
先占个位置,打算记录一下启停python 的脚本start.sh,stop.sh的写法. 内容包括启动python脚本的方式,日志的重定向,获取进程id,以及杀掉进程. 参考文章: http://bl ...
- mysql自己编写启停脚本
一.场景 在实际生产环境中要求相对较高的企业对于root权限管控相对比较高,故而很多软件并非安装在root用户下(当然root用户权限也可管理,但正常情况下root权限并不会给业务使用方,而会给一个普 ...
- nginx启停脚本
安装nginx时,源码包中未带官方的启动脚本,也就无法使用service nginxd start这种启动方式,查了下资料自己写了一个: #!/bin/bash #@version: #@author ...
- liunx weblogic服务启停脚本
#!/bin/bash #sh xx.sh start xx项目 例如:sh autoWeblogic.sh start bius #经测试发现weblogic 启动大概需要完全启动成功35秒左右 停 ...
随机推荐
- seajs之seajs-debug坑
最近遇到两个关于seajs-debug的坑 一个与preload有关,详情见https://github.com/seajs/seajs-debug/issues/15 一个与map时间戳有关,详情见 ...
- javascript trigger触发事件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Flume-NG中Transaction并发性探究
我们曾经在Flume-NG中的Channel与Transaction关系(原创)这篇文章中说了channel和Transaction的关系,但是在source和sink中都会使用Transaction ...
- HDOJ 1536 S-Nim
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- MySQL 索引详解大全
什么是索引? 1.索引 索引是表的目录,在查找内容之前可以先在目录中查找索引位置,以此快速定位查询数据.对于索引,会保存在额外的文件中. 2. 索引,是数据库中专门用于帮助用户快速查询数据的一种数据结 ...
- 【leetcode】Palindrome Partitioning
Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...
- linux中pip安装步骤与使用详解
pip类似RedHat里面的yum,安装软件非常方便.本节详细介绍pip的安装.以及使用方法,希望文章对各位了解pip的安装与使用带来帮助. 1.pip下载安装1.1 pip下载 代码如下 复制代码 ...
- mysql update case when和where之间的注意事项
在日常开发中由于业务逻辑较为复杂,常常需要用到UPDATE和CASE...WHEN...THEN...ELSE...END一起做一些复杂的更新.有时候因为对这几个字句理解得不透彻会带来很大的困扰.因此 ...
- cocos2d c++ 代码规范(译文)
原文在http://cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d_c++_coding_style,我觉得这个规范非常全面,写的非常好,我只捡一些我认为比 ...
- codeforces 468A. 24 Game 解题报告
题目链接:http://codeforces.com/problemset/problem/468/A 题目意思:给出一个数n,利用 1 - n 这 n 个数,每个数只能用一次,能否通过3种运算: + ...