使用命令 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. JavaScript基础系列目录(2014.06.01~2014.06.08)

    下列文章,转载请亲注明链接出处,谢谢! 链接地址: http://www.cnblogs.com/ttcc/tag/JavaScript%20%E5%9F%BA%E7%A1%80%E7%9F%A5%E ...

  2. c# 关于浅拷贝和深拷贝

    class Program { static void Main(string[] args) { //浅拷贝 Person p1 = new Person(); p1.Name = "张三 ...

  3. redmine邮件发送功能配置详解

    redmine的邮件发送功能还是很有用的.像项目有更新啦,任务分配啦,都能邮件发送的相关责任人.我自己在linux服务器上安装并启动了redmine后,邮件一直发送了不了.查了网上的资料,都是讲修改下 ...

  4. [Linux主机] 优化你的php-fpm(php5.3+)让你的网站跑得更快

    从php5.3以后php自带了php-fpm不是和php5.2一样以插件的方式存在了.这给我们带来一个好处502没有那么容易出现了坛子里用linux的绝大多数应该还是在用小军的lnmp的那个包,但是配 ...

  5. G-nav-04

    'use strict';define([ 'jquery'], function($) { var nav = { init : function() { $("#burger-menu& ...

  6. Linux中使用crontab命令定时执行shell脚本或其他Linux命令

    使用crontab你可以在指定的时间执行一个shell脚本或者一系列Linux命令.例如系统管理员安排一个备份任务使其每天都运行 如何往 cron 中添加一个作业? # crontab –e0 5 * ...

  7. 【BZOJ 1013】【JSOI2008】球形空间产生器sphere 高斯消元基础题

    最基础的高斯消元了,然而我把j打成i连WA连跪,考场上再犯这种错误就真的得滚粗了. #include<cmath> #include<cstdio> #include<c ...

  8. BZOJ2121 字符串游戏

    Description BX正在进行一个字符串游戏,他手上有一个字符串L,以及其 他一些字符串的集合S,然后他可以进行以下操作:对于一个在集合S中的字符串p,如果p在L中出现,BX就可以选择是否将其删 ...

  9. CODEVS 1258 关路灯

    写动归终于能不看题解一次A了!(其实交了两次,一次80一次A) 我练功发自真心! 题目描述 Description 多瑞卡得到了一份有趣而高薪的工作.每天早晨他必须关掉他所在村庄的街灯.所有的街灯都被 ...

  10. UvaLive 5026 Building Roads

    传送门 Time Limit: 3000MS Description There is a magic planet in the space. There is a magical country ...