使用命令 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. MVC上传文件示例

    [HttpPost] public void SaveFile(FormCollection form) { var c = Request.Files.Count; ]; } @using (Htm ...

  2. HTML上传文件写法

    来源于:http://www.cnblogs.com/SkySoot/p/3525139.html html 表单上传文件 一般处理程序由于没有 apsx 页面的整个模型和控件的创建周期,而比较有效率 ...

  3. at org.apache.catalina.loader.WebappClassLoader.loadClass问题处理

    在连接oracle数据库时,正常的java application可以连接,但是到javabean web中就出错,说是Class.forName(dirver)找不到驱 动,问题是,我将oracle ...

  4. oracle练习题

    题干:设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 建表后数据如下: SQL> select * from ...

  5. 【UVA 1583】Digit Generator

    题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...

  6. 修改Oracle最大连接数

    1.修改Oracle最大连接数的方法 http://my.oschina.net/shootercn/blog/11193 a.以sysdba身份登陆PL/SQL 或者 Worksheet sqlpl ...

  7. 【poj1144】 Network

    http://poj.org/problem?id=1144 (题目链接) 题意 求无向图的割点. Solution Tarjan求割点裸题.并不知道这道题的输入是什么意思,也不知道有什么意义= =, ...

  8. JAVA-基本数据类型与引用数据类型区别

    package com.liu.u6.copy1; /* * 基本数据类型与引用数据类型有什么区别 */ public class Sjlx { public int age; } package c ...

  9. Android自动化测试框架对比

    1.Monkeyrunner:优点:操作最为简单,可以录制测试脚本,可视化操作:缺点:主要生成坐标的自动化操作,移植性不强,功能最为局限:2.Rubotium:主要针对某一个APK进行自动化测试,AP ...

  10. android 事件处理概念簇

    1)事件传递函数 2)事件相关: 事件.事件源.事件监听器.MotionEvent 3)坐标系.定位.路由: 4)Window activity view viewGroup