OSDN Git Service

release 0.6.3-2 (typo)
[pysilhouette/pysilhouette.git.git] / doc / rc.d / init.d / silhouetted
1 #!/bin/bash
2 #
3 # silhouetted  The startup script for the Pysilhouette system.
4 #
5 # chkconfig: 2345 97 03
6 # description: Pysilhouette is an application running in the background system.
7 #
8 # processname: silhouetted
9 # config: /etc/sysconfig/silhouetted
10 # pidfile: /var/run/silhouetted.pid
11 #          /var/run/schedulerd.pid
12 #          /var/run/performerd.pid
13 # lockfile: /var/lock/subsys/silhouetted
14 #           /var/lock/subsys/schedulerd
15 #           /var/lock/subsys/performerd
16
17 source /etc/rc.d/init.d/functions
18 source /etc/sysconfig/network
19
20 # For SELinux we need to use 'runuser' not 'su'
21 if [ -x /sbin/runuser ]; then
22     SU=runuser
23 else
24     SU=su
25 fi
26
27 # Check that networking is up.
28 [ ${NETWORKING} = "no" ] && exit 1
29
30 #Default value
31 prog="silhouette"
32 progd="silhouetted"
33 app="pysilhouette"
34 sch_progd='schedulerd'
35 per_progd='performerd'
36
37 sysconfig="/etc/sysconfig/${progd}"
38
39 # Read configuration
40 [ -r "${sysconfig}" ] && source "${sysconfig}"
41
42 if [ "x${PYTHON}" == "x" ]; then
43   PYTHON=`which python`
44 fi
45
46 # Config file.
47 conf="/etc/opt/${app}/${prog}.conf"
48
49 # Process id file.
50 pidfile="/var/run/${progd}.pid"
51 lockfile="/var/lock/subsys/${progd}"
52 sch_pidfile="/var/run/${sch_progd}.pid"
53 sch_lockfile="/var/lock/subsys/${sch_progd}"
54 per_pidfile="/var/run/${per_progd}.pid"
55 per_lockfile="/var/lock/subsys/${per_progd}"
56
57 # Daemon mode.
58 extra_args=""
59 if [ "x${DAEMON}" = "xyes" ]; then
60     extra_args=${extra_args}" -d"
61 fi
62
63 # Debug mode.
64 if [ "x${DEBUG}" = "xyes" ]; then
65     extra_args=${extra_args}" -v"
66 fi
67
68 desc="${progd} (Daemon)"
69
70 # options
71 CMD_ARGS="-p ${pidfile} -c ${conf} ${extra_args}"
72
73
74 start() {
75     echo -n $"Starting $desc: "
76     if [ -e ${pidfile} ]; then
77             echo "already running..."
78             return 1
79     fi
80
81     touch ${pidfile} ${sch_pidfile} ${per_pidfile}
82     chown ${USER}:${GROUP} ${pidfile} ${sch_pidfile} ${per_pidfile}
83     if [ "x${PYTHON_SEARCH_PATH}" != "x" ]; then
84         env="PYTHONPATH=${PYTHON_SEARCH_PATH}:\$PYTHONPATH"
85     fi
86     ${SU} -l ${USER} -c "${env} ${PYTHON} ${PREFIX}/opt/pysilhouette/bin/${prog}.py ${CMD_ARGS}"
87     RETVAL=$?
88     if [ ${RETVAL} -eq 0 ]; then
89         touch ${lockfile} ${sch_lockfile} ${per_lockfile}
90         success
91     else
92         failure 
93         stop
94     fi
95     echo ""
96     return ${RETVAL} 
97 }
98
99 silhouetted_stop() {
100     echo -n $"Shutting down $desc: "
101     if [ ! -e ${pidfile} ]; then
102         echo "not running..."
103         return 1
104     fi
105     pid=`cat ${pidfile}`
106     if [ "x${pid}" == "x" ]; then
107         echo "not running... - not pid"
108         rm -f ${pidfile}
109         return 1
110     fi
111     killproc -p ${pidfile} -15
112     echo
113     RETVAL=$?
114     return ${RETVAL}
115 }
116
117 stop() {
118     silhouetted_stop
119     SIL_RETVAL=$?
120     if [ ${SIL_RETVAL} -eq 0 ]; then
121         rm -f ${lockfile}
122         rm -f ${pidfile}
123     fi  
124     eval "/etc/rc.d/init.d/${sch_progd} stop"
125     SCH_RETVAL=$?
126     if [ ${SCH_RETVAL} -eq 0 ]; then
127         rm -f ${sch_lockfile}
128         rm -f ${sch_pidfile}
129     fi  
130     eval "/etc/rc.d/init.d/${per_progd} stop"
131     PER_RETVAL=$?
132     if [ ${PER_RETVAL} -eq 0 ]; then
133         rm -f ${per_lockfile}
134         rm -f ${per_pidfile}
135     fi  
136     # The return code of the performer daemon is the first digit. 
137     # The return code of the scheduler daemon is the second digit. 
138     # The return code of the silhouetted daemon is the third digit. 
139     # All stop functions return only the exit code of 0(Normal) or 1(Abnormal).
140     RETVAL=`expr ${SIL_RETVAL} \* 100 + ${SCH_RETVAL} \* 10 + ${PER_RETVAL}`
141     return ${RETVAL}
142 }
143
144 restart() {
145     stop
146     sleep 1
147     start
148 }
149
150
151 case "$1" in
152     start)
153         start
154         ;;
155     stop)
156         stop
157         ;;
158     restart|reload)
159         restart
160         ;;
161     condrestart)
162         [ -e ${lockfile} ] && restart
163         RETVAL=$?
164         ;;
165     status)
166         status ${progd}
167     eval "/etc/rc.d/init.d/${sch_progd} status"
168     eval "/etc/rc.d/init.d/${per_progd} status"
169         RETVAL=$?
170         ;;
171     *)
172         echo $"Usage: $0 {start|stop|restart|condrestart|status}"
173         RETVAL=1
174 esac
175
176 exit $RETVAL