updated on Sun Jan 22 12:09:12 UTC 2012
[aur-mirror.git] / ovz-web-panel / owp
blob0060147b8f029da415ebf52e088ed52585419887
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
6 ruby="ruby-1.8"
7 daemon=owp
8 LOG="/var/log/owp.log"
10 if [ -f `dirname $0`/../script/owp ]; then
11 INSTALL_DIR=`dirname $0`/../
12 else
13 INSTALL_DIR="/opt/ovz-web-panel"
16 PORT=3000
17 IP=0.0.0.0
18 SSL=off
19 LOCK_FILE=/var/lock/owp
21 [ -f /etc/owp.conf ] && . /etc/owp.conf
23 check_environment() {
24 if [ -f /proc/vz/version ]; then
25 ENVIRONMENT="HW-NODE"
26 else
27 ENVIRONMENT="STANDALONE"
31 start() {
32 if [ -f $LOCK_FILE ]; then
33 stat_fail "OpenVZ Web Panel is already running!"
34 else
35 stat_busy "Starting OpenVZ Web Panel Server"
36 $ruby $INSTALL_DIR/utils/watchdog/watchdog.rb start &>>$LOG
37 if [ "x$SSL" = "xon" ]; then
38 $ruby $INSTALL_DIR/script/server_ssl webrick -e production -p $PORT -b $IP -d &>>$LOG
39 else
40 $ruby $INSTALL_DIR/script/server webrick -e production -p $PORT -b $IP -d &>>$LOG
42 [ "$ENVIRONMENT" = "HW-NODE" ] && $ruby $INSTALL_DIR/utils/hw-daemon/hw-daemon.rb start &>>$LOG && \
43 touch $LOCK_FILE
44 sleep 1 # wait a little for forked processes
45 echo "Syncing physical servers state..." &>>$LOG
46 $ruby $INSTALL_DIR/script/runner -e production "HardwareServer.all.each { |server| server.sync }" &>>$LOG
47 if [ -f $LOCK_FILE ]; then
48 add_daemon $daemon
49 stat_done
50 else
51 stat_fail
56 stop() {
57 stat_busy "Stopping OpenVZ Web Panel server"
58 PANEL_APP_PID=`ps auxww | grep $ruby | grep script/server | awk '{ print $2 }'`
59 [ -n "$PANEL_APP_PID" ] && kill -2 $PANEL_APP_PID
60 [ "$ENVIRONMENT" = "HW-NODE" ] && $ruby $INSTALL_DIR/utils/hw-daemon/hw-daemon.rb stop &>>$LOG && \
61 $ruby $INSTALL_DIR/utils/watchdog/watchdog.rb stop &>>$LOG && \
62 rm -f $LOCK_FILE
63 if [ ! -f $LOCK_FILE ]; then
64 rm_daemon $daemon
65 stat_done
66 else
67 stat_fail
71 status() {
72 $ruby $INSTALL_DIR/utils/watchdog/watchdog.rb status
74 if [ -f $LOCK_FILE ]; then
75 echo "OpenVZ Web Panel is running!"
76 exit 0
77 else
78 echo "OpenVZ Web Panel is NOT running!"
79 exit 1
83 # main()
84 check_environment
85 case "$1" in
86 start)
87 start
89 stop)
90 stop
92 status)
93 status
95 restart|reload|condrestart)
96 stop
97 start
100 echo $"Usage: $0 {start|stop|restart|reload|status}"
101 exit 1
102 esac
104 exit 0