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 ...
随机推荐
- SpringBoot 中使用redis以及redisTemplate
1.首先在pom.xml中添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <art ...
- Kotlin入门简介
Kotlin的“简历” 来自于著名的IDE IntelliJ IDEA(Android Studio基于此开发) 软件开发公司 JetBrains(位于东欧捷克) 起源来自JetBrains的圣彼得堡 ...
- 解题:ZJOI 2015 幻想乡战略游戏
题面 神**所有点都爆int,我还以为我写出什么大锅了,不开long long见祖宗... 动态点分治利用点分树树高不超过log的性质,我们对每个点维护一个子树和,一个点分树子树和,一个点分树上父亲的 ...
- struts的问题
将SSH框架进行整合的时候,将三者的jar包加入到lib下面,然后测试struts,结果页面显示不出来报404错误,可是路径没有问题 找到罪魁祸首是:原因两个:(1)在未用到spring的时候,先不要 ...
- poj 3294 后缀数组 多字符串中不小于 k 个字符串中的最长子串
Life Forms Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16223 Accepted: 4763 Descr ...
- IAR ------- 在线调试技巧
调试模式下,右击某一行选“Set Next Statement”,可以不执行中间程序,执行点直接到此行,用于不执行某些代码.
- 【Asp.net入门05】第一个ASP.NET 应用程序-测试Asp.net程序
测试示例应用程序 本部分内容: ASP.NET应用程序测试方法 web窗体访问过程 Visual Studio工具栏上有一个下拉列表,其中列出了工作站上已安装的浏览器的名称(单击浏览器名称右侧的向下箭 ...
- my-innodb-heavy-4G.cnf配置文件注解
[client] ####客户端 port = 3306 ####mysql客户端连接时的默认端口号 socket = /application/mysql-5.5.32/tmp/mysql.sock ...
- Excel批量删除换行符_clean函数
http://jingyan.baidu.com/article/e2284b2b489b96e2e6118d30.html CLEAN函数,用于删除文本中不能打印的字符.对从其他应用程序中输入的文本 ...
- 学习Oracle的一些收获
前言: 在看尚硅谷的Oracle视频时,总结的一些自己之前不熟的,或者完全不了解的知识点,只适用于本人,本人有一定的SQL基础,所以一些我比较熟悉的知识点不会列出来. Oracle中SQL使用技巧: ...