Ubuntu add custom service(daemon)

Task

需要在系统启动的时候自动启动一个服务(后台程序),在系统关闭的时候关闭服务。

比如在部署某个应用之前,需要将某个任务设置成后台程序(daemon),而这些* 任务 *可以是Liunx command, 或者自己写的脚本。

比如在部署我的Django应用之前,需要启动MQ服务,一种可能的方式是:需要执行python manage.py runMQServer

Why dont use /etc/init.d

/etc/init.d是陈旧的方式,目前已经被淘汰,取而代之的是upstart

使用upstart方式添加后台程序配置更容易

/etc/init/run_mq.conf

以task中的需求为例,创建daemon的配置文件run_mq.conf:

# TMS MQ Service

description "TMS message queue server"
author "xxx <xxx@xxx.com>" #the job is started automatically when the machine is first started (without writable filesystems or networking).
start on startup #the job is stoped automatically when the machine is shut down
stop on shutdown #a job that exits quietly transitions into the stop/waiting state, no matter how it exited.
respawn #respawn the job up to 2 times within a 5 second period.
#If the job exceeds these values, it will be stopped and
#marked as failed.
respawn limit 2 5 #controls where a job's output goes, and where its input comes from
console ouput #additional shell code can be given to be run before the binary or script,it is intended for preparing the environment
pre-start script
#prepare environment
end script script
if [ -f /home/tms/TMS/tmsApp/management/commands/runMSGServer.py ]; then
python /home/tms/TMS/manage.py runMSGServer
fi
end script #additional shell code can be given to be run after the binary or script,it is intended for cleaning up afterwards
post-stop script
#clean up or else
logger "TMS message queue server started..."
end script

references

How to correctly add a custom daemon to init.d?

Upstart getting started

Add custom daemon on Linux System的更多相关文章

  1. Linux System and Performance Monitoring

    写在前面:本文是对OSCon09的<Linux System and Performance Monitoring>一文的学习笔记,主要内容是总结了其中的要点,以及加上了笔者自己的一些理解 ...

  2. Add custom and listview web part to a page in wiki page using powershell

    As we know, Adding list view web part is different from custom web part using powershell, what's mor ...

  3. The type 'Expression<>' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

    在我将一个.net framework 4.0+mvc4+ef5的项目,升级到.net framework 4.6.1+mvc5+ef6之后,解决了所有的升级带来的问题,唯独在razor的cshtml ...

  4. Howto Reboot or halt Linux system in emergency (ZT)

    http://www.cyberciti.biz/tips/reboot-or-halt-linux-system-in-emergency.html Linux kernel includes ma ...

  5. [webgrid] – header - (How to Add custom html to Header in WebGrid)

    How to Add custom html to Header in WebGrid MyEvernote Link Posted on March 30, 2013by mtryambake Ho ...

  6. (copy) Shell Script to Check Linux System Health

    source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...

  7. The frequent used operation in Linux system

    The frequently used operation in Linux system    2017-04-08 12:48:09  1. mount the hard disk:  #: fd ...

  8. How To Add Custom Build Steps and Commands To setup.py

    转自:https://jichu4n.com/posts/how-to-add-custom-build-steps-and-commands-to-setuppy/ A setup.py scrip ...

  9. The package 'MySql.Data' tried to add a framework reference to 'System.Runtime' which was not found in the GAC

    最近在学习Visual Studio连接mysql EF模型.在nuget中安装mysql.data时总是提示The package 'MySql.Data' tried to add a frame ...

随机推荐

  1. 【2018CCPC秦皇岛】

    递推式的线段树可以用矩阵维护.

  2. wazuh官方安装指南(中文译版本)

      安装Wazuh服务器 Wazuh服务器可以安装在任何类型的Unix操作系统上.最常见安装在Linux上.如果可以为您的系统提供自动化脚本,则安装过程会更容易,但是,从源码构建和安装也非常简单. 通 ...

  3. 针对Weblogic测试的一些小总结(转)

    1. 管理员登录页面弱密码 Weblogic的端口一般为7001,弱密码一般为weblogic/Oracle@123 or weblogic,或者根据具体情况进行猜测,公司名,人名等等,再有就可以用b ...

  4. Android Studio自动生成UML关系类图

    android studio 根据源码自动生成UML的插件介绍http://www.jianshu.com/p/cbccd831cf01 simpleumlhttps://plugins.jetbra ...

  5. python之旅:函数对象、函数嵌套、名称空间与作用域、装饰器

    一 函数对象 一 函数是第一类对象,即函数可以当作数据传递 #1 可以被引用 #2 可以当作参数传递 #3 返回值可以是函数 #3 可以当作容器类型的元素 二 利用该特性,优雅的取代多分支的if de ...

  6. PyPt5 浏览器实例

    title: PyPt5 浏览器实例 date: 2018-02-02 13:40:03 tags: Python PyQt5 便携浏览器 categries: Python --- 导入包 pyQt ...

  7. go数据类型之基本类型

    基本数据类型 数值型 整数 int 64位操作系统默认为int64,32位操作系统为int32,但是类型检查时时int int8 (byte 1字节) int16 (short 2字节) int32 ...

  8. Spring MVC使用Cors实现跨域

    在开发APP过程中,APP调用后端接口有跨域的问题,只要在spring-mvc.xml 文件中加入下面的配置即可: <!-- 解决API接口跨域问题配置 Spring MVC 版本必须是 4.2 ...

  9. js子节点children和childnodes的用法

    想要获取子节点的数量,有几种办法. childNodes 它会把空的文本节点当成节点, <ul> 文本节点 <li>元素节点</li> 文本节点 <li> ...

  10. R语言的ARIMA模型预测

    R通过RODBC连接数据库 stats包中的st函数建立时间序列 funitRoot包中的unitrootTest函数检验单位根 forecast包中的函数进行预测 差分用timeSeries包中di ...