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

Linux跟環境變數有關的檔案有兩個
/etc/profile
/etc/bashrc

理論上來說/etc/profile已是全域環境變數
但若是使用非互動式bash(程式大部分會用這個)
則會用到/etc/bashrc檔案

未免麻煩兩個都加就是了

profile, bashrc
1
2
JAVA_HOME=/usr/java/jdk1.7.0_55
PATH=$PATH:$JAVA_HOME/bin/

Comment and share

Cwza

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


Software Engineer


Taiwan/Taipei