使用命令 start-stop-daemon

官方文档:http://manpages.ubuntu.com/manpages/lucid/en/man8/start-stop-daemon.8.html

Usage: start-stop-daemon [<option> ...] <command>

Commands:
-S|--start -- <argument> ... start a program and pass <arguments> to it
-K|--stop stop a program
-T|--status get the program status
-H|--help print help information
-V|--version print version Matching options (at least one is required):
-p|--pidfile <pid-file> pid file to check
-x|--exec <executable> program to start/check if it is running
-n|--name <process-name> process name to check
-u|--user <username|uid> process owner to check Options:
-g|--group <group|gid> run process as this group
-c|--chuid <name|uid[:group|gid]>
change to this user/group before starting
process
-s|--signal <signal> signal to send (default TERM)
-a|--startas <pathname> program to start (default is <executable>)
-r|--chroot <directory> chroot to <directory> before starting
-d|--chdir <directory> change to <directory> (default is /)
-N|--nicelevel <incr> add incr to the process' nice level
-P|--procsched <policy[:prio]>
use <policy> with <prio> for the kernel
process scheduler (default prio is 0)
-I|--iosched <class[:prio]> use <class> with <prio> to set the IO
scheduler (default prio is 4)
-k|--umask <mask> change the umask to <mask> before starting
-b|--background force the process to detach
-m|--make-pidfile create the pidfile before starting
-R|--retry <schedule> check whether processes die, and retry
-t|--test test mode, don't do anything
-o|--oknodo exit status 0 (not 1) if nothing done
-q|--quiet be more quiet
-v|--verbose be more verbose Retry <schedule> is <item>|/<item>/... where <item> is one of
-<signal-num>|[-]<signal-name> send that signal
<timeout> wait that many seconds
forever repeat remainder forever
or <schedule> may be just <timeout>, meaning <signal>/<timeout>/KILL/<timeout> The process scheduler <policy> can be one of:
other, fifo or rr The IO scheduler <class> can be one of:
real-time, best-effort or idle Exit status:
0 = done
1 = nothing done (=> 0 if --oknodo)
2 = with --retry, processes would not die
3 = trouble
Exit status with --status:
0 = program is running
1 = program is not running and the pid file exists
3 = program is not running
4 = unable to determine status

  

demo:

odoo的启动脚本

#!/bin/sh

### BEGIN INIT INFO
# Provides: openerp-server
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Enterprise Resource Management software
# Description: Open ERP is a complete ERP and CRM software.
### END INIT INFO PATH=/bin:/sbin:/usr/bin
DAEMON=/opt/openerp/server/openerp-server
NAME=openerp-server
DESC=openerp-server # Specify the user name (Default: openerp).
USER=openerp # Specify an alternate config file (Default: /etc/openerp-server.conf).
CONFIGFILE="/etc/openerp-server.conf" # pidfile
PIDFILE=/var/run/$NAME.pid # Additional options that are passed to the Daemon.
DAEMON_OPTS="-c $CONFIGFILE" [ -x $DAEMON ] || exit 0
[ -f $CONFIGFILE ] || exit 0 checkpid() {
[ -f $PIDFILE ] || return 1
pid=`cat $PIDFILE`
[ -d /proc/$pid ] && return 0
return 1
} case "${1}" in
start)
echo -n "Starting ${DESC}: " start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid ${USER} --background --make-pidfile \
--exec ${DAEMON} -- ${DAEMON_OPTS} echo "${NAME}."
;; stop)
echo -n "Stopping ${DESC}: " start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--oknodo echo "${NAME}."
;; restart|force-reload)
echo -n "Restarting ${DESC}: " start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--oknodo sleep 1 start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
--chuid ${USER} --background --make-pidfile \
--exec ${DAEMON} -- ${DAEMON_OPTS} echo "${NAME}."
;; *)
N=/etc/init.d/${NAME}
echo "Usage: ${NAME} {start|stop|restart|force-reload}" >&2
exit 1
;;
esac exit 0

  

ubuntu12.04 Daemon的简单实现的更多相关文章

  1. ubuntu12.04下一个简单的conky安装

    这个conky用一些漂亮的圆圈来显示cpu,时钟,内存,交换空间,硬盘信息,网络及天气信息(不需要登陆任何网站噢).而且,提供多种色彩方案供选择,带发行版标记(fedora,mint,debian,o ...

  2. ubuntu12.04+proftpd1.3.4a的系统用户+虚拟用户权限应用实践

    目录: 一.什么是Proftpd? 二.Proftpd的官方网站在哪里? 三.在哪里下载? 四.如何安装? 1)系统用户的配置+权限控制 2)虚拟用户的配置+权限控制   一.什么是Proftpd? ...

  3. mono3.2和monodevelop4.0在ubuntu12.04上两天的苦战

    首先第一步是设置ubuntu server 12.04版更新源,推荐中科大的比较快:deb http://debian.ustc.edu.cn/ubuntu/ precise main multive ...

  4. ubuntu12.04+Elasticsearch2.3.3伪分布式配置,集群状态分片调整

    目录 [TOC] 1.什么是Elashticsearch 1.1 Elashticsearch介绍 Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.能够快速搜索数 ...

  5. ubuntu12.04 gitlab搭建

    最近在尝试内部搭建gitlab,wiki这些工具...我使用的官网的gitlab-ce包一键安装,自己搭建的ubuntu12.04 server服务器. 分配253地址,放在办公室的小角落. 配置过程 ...

  6. Modelsim6.5在Ubuntu12.04的安装过程

    注:本人是在虚拟机Ubuntu12.04安装成功的,但是在虚拟机Ubuntu11.10却没有安装成功,具体原因至今未详,以后如果知道再补充吧.本博文主要的参考博文是http://blog.csdn.n ...

  7. vmware安装ubuntu12.04嵌套安装xen server(实现嵌套虚拟化)

    环境准备 软件:vmware workstation 9.0    ubuntu-12.04.2-server-amd64(官方下载) 硬件:确认CPU支持虚拟化VM-T vmware设置 vmwar ...

  8. VirtualBox中安装Ubuntu12.04/Ubuntu14.04虚拟机

    NOTE: 一开始安装的Ubuntu12.04,后来又重新安装了14.04.截图基本使用了安装12.04时的截图,后来安装14.04时又补充了几张.该安装过程对Ubuntu12.04和14.04都是适 ...

  9. ubuntu12.04下安卓编译环境搭建总结

    前言:      因为工作需要,经常要编译安卓下的动态库,公司有已经搭建好环境的服务器,但是第一自己想自己搭建一下了解一个整个过程,另外,公司的服务器也经常出现问 题,导致编译不了,所以就想自己搭建环 ...

随机推荐

  1. 第三十四课:jQuery Deferred详解2

    上一课主要分析了jQuery1.51版本的jQuery Deferred.在jQuery1.6中,jQuery Deferred添加了两个方法,always,pipe. always用来添加回调,无论 ...

  2. 关于js的string的3个函数slice,substring,substr对比

    slice,substring,substr三个函数都是截取字符串,但是对参数的处理有区别 参数处理相似的两个函数式slice和substring slice(start,end)和substring ...

  3. C头文件之<stdio.h>

    (stdio.h) 该头文件主要是执行输入输出操作.文件中重要的概念是“流”(streams).“流”在函数库中用FILE表示,用指针类型FILE *来操作.有三个标准流:stdin, stdout, ...

  4. Java web 学习之旅

    java web学习之旅 来公司十天了,感觉已经慢慢地融入了这个环境中,几个学长人都很好,都是在他们帮助下,我才能比较顺利的开始了学习java web的旅途. 来这里学习的第一个阶段是做一个简单的用户 ...

  5. Hibernate-缓存

    Hibernate是一个持久层框架,经常访问物理数据库.为了降低应用程序对物理数据源访问的频次,从而提高应用程序的运行性能.缓存内的数据是对物理数据源中的数据的复制,应用程序在运行时从缓存读写数据,在 ...

  6. Spring 使用中的设计模式

    1. 简单工厂 又叫做静态工厂方法(StaticFactory Method)模式,但不属于23种GOF设计模式之一. 简单工厂模式的实质是由一个工厂类根据传入的参数,动态决定应该创建哪一个产品类. ...

  7. GCC、Makefile编程学习

    相关学习资料 http://gcc.gnu.org/ https://gcc.gnu.org/onlinedocs/ http://zh.wikipedia.org/zh/GCC http://blo ...

  8. jQuery键盘事件绑定Enter键

    <script> $(function(){ $(document).keydown(function(event){ if(event.keyCode==13){ $("#mo ...

  9. JSP 九个隐含JSP对象

    输入输出对象:request.response.out. 作用域通信对象:session.application.pageContext servlet对象:page.config 错误对象:exce ...

  10. Emgu学习之(二)——图像读取、显示、保存

    visual Studio Community 2015 工程和源代码:http://pan.baidu.com/s/1o6u5Fdw 内容 在这篇文章中将提到以下内容: 从文件中读取图像 Image ...