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. [Ispc2009]Let there be rainbows!

    Description HY Star是一个处处充满和谐,人民安居乐业的星球,但是HYStar却没有被评上宇宙文明星球,很大程度上是因为星球的形象问题. HY Star由N个国家组成,并且在一些国家之 ...

  2. 【CF835D】Palindromic characteristics 加强版 解题报告

    [CF835D]Palindromic characteristics 加强版 Description 给你一个串,让你求出\(k\)阶回文子串有多少个.\(k\)从\(1\)到\(n\). \(k\ ...

  3. Windows Shell远程执行代码漏洞((CVE-2018-8414)复现

    0x00   SettingContent-ms文件介绍 .SettingContent-ms是在Windows 10中引入的一种文件类型,它的内容是XML格式进行编写的,主要用于创建Windows设 ...

  4. 前端学习 -- Css -- 属性选择器

    属性选择器:根据元素的属性选择指定元素 语法:[属性名] 选取含有指定属性的元素 [属性名="属性值"]:选取属性值等于指定值的元素 [属性名^="属性值"]: ...

  5. Android中的Surface, SurfaceHolder, SurfaceHolder.Callback, SurfaceView

    传入一个surface,然后让openGL在surface上画图 window->view hierachy(DecorView是tree的root)->ViewRoot->Surf ...

  6. 解题:SCOI 2008 配对

    题面 如果没有两个数不能相同这个限制就两个数组排序后贪心即可.现在加上这个限制,注意到每个数组中的数是两两不同的,所以每次一定能在前面或后面一个数中找一个换过来,这样每次考虑相邻三个数转移就可以了,注 ...

  7. 【整体二分】【P3834】 【模板】可持久化线段树 1(主席树)

    Description 给定一个长度为 \(n\) 的序列, \(m\) 次操作静态查询区间第 \(k\) 大 Input 第一行是 \(n,m\) 下一行描述这个序列 下面 \(m\) 行描述操作 ...

  8. 【贪心】【CF1061D】 TV Shows

    Description 给定 \(n\) 个电视节目和两个参数 \(x,y\).你想要看全部的电视节目,但是同一个电视机同一个时刻只能播放一个电视节目,所以你只能多租赁电视机.在时间 \([l,r]\ ...

  9. golang简单实现二叉树的数据添加和遍历

    代码实现 package tree import "fmt" type Node struct { elem interface{} left, right *Node } typ ...

  10. C++下实现同接口下多个类作为参数的调用和传参

    /* 实现同接口下不同类的对象的转移 定义类的接口 定义多个继承该接口的类 定义管理类,把接口当作类型, 传入该接口下各种类的对象,进行操作 */ #include<iostream> # ...