-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneric
More file actions
160 lines (147 loc) · 4.99 KB
/
Copy pathGeneric
File metadata and controls
160 lines (147 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/sh
#
# WebKit application server
# part of Webware for Python
# www.webwareforpython.org
#
# /etc/init.d/webkit
#
# Generic init.d shell start script for Unix
#
# Note: You will find more sophisticated start scripts
# for various Unix flavors in the StartScripts folder.
#
# START LOCAL CONFIGURATION
# If you store this script in your Webware working directory
# and create a symlink to it as /etc/init.d/webkit_appname,
# it will try to guess your configuration parameters. Otherwise
# you need to hard code the path to the working directory here.
# You can make changes either directly here in the start script or
# you can also override the configuration in the Launch.py script.
# The location and name of the start sript:
START_SCRIPT="$0"
APP_NAME=`basename "$START_SCRIPT"`
if [ -h "$START_SCRIPT" ]; then
# Get the target file if start script is given as a link:
START_SCRIPT=`echo "import os;p='$START_SCRIPT'
while os.path.islink(p):
p = os.path.join(os.path.dirname(p), os.readlink(p))
print p" | python`
fi
# The location of the working directory:
WORK_DIR=`dirname "$START_SCRIPT"`
if [ "$WORK_DIR" = "/etc/init.d" ]; then
# Put hard coded path to working directory here:
WORK_DIR="."
fi
# Make sure to have the absolute path:
test -d "$WORK_DIR" || exit 5
WORK_DIR=`cd "$WORK_DIR" 2>/dev/null && pwd`
# The app server launch script:
APP_SERVER="$WORK_DIR/AppServer"
test -x "$APP_SERVER" || exit 5
# The WebKit app server log file
# (you can set this in Launch.py as well):
#LOG_FILE="/var/log/$APP_NAME.log"
LOG_FILE="$WORK_DIR/Logs/webkit.log"
# Use this extension if you want to move the last log away
# (also consider using logrotate or something similar):
LOG_OLD=".old"
# The app server process id file
# (you can set this in Launch.py as well):
#PID_FILE="/var/run/$APP_NAME.pid"
PID_FILE="$WORK_DIR/webkit.pid"
# The user to run the app server
# (you can set this in Launch.py as well).
# If undefined, it will be the user
# running the start script (usually root).
# You should use a low-privilege account,
# like the work dir owner, wwwrun or nobody.
# This will use the owner of the AppServer script:
WEBWARE_USER=`echo "import os,pwd;
print pwd.getpwuid(os.stat('$APP_SERVER')[4])[0]" | python`
# Unset the following variable if you want to store the
# pid and log files as the user running the start script
# (usually root) or set it if you want these files to be
# written after switching to the WEBWARE_USER.
LAUNCH_AS_WEBWARE="yes"
# Additional options -u or -O to be passed on to Python:
PYTHONOPTS=
# Additional libraries to be included in the Python path:
PYTHONPATH=
export PYTHONPATH
# END LOCAL CONFIGURATION
case "$1" in
start)
printf "Starting $APP_NAME ... "
# Keep backup of last log file:
if [ "$LOG_OLD" -a -f "$LOG_FILE" ]; then
if [ -s "$LOG_FILE" ]; then
mv -f "$LOG_FILE" "$LOG_FILE$LOG_OLD"
else
rm -f "$LOG_FILE"
fi
fi
# Check if the server is already running:
if [ -f "$PID_FILE" ] ; then
PID=`cat "$PID_FILE"`
if [ "$PID" ]; then
# Check on the command line if it is really our pid file
# (MacOs has only "command", SunOS has only "args"):
if (ps -o command= -p $PID 2>/dev/null \
|| ps -o args= -p $PID 2>/dev/null) \
| grep -q " -i $PID_FILE "; then
echo "already running"
exit 0
fi
fi
rm -f "$PID_FILE"
fi
if [ -z "$WEBWARE_USER" -o "$WEBWARE_USER" = "$USER" ]; then
"$APP_SERVER" $PYTHONOPTS -i "$PID_FILE" \
-d "$WORK_DIR" -o "$LOG_FILE" > /dev/null &
else
if [ "$LAUNCH_AS_WEBWARE" ]; then
# Switch user first, then create pid and log files:
CMD="\"$APP_SERVER\" $PYTHONOPTS"
CMD="$CMD -i \"$PID_FILE\" -d \"$WORK_DIR\" -o \"$LOG_FILE\""
su $WEBWARE_USER -c "$CMD" > /dev/null &
else
# Create pid and log files first, then switch user:
"$APP_SERVER" $PYTHONOPTS -i "$PID_FILE" \
-d "$WORK_DIR" -u $WEBWARE_USER >> "$LOG_FILE" 2>&1 &
fi
fi
echo "done"
;;
stop)
printf "Stopping $APP_NAME ... "
if [ -f "$PID_FILE" ] ; then
PID=`cat "$PID_FILE"`
if [ "$PID" ]; then
if (ps -o command= -p $PID 2>/dev/null \
|| ps -o args= -p $PID 2>/dev/null) \
| grep -q " -i $PID_FILE "; then
if kill $PID > /dev/null 2>&1 ; then
echo "done"
else
echo "error"
echo "Could not kill process $PID named in $PID_FILE"
exit 1
fi
else
echo "not running (removing stale pid file)"
fi
else
echo "not running (removing empty pid file)"
fi
rm -f "$PID_FILE"
else
echo "not running"
fi
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac