Add custom daemon on Linux System
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的更多相关文章
- Linux System and Performance Monitoring
写在前面:本文是对OSCon09的<Linux System and Performance Monitoring>一文的学习笔记,主要内容是总结了其中的要点,以及加上了笔者自己的一些理解 ...
- 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 ...
- 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 ...
- 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 ...
- [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 ...
- (copy) Shell Script to Check Linux System Health
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Wow! Such Doge! HDU - 4847(虽然是道水题 但很有必要记一下)
就是求出现了多少次doge 不区分大小写 巧用字符串函数 isalpha 判断是否是字母 tolower 转换为小写字母 toupper 转换为大写字母 strncmp字符串比较函数 能限制比较的 ...
- POJ 3469 Dual Core CPU Dual Core CPU
Time Limit: 15000MS Memory Limit: 131072K Total Submissions: 23780 Accepted: 10338 Case Time Lim ...
- 【BZOJ2989】数列(CDQ分治,扫描线)
[BZOJ2989]数列(CDQ分治) 题面 BZOJ 权.....权限题.. 题解 Description 给定一个长度为n的正整数数列a[i]. 定义2个位置的graze值为两者位置差与数值差的和 ...
- 面向对象高级编程(2)-使用@property
使用@property 在绑定属性时,如果我们直接把属性暴露出去,虽然写起来很简单,但是,没办法检查参数,导致可以把成绩随便改: s = Student() s.score = 9999 这显然不合逻 ...
- 前端学习 -- Css -- 兄弟元素选择器
为一个元素后边的元素设置css样式: 语法:前一个 + 后一个. 作用:可以选中一个元素后紧挨着的指定的兄弟元素. 为一个元素后边的所有相同元素设置css样式: 语法:前一个 ~ 后边所有. < ...
- 解题:POI 2009 Ticket Inspector
题面 看起来很水,然而不会DP的蒟蒻并不会做,PoPoqqq orz 设$f[i][j]$表示当前在第$i$个点和第$i+1$个点之间查票,已经查了$j$次的最大收益.然后就是那种很常见的枚举前一个结 ...
- Fibonacci数列时间复杂度之美妙
Fibonacci数列: fib(0)=1 fib(1)=1 fib(n)=fib(n-1)+fib(n-2) 上课老师出了一道题,求下列函数的时间复杂度: int fib(int d) { ) ; ...
- 初识Unity Mesh
Mesh概念:Mesh是Unity中的一个组件,称为网格组件.通俗的讲,Mesh是指模型的网格,3D模型是由多边形拼接而成,而多边形实际上是由多个三角形拼接而成的.所以一个3D模型的表面其实是由多个彼 ...
- django中的转义
什么是html转义? 所谓html转义就是将 html关键字(包括标签,特殊字符等) 进行过滤替换.过滤替换格式如下: 接下来我们通过实例演示django中转义的细节以及如何关闭转义 一 dja ...
- 利用ImageOps调整图片的Aspect Ratio(给图片添加borders)
# -*- coding: utf-8 -*- #******************** # 改变图片的纵横比(aspect retio) # 使用ImageOps.expand() # Image ...