自定义脚本将memcached作为系统服务启动以及开机启动。

一、编写脚本

在/etc/init.d/目录下新建一个脚本,名称为:memcached。内容如下:
vi /etc/init.d/memcached
    1. #!/bin/bash
    1. #description: Memcached Service Daemon
    1. #processname: Memcached
    1. #chkconfig: 2345 90 50
    1. #Source function library.
    1. . /etc/rc.d/init.d/functions
    1. . /etc/sysconfig/network
    1. memcached_exec="/usr/local/bin/memcached"
    1. memcached_pid="/var/run/memcached.pid"
    1. lockfile="/var/lock/subsys/memcached"
    1. prog="memcached"
    1. memcached_host="182.168.36.54"
    1. memcached_port=11411
    1. memcached_memory="1024"
    1. start() {
    1. if [ $UID -ne 0 ]; then
    1. echo "User has insufficient privilege."
    1. exit 4
    1. fi
    1. [ -x $memcached_exec ] || exit 5
    1. echo -n $"starting $prog: "
    1. daemon $memcached_exec -u daemon -d -m $memcached_memory -l $memcached_host -p $memcached_port -c 256 -P $memcached_pid
    1. retval=$?
    1. echo
    1. [ $retval -eq 0 ] && touch $lockfile
    1. }
    1. stop() {
    1. if [ $UID -ne 0 ]; then
    1. echo "User has insufficient privilege."
    1. exit 4
    1. fi
    1. echo -n $"Stopping $prog: "
    1. if [ -n "`pidfileofproc $memcached_exec`" ]; then
    1. killproc $memcached_exec
    1. else
    1. failure $"stopping $prog"
    1. fi
    1. retval=$?
    1. echo
    1. [ $retval -eq 0 ] && rm -f $lockfile
    1. }
    1. status() {
    1. # run checks to determine if the service is running or use generic status
    1. status $prog
    1. }
    1. case "$1" in
    1. "start")
    1. start
    1. ;;
    1. "stop")
    1. stop
    1. ;;
    1. "restart")
    1. stop
    1. sleep 3
    1. start
    1. ;;
    1. "status")
    1. status
    1. ;;
    1. *)
    1. echo $"Usage: $0 {start|stop|status|restart}"
    1. exit 1
    1. ;;
    1. esac
    1. exit $?
此脚本使用了functions文件里的函数,因此需要将其加载进来。因为要判断memcached服务的运行状态,所以在调用memcached程序时,传递了pid文件参数。因为在此脚本中判断运行状态以及停止memcached服务时,是使用pid文件来进行的。
由上面的脚本可以看出,提供了四个动作:start、stop、status、restart。

添加执行权限:

    1. chmod +x /etc/init.d/memcached

二、memcached服务的安装

查看memcached服务是否在chkconfig管理列表:
chkconfig --list memcached
将其加入chkconfig管理:
chkconfig --add memcached
chkconfig --level 235 memcached on

三、memcached服务启动

chkconfig --list | grep memcached
service memcached start
service memcached stop
service memcached restart




Memcache 服务管理脚本的更多相关文章

  1. 如何写SysV服务管理脚本

    本文目录: 1.1 SysV脚本的特性1.2 SysV脚本要具备的能力1.3 start函数分析1.4 stop函数分析1.5 reload函数分析1.6 status.restart.force-r ...

  2. [转贴]systemd 编写服务管理脚本

    [转贴]sparkdev大神的博客, 关于 systemd的配置文件的 介绍, 自己之前二进制安装 k8s 时 超过一个 service文件 但是当时不明不白的. 现在再学习一下大神的文章 的确牛B ...

  3. systemd 编写服务管理脚本

    我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web server等.因此管理 linux 服务器主要工作就是配置并管理上面运行的各种服务程序.在 linux 系统中 ...

  4. systemd 编写服务管理脚本---学习

    转载:https://www.cnblogs.com/sparkdev/p/8521812.html 我们运行 linux 服务器的主要目的是通过运行程序提供服务,比如 mysql.web serve ...

  5. 自己编写服务启动脚本(一):functions文件详细分析和说明

    本文目录: 1.几个显示函数2.action函数3.is_true和is_false函数4.confirm函数5.pid检测相关函数 5.1 checkpid.__pids_var_run和__pid ...

  6. systemd 服务管理编写

    1.编辑服务管理脚本 $ cat /lib/systemd/system/kafka.service [Unit] Description=Kafka Server Documentation=htt ...

  7. CentOS 7安装/卸载Redis,配置service服务管理

    Redis简介 Redis功能简介 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 相比于传统的关系型数据库,Redis的存储方式是key-va ...

  8. centOS 6 服务管理与服务脚本

    服务管理与服务脚本   linux服务 服务管理与服务脚本 linux服务 服务启动过程详解 chkconfig命令 非独立服务与xinetd进程 一个特殊的服务脚本   服务启动过程详解 在开机启动 ...

  9. 第11章 Linux服务管理

    1. 服务分类 (1)Linux的服务 ①Linux中绝大多数的服务都是独立的,直接运行于内存中.当用户访问时,该服务直接响应用户,其好处是服务访问响应速度快.但不利之处是系统中服务越多,消耗的资源越 ...

随机推荐

  1. python面试题(三)

    一.项目技术点梳理 (一)Django项目 本项目是用python的Django框架开发的前后端不分离项目.项目采用MVT架构,使用的MySQL和redis数据库,用Django自带的orm与数据库交 ...

  2. font:12px/1.5 tahoma, arial, \5b8b\4f53, sans-serif详解

    在phpcms v9的样式表文件reset.css中有如下一段样式,具体什么意思?代码如下:body,html,input{font:12px/1.5 tahoma,arial,\5b8b\4f53, ...

  3. linux用命令行编译使用函数库

    同步于气象家园日志 from fcode 视频 编译静态链接库   gfortran -c sub.f90 func.f90  产生了func.mod文件.注:mod文件是静态库的接口.如果删掉了fu ...

  4. 记一个小bug的锅

    人生中的第一个线上bug 我参与的第一个项目就出现了.但是自己还觉得这锅也不全是自己的,毕竟那么明显的bug出现在历史模块中(不是我写的新模块),难道测试部就没一点责任?代码走查人员就没一点责任?不过 ...

  5. cpp-variable-lifetime

    #include <cstdio> #include <iostream> using namespace std; class TmpClass; void FuncScop ...

  6. 一个可以自由存取的onedriver

    https://cittedu-my.sharepoint.com/personal/jostin_5gd_me/Documents/jostin

  7. java之接口开发-初级篇

    简述:转眼之间已经开发java有五年之余了,从以前的刚刚接触电脑,到现在的公司上班,真是转眼之间呀!前两年开发过前端,后台和Android,Android火的那几年,差点转去做Android,哈哈!后 ...

  8. 程序设计 之 C#实现《拼图游戏》 (上)代码篇

    原理详解请参考博客中 拼图游戏(下)原理篇 http://www.cnblogs.com/labixiaohei/p/6713761.html 功能描述: 1.用户自定义上传图片 2.游戏难度选择:简 ...

  9. printf命令详解

    基础命令学习目录首页 本文是Linux Shell系列教程的第(八)篇,更多shell教程请看:Linux Shell系列教程 在上一篇:Linux Shell系列教程之(七)Shell输出这篇文章中 ...

  10. oraclejdbc

    https://segmentfault.com/q/1010000004952621/a-1020000004955600