Supervisord requires that the programs it is configured to run don’t daemonize themselves. Instead, they should run in the foreground and respond to the stop signal (TERM by default) by properly shutting down.

Use Following shell script to wrapper your background program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
# run something background
./run &
# get nearest running background pid
$PID=$!
# Perform program exit housekeeping
function clean_up {
# dosomething for cleanup
rm -rf dump_file
# remove trap
trap - SIGHUP SIGINT SIGTERM SIGQUIT SIGKILL
exit $?
}
# Add trap for catch sistem signal
trap clean_up SIGHUP SIGINT SIGTERM SIGQUIT SIGKILL
wait $PID

Comment and share

Upstart 筆記

in linux

Table of Contents

傳統init.d的取代方案,比init.d好寫很多
http://upstart.ubuntu.com/index.html

1 Example

開機時(有網路連接狀態)自動啟動Gunicorn,Crash時自動重啟,關機時關閉
將以下檔案放到/etc/init/gunicorn-superlists-staging.ottg.eu.conf

description "Gunicorn server for superlists-staging.ottg.eu"

start on net-device-up #start after net OK
stop on shutdown

respawn #restart if crash

setuid elspeth #user
chdir /home/elspeth/sites/superlists-staging.ottg.eu/source #working directory

#execute command
exec ../virtualenv/bin/gunicorn \
--bind unix:/tmp/superlists-staging.ottg.eu.socket \
--access-logfile ../access.log \
--error-logfile ../error.log \
superlists.wsgi:application

2 Command

sudo start gunicorn-superlists-staging.ottg.eu
sudo stop gunicorn-superlists-staging.ottg.eu
sudo restart gunicorn-superlists-staging.ottg.eu
Last Updated 2017-03-10 五 10:26.
Render by hexo-renderer-org with Emacs 25.2.1 (Org mode 8.2.10)

Comment and share

Cwza

Hello everyone.
I’m cwza.
Welcome to my blog.


Software Engineer


Taiwan/Taipei