source: mailjam/bin/rc.d/mailjam@ 32:43c12f3bc1bd

Last change on this file since 32:43c12f3bc1bd was 32:43c12f3bc1bd, checked in by Borja Lopez <borja@…>, 12 years ago

Added an init/rc.d script to manage the start/stop/restart actions related
to the mailjam daemon (more info in ticket #5)

  • Property exe set to *
File size: 2.7 KB
Line 
1#!/bin/sh
2#
3# Generic init.d/rc.d script to invoke mailjam daemon properly
4#
5# Use this only if there is no specific startup script for your OS
6#
7# This file is released under the BSD license, see LICENSE for
8# more information.
9#
10# Francisco de Borja Lopez Rio - <borja@codigo23.net>
11# Soluciones Informaticas Codigo23 S.L.U. - http://codigo23.net
12#
13
14mailjam_bin_path=/usr/local/bin
15mailjam_server=${mailjam_bin_path}/mailjam-server
16# check if that binary exists, if not, try to find where it is
17if [ ! -x "${mailjam_server}" ]
18then
19 mailjam_server=`which mailjam-server`
20fi
21
22#mailjam_etc_path=/usr/local/etc
23mailjam_etc_path=/Users/wu/codigo23/devel_python/MailingList/osx/env/etc
24mailjam_conf=${mailjam_etc_path}/mailjam.conf
25
26access_log=`grep accesslog etc/mailjam.conf |cut -f 2 -d '='|sed 's/^[ \t]*//'`
27pidfile=/tmp/mailjam.pid
28
29rm=`which rm`
30# pgrep=`which pgrep`
31pkill=`which pkill`
32kill=`which kill`
33killall=`which killall`
34
35usage() {
36 echo "Usage: $0 [ start|stop|restart ]"
37}
38
39start_mailjam_server() {
40 echo "Starting Mailjam daemon"
41 if [ -x "${mailjam_server}" ]
42 then
43 if [ -f "${mailjam_conf}" ]
44 then
45 ${mailjam_server} -c ${mailjam_conf} > ${access_log} 2>&1 &
46 else
47 ${mailjam_server} > ${access_log} 2>&1 &
48 fi
49 # save the pidfile
50 echo $! > ${pidfile}
51 else
52 echo "ERROR - mailjam-server not found"
53 fi
54}
55
56check_then_start_mailjam_server() {
57 # check if there is another daemon running, call the start function
58 # if needed
59 if [ -f "${pidfile}" ]
60 then
61 mailjam_pid=`head -n 1 ${pidfile}|cut -f 1 -d " "`
62 ps -p ${mailjam_pid} > /dev/null
63 if [ $? -eq 0 ]
64 then
65 echo "Another mailjam server is already running (pid ${mailjam_pid})"
66 else
67 start_mailjam_server
68 fi
69 else
70 start_mailjam_server
71 fi
72}
73
74stop_mailjam_server() {
75 echo "Stopping Mailjam daemon"
76 if [ -f "${pidfile}" ]
77 then
78 # if there is a pidfile, try to kill the process by its pid
79 ${kill} -15 `head -n 1 ${pidfile}|cut -f 1 -d " "`
80 ${rm} ${pidfile}
81 else
82 # if there is no pidfile, try to locate the pid and kill it.
83 # FIXME: This will not work if the process is not "mailjam-server"
84 # but "python mailjam-server"
85 if [ -x "${pkill}" ]
86 then
87 ${pkill} -15 ${mailjam_server}
88 else
89 if [ -x "${killall}" ]
90 then
91 ${killall} -15 "${python_path} ${mailjam_server}"
92 else
93 echo "ERROR - can't stop the mailjam server"
94 fi
95 fi
96 fi
97}
98
99case "$1" in
100 'start')
101 check_then_start_mailjam_server
102 ;;
103 'stop')
104 stop_mailjam_server
105 ;;
106 'restart')
107 stop_mailjam_server
108 sleep 2
109 start_mailjam_server
110 ;;
111 *)
112 usage
113esac
Note: See TracBrowser for help on using the repository browser.