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 ...
随机推荐
- Jmeter—添加断言 判断接口响应数据是否符合预期
发出请求之后,通过添加断言可以判断响应数据是否是我们的预期结果. 1 在Jmeter中发送一个状态返回200的http请求(参数故意输入错误).结果肯定是不是返回200啦. 但结果树中http请求的图 ...
- Fork/Join框架实现原理
ForkJoinPool由ForkJoinTask数组和ForkJoinWorkerThread数组组成,ForkJoinTask数组负责存放程序提交给ForkJoinPool的任务,而ForkJoi ...
- UOJ #7 【NOI2014】 购票
题目链接:购票 这道题我调了好久啊……主要还是因为这种用\(CDQ\)分治来搞斜率优化的题已经很久没写过了……上一次要追溯到去年暑假去了…… 看下面这些东西之前你需要先自己推出斜率优化的式子…… 这道 ...
- 【uoj129】 NOI2015—寿司晚宴
http://uoj.ac/problem/129 (题目链接) 题意 给出2~n这n-1个数,求选2个集合,使得从两集合中任意各选取1个数出来它们都互质.求方案数. Solution PoPoQQQ ...
- wazhu之agent功能详解
一.日志数据收集 日志数据收集是从服务器或设备生成的记录中收集的实时过程.此组件可以通过文本文件或Windows事件日志接收日志.它还可以通过远程syslog直接接收日志,这对防火墙和其他此类设备 ...
- phpmyadmin 配置方法
几乎所有的配置参数都在 config.inc.php 文件中.如果这个文件不存在,您可以在 libraries 目录中找到 config.default.php,将它复制到根目录,并改名为 confi ...
- substring()方法到底做了什么?不同版本的JDK中是否有区别?为什么?
该文章是图说Java系列文章中的一篇 substring(int beginIndex, int endIndex)方法在jdk 6和jdk 7中的实现是不同的.了解他们的区别可以帮助你更好的使用 ...
- Centos 7安装Python3.6
1> 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel ...
- 2018 CTSC&APIO 游记
CTSC 居然是CTSC先考,弄得我有些意外. 5.6 早上5:30乘坐高铁来到北京,差不多下午了吧,具体几点忘记了,然后来到宾馆 试机也没有去,就直接在宾馆颓废了. 5.7 考试的第一天,6:3 ...
- python基础之字符串格式化
python中字符串格式化有两种,一种是%,另一种是str中的format()功能. % 列举格式符 %s 字符串 %c 单个字符 %b 二进制整数 %d 十进制整数 %i ...