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秒左右 停 ...
随机推荐
- 在spring中获取代理对象代理的目标对象工具类
昨天晚上一哥们需要获取代理对象的目标对象,查找了文档发现没有相应的工具类,因此自己写了一个分享给大家.能获取JDK动态代理/CGLIB代理对象代理的目标对象. 问题描述:: 我现在遇到个棘手的问题,要 ...
- [Effective JavaScript 笔记]第15条:当心局部块函数声明笨拙的作用域
嵌套函数声明.没有标准的方法在局部块里声明函数,但可以在另一个函数的顶部嵌套函数声明. function f(){return "global"} function test(x) ...
- 今天逛VC驿站 的收获
1.C++ 如何定义一个定长字符串, 若不足位数,就补字符串"0"? eg: CString str1 = “123”;不足20位,前面补“0”,实现效果为“00000000000 ...
- [BZOJ1998][Hnoi2010]Fsk物品调度
[BZOJ1998][Hnoi2010]Fsk物品调度 试题描述 现在找工作不容易,Lostmonkey费了好大劲才得到fsk公司基层流水线操作员的职位.流水线上有n个位置,从0到n-1依次编号,一开 ...
- JSP基本面试的试题
JSP基本面试的试题 1.jsp有哪些内置对象作用分别是什么 答:JSP共有以下9种基本内置组件(可与ASP的6种内部组件相对应): request 用户端请求,此请求会包含来自GET/PO ...
- linux安装setup工具
如果你的Linux系统是最小化安装的,可能会没有setup命令工具,环境是centos 5.8 安装setup命令工具的步骤. 安装setuptool #yum install setuptool 系 ...
- dell idrac8 部署操作系统的方法
1,打开虚拟控制台 2,“虚拟介质”->“连接虚拟介质”->“映射虚拟介质到CD”->(选择要安装的镜像文件)->“Map device” 3, “next boot”-> ...
- dhcp原理、安装、相关命令、疑惑
转自: http://blog.sina.com.cn/s/blog_642e41c20101tct3.html
- 开博一周总结与随谈[thinking of writing blog for one week]
8天前,就是5月19号,突发奇想,觉得应该开个博客记录下自己的学习笔记和心得,更重要的是做个自我梳理和总结.大致看了下国内的博客,最后选定cnblogs.之所以选则cnblogs是因为平时搜到不少好文 ...
- ios如何生成crash报告
#include <signal.h> #include <execinfo.h> void OnProcessExceptionHandler(int sigl) { do ...