Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 708 lines (561 sloc) 18.801 kB
8bcefee @alobbs Initial import
alobbs authored
1 #!/usr/bin/env python
2
3 # -*- coding: utf-8 -*-
4 #
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
5 # Cherokee easy-install script
8bcefee @alobbs Initial import
alobbs authored
6 #
7 # Authors:
8 # Alvaro Lopez Ortega <alvaro@alobbs.com>
9 #
10 # Copyright (C) 2001-2011 Alvaro Lopez Ortega
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of version 2 of the GNU General Public
14 # License as published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 # 02110-1301, USA.
25 #
26
27 import re
28 import os
29 import sys
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
30 import glob
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
31 import time
32 import stat
8bcefee @alobbs Initial import
alobbs authored
33 import subprocess
34
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
35 BUILD_DIR = "/var/tmp/cherokee-build"
36 URL_LATEST_RELEASE = "http://www.cherokee-project.com/cherokee-latest-tarball"
37 URL_SNAPSHOT_RELEASE = "http://www.cherokee-project.com/download/trunk/cherokee-latest-svn.tar.gz"
d625433 @alobbs Add a new --devel mode
alobbs authored
38 PREFIX_STANDARD = "/opt/cherokee"
39 PREFIX_DEVEL = "/opt/cherokee-dev"
8bcefee @alobbs Initial import
alobbs authored
40
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
41 PHASE_DOWNLOAD = 1
42 PHASE_UNPACK = 2
43 PHASE_COMPILE = 3
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
44 PHASE_INSTALL = 4
45 PHASE_INITD = 5
46 PHASE_REPORT = 6
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
47
48
49 # Texts
50 #
51 LAUNCHD_PLIST = """\
52 <?xml version="1.0" encoding="UTF-8"?>
53 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
54 <plist version="1.0">
55 <dict>
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
56 <key>Label</key><string>org.cherokee.webserver</string>
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
57 <key>RunAtLoad</key><true/>
58 <key>ProgramArguments</key><array>
d625433 @alobbs Add a new --devel mode
alobbs authored
59 <string>%(prefix)s/sbin/cherokee</string>
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
60 </array>
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
61 <key>UserName</key>
62 <string>root</string>
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
63 </dict>
64 </plist>
65 """
66
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
67 SOLARIS_SVC = """\
68 <?xml version="1.0"?>
69 <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
70
71 <service_bundle type='manifest' name='cherokee'>
72 <service name='network/http' type='service' version='1'>
73 <instance name='cherokee' enabled='true'>
74
75 <dependency name='loopback' grouping='require_all' restart_on='error' type='service'>
76 <service_fmri value='svc:/network/loopback:default'/>
77 </dependency>
78
79 <dependency name='physical' grouping='optional_all' restart_on='error' type='service'>
80 <service_fmri value='svc:/network/physical:default'/>
81 </dependency>
82
83 <exec_method type='method' name='start' exec='%(prefix)s/sbin/cherokee -d' timeout_seconds='60'>
84 <method_context><method_credential user='root' group='root' /></method_context>
85 </exec_method>
86
87 <exec_method type='method' name='stop' exec='kill `cat %(prefix)s/var/run/cherokee.pid`' timeout_seconds='60'>
88 <method_context><method_credential user='root' group='root' /></method_context>
89 </exec_method>
90
91 <exec_method type='method' name='refresh' exec='kill -HUP `cat %(prefix)s/var/run/cherokee.pid`' timeout_seconds='60'>
92 <method_context><method_credential user='root' group='root' /></method_context>
93 </exec_method>
94
95 <property_group name='startd' type='framework'>
96 <propval name='duration' type='astring' value='contract'/>
97 <propval name='ignore_error' type='astring' value='core,signal' />
98 </property_group>
99
100 </instance>
101
102 <template>
103 <common_name><loctext xml:lang='C'>Advanced and Fast Web Server</loctext></common_name>
104 <documentation>
105 <doc_link name='www.cherokee-project.com' uri='http://www.cherokee-project.com/doc/' />
106 </documentation>
107 </template>
108 </service>
109 </service_bundle>
110 """
111
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
112 INITD_SH = """\
113 #!/bin/sh -e
114
d625433 @alobbs Add a new --devel mode
alobbs authored
115 PATH=/sbin:/bin:/usr/sbin:/usr/bin:%(prefix)s/sbin:%(prefix)s/bin
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
116
d625433 @alobbs Add a new --devel mode
alobbs authored
117 DAEMON=%(prefix)s/sbin/cherokee
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
118 NAME=cherokee
d625433 @alobbs Add a new --devel mode
alobbs authored
119 PIDFILE=%(prefix)s/var/run/cherokee.pid
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
120
121 set -e
122 test -x $DAEMON || exit 0
123
124 case "$1" in
125 start)
d625433 @alobbs Add a new --devel mode
alobbs authored
126 %(prefix)s/sbin/cherokee -d
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
127 ;;
128
129 stop)
130 if [ -f $PIDFILE ]; then
131 PID=$(cat $PIDFILE)
132 kill $PID
133 fi
134 ;;
135
136 restart)
137 $0 stop
138 sleep 1
139 $0 start
140 ;;
141
142 reload|force-reload)
143 printf "Reloading web server: %%s\t" "$NAME"
144 if [ -f $PIDFILE ]; then
145 PID=$(cat $PIDFILE)
146 if ps p $PID | grep $NAME >/dev/null 2>&1; then
147 kill -HUP $PID
148 else
149 echo "PID present, but $NAME not found at PID $PID - Cannot reload"
150 exit 1
151 fi
152 else
153 echo "No PID file present for $NAME - Cannot reload"
154 exit 1
155 fi
156 ;;
157
158 status)
159 printf "%%s web server status:\t" "$NAME"
160 if [ -e $PIDFILE ] ; then
161 PROCNAME=$(ps -p $(cat $PIDFILE) -o comm=)
162 if [ "x$PROCNAME" = "x" ]; then
163 printf "Not running, but PID file present \t"
164 else
165 if [ "$PROCNAME" = "$NAME" ]; then
166 printf "Running\t"
167 else
168 printf "PID file points to process '%%s', not '%%s'\t" "$PROCNAME" "$NAME"
169 fi
170 fi
171 else
172 if PID=$(pidofproc cherokee); then
173 printf "Running (PID %%s), but PIDFILE not present\t" "$PID"
174 else
175 printf "Not running\t"
176 fi
177 fi
178 ;;
179
180 *)
181 N=/etc/init.d/$NAME
182 echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
183 exit 1
184 ;;
185 esac
186
187 if [ $? = 0 ]; then
188 echo .
189 exit 0
190 else
191 echo failed
192 exit 1
193 fi
194 exit 0
195 """
196
00d56eb @alobbs Adds BSD support
alobbs authored
197 BSD_INIT = """\
198 #!/bin/sh
199
200 . /etc/rc.subr
201
202 name="cherokee"
203 rcvar="`set_rcvar`"
204 command="%(prefix)s/sbin/cherokee"
205
206 load_rc_config $name
207 command_args="-d"
208
209 run_rc_command "$1"
210 """
211
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
212
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
213 # Globals
214 #
d625433 @alobbs Add a new --devel mode
alobbs authored
215 prefix = PREFIX_STANDARD
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
216 start_at = PHASE_DOWNLOAD
217 download_snapshot = False
d625433 @alobbs Add a new --devel mode
alobbs authored
218 devel_build = False
8bcefee @alobbs Initial import
alobbs authored
219
220
221 # ANSI Colors
222 #
223 ESC = chr(27) + '['
224 RESET = '%s0m' %(ESC)
225
226 def green (s): return ESC + '0;32m' + s + RESET
227 def red (s): return ESC + '0;31m' + s + RESET
228 def yellow (s): return ESC + '1;33m' + s + RESET
229 def blue (s): return ESC + '0;34m' + s + RESET
230
231
232 # Utilities
233 #
e924481 @alobbs Better error reports, plus a new check for Python.
alobbs authored
234 def FATAL_error (error, retcode=1):
235 print (red(error))
236 sys.exit (retcode)
237
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
238 def exe (cmd, colorer=lambda x: x, cd=None, stdin=None, return_fatal=True):
8bcefee @alobbs Initial import
alobbs authored
239 print (yellow(cmd))
240
241 stdout = ''
242
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
243 kwargs = {'shell': True, 'stdout': subprocess.PIPE, 'cwd': cd}
244 if stdin:
245 kwargs['stdin'] = subprocess.PIPE
246
247 p = subprocess.Popen (cmd, **kwargs)
248
249 if stdin:
828bc25 @alobbs Fixes a couple of issues calling sudo
alobbs authored
250 try:
251 p.stdin.write (stdin)
252 p.stdin.close()
253 except IOError:
254 pass
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
255
8bcefee @alobbs Initial import
alobbs authored
256 while True:
257 line = p.stdout.readline()
258 if not line:
259 break
260
261 line = line.decode('utf-8')
262 stdout += line
263 print (colorer (line.rstrip('\n\r')))
264
265 p.wait()
266
267 # Return
268 if p.returncode != 0 and return_fatal:
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
269 print ('\n%s: Could not execute: %s' %(red('ERROR'), cmd))
8bcefee @alobbs Initial import
alobbs authored
270
271 return {'stdout': stdout,
272 'retcode': p.returncode}
273
828bc25 @alobbs Fixes a couple of issues calling sudo
alobbs authored
274 _root_password = None
275 def get_root_password():
276 global _root_password
277
278 while not _root_password:
279 _root_password = read_input ("root's password: ")
280 if _root_password:
281 _root_password += '\n'
282
283 return _root_password
284
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
285 def exe_sudo (cmd, **kwargs):
828bc25 @alobbs Fixes a couple of issues calling sudo
alobbs authored
286 if os.getuid() != 0:
287 root_password = get_root_password()
288 kwargs['stdin'] = root_password
5dbfaab @alobbs Bugfix: Installer failed when run as root.
alobbs authored
289 cmd = "sudo -S " + cmd
290 return exe (cmd, **kwargs)
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
291
8bcefee @alobbs Initial import
alobbs authored
292 def which (program):
293 def is_exe(fpath):
294 return os.path.exists(fpath) and os.access(fpath, os.X_OK)
295
296 fpath, fname = os.path.split(program)
297 if fpath:
298 if is_exe(program):
299 return program
300 else:
301 for path in os.environ["PATH"].split(os.pathsep):
302 exe_file = os.path.join(path, program)
303 if is_exe(exe_file):
304 return exe_file
305
306 return None
307
308 def rm (path):
309 return exe ("rm -rf '%s'" %(path), red)
310
311 def mkdir (path):
312 return exe ("mkdir -p '%s'" %(path), blue)
313
314 def download (url, target_file):
315 # Wget
316 wget_bin = which ('wget')
317 if wget_bin:
318 ret = exe ("wget '%(url)s' --output-document='%(target_file)s'" %(locals()))
319 if ret['retcode'] == 0:
320 return
321
322 # Curl
323 curl_bin = which ('curl')
324 if curl_bin:
325 ret = exe ("curl '%(url)s' --output '%(target_file)s'" %(locals()))
326 if ret['retcode'] == 0:
327 return
328
329 # Python
330 import urllib2
331 print ("Downloading %s" %(url))
332 i = urllib2.urlopen (url)
333 o = open (target_file, 'w+')
334 o.write (i.read())
335
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
336 def read_input (prompt):
337 try:
338 # Python 2.x
339 return raw_input (prompt)
340 except NameError:
341 # Python 3.x
342 return input (prompt)
343
344 def read_yes_no (prompt, empty_is=None):
345 while True:
346 ret = read_input (prompt).lower()
347 if ret in ('y','yes'):
348 return True
349 if ret in ('n','no'):
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
350 return False
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
351 if not ret and empty_is != None:
352 return empty_is
353
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
354 def figure_initd_app_level (directory, app, not_found=99):
355 files = [x.lower() for x in os.listdir(directory)]
356 for filename in files:
357 tmp = re.findall (r's(\d+)(.+)', filename)
358 if not tmp: continue
359
360 if tmp[0][1] == app:
361 return tmp[0][0]
362
363 return not_found
364
33abc5b @alobbs Adds support for gmake
alobbs authored
365 def make_path():
366 return which("gmake") or which("make")
367
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
368
8bcefee @alobbs Initial import
alobbs authored
369 # Cherokee
370 #
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
371 def cherokee_download (tar_file):
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
372 # Clean up
8bcefee @alobbs Initial import
alobbs authored
373 rm (BUILD_DIR)
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
374 rm (tar_file)
8bcefee @alobbs Initial import
alobbs authored
375 mkdir (BUILD_DIR)
376
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
377 # Download
378 if download_snapshot:
379 url = URL_SNAPSHOT_RELEASE
380 else:
381 url = URL_LATEST_RELEASE
382
383 download (url, tar_file)
8bcefee @alobbs Initial import
alobbs authored
384
385
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
386 def cherokee_find_unpacked():
8bcefee @alobbs Initial import
alobbs authored
387 for f in os.listdir (BUILD_DIR):
388 fp = os.path.join (BUILD_DIR, f)
389 tmp = re.findall (r'cherokee-(\d+\.\d+\.\d+)', f)
390 if tmp and os.path.isdir (fp):
391 return fp
392
393
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
394 def cherokee_unpack (latest_local):
395 # Unpack
ebd2a17 @alobbs Better error handling
alobbs authored
396 ret = exe ("gzip -dc '%s' | tar xfv -" %(latest_local), cd=BUILD_DIR)
397 if ret['retcode'] != 0:
398 return None
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
399
400 # Look for the src directory
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
401 path = cherokee_find_unpacked()
402 if not path:
403 return
404
405 # Works around clock issues
406 touch = False
407 for f in [os.path.join (path, x) for x in os.listdir (path)]:
408 if os.stat(f)[stat.ST_MTIME] > time.time():
409 touch = True
410 break
411
412 if touch:
413 exe ("find '%s' -exec touch '{}' \;" %(path))
414
415 return path
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
416
417
8bcefee @alobbs Initial import
alobbs authored
418 def cherokee_compile (src_dir):
d625433 @alobbs Add a new --devel mode
alobbs authored
419 params="--prefix='%s'" %(prefix)
91ba3f2 @alobbs Workaround for OSes/distros where gettext is not installed. It is
alobbs authored
420
421 # Look for gettext
422 if not which ("msgfmt"):
423 params += " --enable-nls=no"
424
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
425 # Snaphost
426 if download_snapshot:
427 params += " --enable-beta"
428
d625433 @alobbs Add a new --devel mode
alobbs authored
429 # Trace
430 if devel_build:
431 params += " --enable-trace"
33abc5b @alobbs Adds support for gmake
alobbs authored
432 params += " CFLAGS='-ggdb3 -O0'"
d625433 @alobbs Add a new --devel mode
alobbs authored
433
91ba3f2 @alobbs Workaround for OSes/distros where gettext is not installed. It is
alobbs authored
434 # Configure
435 ret = exe ("./configure " + params, cd=src_dir)
ebd2a17 @alobbs Better error handling
alobbs authored
436 if ret['retcode'] != 0:
437 return True
438
91ba3f2 @alobbs Workaround for OSes/distros where gettext is not installed. It is
alobbs authored
439 # Build
33abc5b @alobbs Adds support for gmake
alobbs authored
440 ret = exe (make_path(), cd=src_dir)
ebd2a17 @alobbs Better error handling
alobbs authored
441 if ret['retcode'] != 0:
442 return True
8bcefee @alobbs Initial import
alobbs authored
443
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
444
445 def cherokee_install (src_dir):
d625433 @alobbs Add a new --devel mode
alobbs authored
446 if os.access (prefix, os.W_OK):
33abc5b @alobbs Adds support for gmake
alobbs authored
447 ret = exe ("%s install" %(make_path()), cd=src_dir)
8bcefee @alobbs Initial import
alobbs authored
448 else:
33abc5b @alobbs Adds support for gmake
alobbs authored
449 ret = exe_sudo ("%s install" %(make_path()), cd=src_dir)
ebd2a17 @alobbs Better error handling
alobbs authored
450
451 if ret['retcode'] != 0:
452 return True
8bcefee @alobbs Initial import
alobbs authored
453
454
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
455 def cherokee_set_initd():
456 print('')
457
458 proceed = read_yes_no ("Do you want Cherokee to be started at boot time? [Y/n] ", True)
459 if not proceed:
460 return
461
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
462 variables = globals()
463 variables.update (locals())
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
464
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
465 # MacOS X
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
466 if sys.platform == 'darwin':
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
467 tmp_fp = os.path.join (BUILD_DIR, "launchd-cherokee.plist")
d625433 @alobbs Add a new --devel mode
alobbs authored
468 plist_fp = os.path.join (prefix, "launchd-cherokee.plist")
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
469
470 # Write the plist file
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
471 txt = LAUNCHD_PLIST %(variables)
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
472 f = open (tmp_fp, 'w+')
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
473 f.write (txt)
474 f.close()
475
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
476 # Permissions
477 exe_sudo ("cp '%s' '%s'" %(tmp_fp, plist_fp))
478 exe_sudo ("chown root '%s'" %(plist_fp))
479 exe_sudo ("chgrp admin '%s'" %(plist_fp))
480
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
481 # Let launchd know about it
f11c93d @alobbs Overwrite the launchctl plist entry.
alobbs authored
482 exe_sudo ("launchctl unload -w '%s'" %(plist_fp))
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
483 exe_sudo ("launchctl load -w '%s'" %(plist_fp))
484 exe_sudo ("launchctl start org.cherokee.webserver")
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
485 return
486
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
487 # Solaris
488 if sys.platform.startswith('sunos'):
489 def smf_present():
490 return (os.access ("/etc/svc/volatile/repository_door", os.R_OK) and
491 not os.path.isfile ("/etc/svc/volatile/repository_door"))
492
493 variables['prefix_var'] = os.path.join (prefix, "var")
494
495 tmp_fp = os.path.join (BUILD_DIR, "http-cherokee.xml")
496 xml_fp = "/var/svc/manifest/network/http-cherokee.xml"
497
498 # Write the plist file
499 txt = SOLARIS_SVC %(variables)
500 f = open (tmp_fp, 'w+')
501 f.write (txt)
502 f.close()
503
504 # Permissions
505 exe_sudo ("cp '%s' '%s'" %(tmp_fp, xml_fp))
506 exe_sudo ("chown root '%s'" %(xml_fp))
507 exe_sudo ("chgrp sys '%s'" %(xml_fp))
508
509 # Let launchd know about it
510 if smf_present():
511 exe_sudo ("/usr/sbin/svccfg import '%s'" %(xml_fp))
512 exe_sudo ("/usr/sbin/svcadm enable svc:/network/http:cherokee")
513 else:
514 print ("INFO: Skipping SVC, SMF not present")
515 return
516
00d56eb @alobbs Adds BSD support
alobbs authored
517 # BSD
518 if 'bsd' in sys.platform.lower():
519 rcd_fp = '/etc/rc.d/cherokee'
520
521 # Preliminary clean up
522 exe_sudo ("rm -f '%s'"%(rcd_fp))
523
524 # Write the init.d file
525 txt = BSD_INIT %(variables)
526 f = open (rcd_fp, 'w+')
527 f.write (txt)
528 f.close()
529
530 # Permissions
531 exe_sudo ("chown root '%s'" %(rcd_fp))
532 exe_sudo ("chmod 555 '%s'" %(rcd_fp))
533
534 return
535
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
536 # Init.d
8286695 @alobbs Removes a Debian-centric assumption. Do not assume runlevel 2 is the
alobbs authored
537 if os.path.isdir ("/etc/init.d"):
538 # Figure runlevel
539 ret = exe ("runlevel")
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
540
8286695 @alobbs Removes a Debian-centric assumption. Do not assume runlevel 2 is the
alobbs authored
541 tmp = re.findall (r'(\d+)', ret['stdout'])
542 if not tmp:
e924481 @alobbs Better error reports, plus a new check for Python.
alobbs authored
543 print (red ("Could not figure the current runlevel. Skiping step."))
544 return
8286695 @alobbs Removes a Debian-centric assumption. Do not assume runlevel 2 is the
alobbs authored
545
546 runlevel = tmp[0]
547
548 # Figure rc<X>.d directory:
549 # /etc/rc2.d
550 # /etc/init.d/rc2.d
551 rc_paths = ('/etc/rc%s.d'%(runlevel), '/etc/init.d/rc%s.d'%(runlevel))
552 rc_dir = None
553
554 for d in rc_paths:
555 if os.path.isdir (d):
556 rc_dir = d
557 break
558
559 assert rc_dir, "Unknow init.d layout"
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
560
561 # Build paths
562 tmp_fp = os.path.join (BUILD_DIR, "cherokee.initd")
d625433 @alobbs Add a new --devel mode
alobbs authored
563 sh_fp = os.path.join (prefix, "cherokee.initd")
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
564 initd_fp = "/etc/init.d/cherokee-opt"
565
566 # Figure rc2.d file level
567 level = 99
568 for k in ('apache', 'apache2', 'httpd', 'lighttpd', 'nginx'):
8286695 @alobbs Removes a Debian-centric assumption. Do not assume runlevel 2 is the
alobbs authored
569 level = min (level, figure_initd_app_level (rc_dir, k))
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
570
8286695 @alobbs Removes a Debian-centric assumption. Do not assume runlevel 2 is the
alobbs authored
571 rcS_fp = os.path.join (rc_dir, "S%02dcherkee-opt"%(level-1))
572 rcK_fp = os.path.join (rc_dir, "K%02dcherkee-opt"%(level-1))
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
573
574 # Preliminary clean up
8286695 @alobbs Removes a Debian-centric assumption. Do not assume runlevel 2 is the
alobbs authored
575 exe_sudo ("rm -f '%s' '%s' '%s' '%s' '%s'" %(tmp_fp, sh_fp, initd_fp, rcS_fp, rcK_fp))
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
576
577 # Write the init.d file
e71d632 @alobbs Adds support for Solaris' SMF
alobbs authored
578 txt = INITD_SH %(variables)
7551a16 @alobbs Implements support for init.d scripts.
alobbs authored
579 f = open (tmp_fp, 'w+')
580 f.write (txt)
581 f.close()
582
583 # Permissions
584 exe_sudo ("cp '%s' '%s'" %(tmp_fp, sh_fp))
585 exe_sudo ("chown root '%s'" %(sh_fp))
586 exe_sudo ("chmod 755 '%s'" %(sh_fp))
587
588 # Add it
8286695 @alobbs Removes a Debian-centric assumption. Do not assume runlevel 2 is the
alobbs authored
589 exe_sudo ("ln -s '%s' '%s'" %(sh_fp, initd_fp)) # /etc/init.d/cherokee -> /opt/..
590 exe_sudo ("ln -s '%s' '%s'" %(initd_fp, rcS_fp)) # /etc/rc2.d/S99cherokee -> /etc/init.d/..
591 exe_sudo ("ln -s '%s' '%s'" %(initd_fp, rcK_fp)) # /etc/rc2.d/K99cherokee -> /etc/init.d/..
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
592
593
8bcefee @alobbs Initial import
alobbs authored
594 def cherokee_report():
d625433 @alobbs Add a new --devel mode
alobbs authored
595 cherokee_fp = os.path.join (prefix, "sbin", "cherokee")
5d35805 @alobbs Adds an extra message that clarifies where the binaries were installed.
alobbs authored
596
597 print (blue ("Technical details:"))
598 exe ("%s -i" %(cherokee_fp))
599
600 print (blue ("How to:"))
d625433 @alobbs Add a new --devel mode
alobbs authored
601 print (" - Launch manually the server: %s/sbin/cherokee -d" %(prefix))
602 print (" - Launch the administration GUI: %s/bin/cherokee-admin-launcher" %(prefix))
8bcefee @alobbs Initial import
alobbs authored
603
604
605 # Main
606 #
607 def main():
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
608 tar_file = os.path.join (BUILD_DIR, "cherokee-latest.tar.gz")
609
610 if start_at <= PHASE_DOWNLOAD:
611 cherokee_download (tar_file)
612
613 if start_at <= PHASE_UNPACK:
614 src_dir = cherokee_unpack (tar_file)
ebd2a17 @alobbs Better error handling
alobbs authored
615 if not src_dir: return
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
616 else:
617 src_dir = cherokee_find_unpacked()
ebd2a17 @alobbs Better error handling
alobbs authored
618 if not src_dir: return
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
619
620 if start_at <= PHASE_COMPILE:
ebd2a17 @alobbs Better error handling
alobbs authored
621 error = cherokee_compile (src_dir)
622 if error: return
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
623
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
624 if start_at <= PHASE_INSTALL:
ebd2a17 @alobbs Better error handling
alobbs authored
625 error = cherokee_install (src_dir)
626 if error: return
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
627
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
628 if start_at <= PHASE_INITD:
629 cherokee_set_initd()
630
631 if start_at <= PHASE_REPORT:
632 cherokee_report ()
8bcefee @alobbs Initial import
alobbs authored
633
634
635 def check_prerequisites():
098bef1 @alobbs Ensure a C compiler is available, and suggest how to get it installed
alobbs authored
636 # Check for a C compiler
637 if not which("gcc") and not which("cc"):
638 if sys.platform == 'sunos5':
639 cont = read_yes_no ("SUNWgcc must be installed. Proceed? [Y/n] ", True)
640 if not cont:
641 raise SystemExit
642 exe ("pkg install SUNWgcc")
643 else:
e924481 @alobbs Better error reports, plus a new check for Python.
alobbs authored
644 FATAL_error ("A C compiler is required")
098bef1 @alobbs Ensure a C compiler is available, and suggest how to get it installed
alobbs authored
645
e924481 @alobbs Better error reports, plus a new check for Python.
alobbs authored
646 # Check for Python
647 if not which("env"):
648 FATAL_error ("'env' is required")
8bcefee @alobbs Initial import
alobbs authored
649
e924481 @alobbs Better error reports, plus a new check for Python.
alobbs authored
650 ret = exe ("env python -V")
651 if ret['retcode'] != 0:
652 FATAL_error ("Python is not in the path")
653
654 # Check for make
33abc5b @alobbs Adds support for gmake
alobbs authored
655 if not make_path():
656 FATAL_error ("'make' or 'gmake' is required for the compilation")
657
8bcefee @alobbs Initial import
alobbs authored
658
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
659 def process_parameters():
660 global start_at
d625433 @alobbs Add a new --devel mode
alobbs authored
661 global download_snapshot
662 global devel_build
663 global prefix
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
664
b3a3422 @alobbs Implements --help
alobbs authored
665 if '--help' in sys.argv:
666 print ("Cherokee's assisted deployment script:")
667 print (" USAGE: python install.py [params]")
668 print ("")
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
669 print (" --snapshot Compile latest development snapshot")
d625433 @alobbs Add a new --devel mode
alobbs authored
670 print (" --devel snapshot w/ debug under cherokee-dev")
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
671 print ("")
b3a3422 @alobbs Implements --help
alobbs authored
672 print (" Development:")
673 print (" --from-unpack Start at the 'unpack' phase")
674 print (" --from-compile Start at the 'compilation' phase")
675 print (" --from-install Start at the 'install' phase")
676 print (" --from-initd Start at the 'initd' phase")
677 print (" --from-report Start at the 'report' phase")
678 print ("")
679 print ("Report bugs to: http://bugs.cherokee-project.com/")
680 raise SystemExit
681
d625433 @alobbs Add a new --devel mode
alobbs authored
682 # Development
085599c @alobbs Adds a new '--snapshot' parameter. It allows to install the latest
alobbs authored
683 if '--snapshot' in sys.argv:
684 download_snapshot = True
685
d625433 @alobbs Add a new --devel mode
alobbs authored
686 if '--devel' in sys.argv:
687 devel_build = True
688 download_snapshot = True
689 prefix = PREFIX_DEVEL
690
691 # Script development
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
692 if '--from-unpack' in sys.argv:
693 start_at = PHASE_UNPACK
694 if '--from-compile' in sys.argv:
695 start_at = PHASE_COMPILE
ffe9d1e @alobbs WIP: New 'Install' phase, better Launchd script, etc.
alobbs authored
696 if '--from-install' in sys.argv:
697 start_at = PHASE_INSTALL
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
698 if '--from-initd' in sys.argv:
699 start_at = PHASE_INITD
700 if '--from-report' in sys.argv:
701 start_at = PHASE_REPORT
702
703
8bcefee @alobbs Initial import
alobbs authored
704 if __name__ == '__main__':
3fbee9c @alobbs Adds support for --from-<something> parameter. It also adds initial
alobbs authored
705 process_parameters()
8bcefee @alobbs Initial import
alobbs authored
706 check_prerequisites()
707 main()
Something went wrong with that request. Please try again.