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 ...
随机推荐
- 【转】ubuntu16.04安装ncurses-devel
在ubuntu16.04中编译内核时,使用make menuconfig发生错误,说没有安装ncurses-devel. 使用apt install ncurses-devel命令安装该库,没有,然后 ...
- BZOJ3522 [Poi2014]Hotel 【树形dp】
题目链接 BZOJ3522 题解 就是询问每个点来自不同子树离它等距的三个点的个数 数据支持\(O(n^2)\),可以对每个距离分开做 设\(f[i][j]\)表示\(i\)的子树中到\(i\)距离为 ...
- 【codeforces 235E】 Number Challenge
http://codeforces.com/problemset/problem/235/E (题目链接) 题意 给出${a,b,c}$,求${\sum_{i=1}^a\sum_{j=1}^b\sum ...
- listview android:cacheColorHint,android:listSelector属性作用(转)
ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景图片,或者背景颜色时,滚动时listView会黑掉, 原因是,滚动时,列表里面的view重绘时,用的依 ...
- C/C++ 移位计算代替乘除运算
测试移位和乘除的比较,发现移位比乘除运算快一个位数的速度,但是难点在于判断是否是2的幂次级的数,如果不是还得通过代码拆分到2的幂次+上分子的累和,然后通过移位得到2的次幂数这样; 下列代码只是简单的判 ...
- Java入门:绘制简单图形
在上一节,我们学习了如何使用swing和awt工具创建一个空的窗口,本节学习如何绘制简单图形. 基本绘图介绍 Java中绘制基本图形,可以使用Java类库中的Graphics类,此类位于java.aw ...
- Writing Genres 英文文章文体
Description 描述文 It is painting a picture in words of a person, place, object, or scene. narration 记 ...
- Tomcat权威指南-读书摘要系列2
2. 配置Tomcat 2.1. 重定向Web应用程序的目录 将工程文件与Tomcat分离 复制conf和webapps文件夹到分离目录: 配置CATALINA_BASE环境变量,值为分离目录: 2. ...
- bzoj千题计划171:bzoj2456: mode
http://www.lydsy.com/JudgeOnline/problem.php?id=2456 任意删除序列中两个不同的数,众数仍然是众数 不停的删,剩下的最后的数一定是众数 具体实现: 记 ...
- 20155315 2016-2017-2 《Java程序设计》第五周学习总结
教材学习内容总结 第8章 异常处理 1.使用try...catch 与C语言中程序流程和错误处理混在一起不同,Java中把正常流程放try块中,错误(异常)处理放catch块中. 如果父类异常对象在子 ...