source: trunk/dports/java/hadoop/Portfile @ 94077

Last change on this file since 94077 was 94077, checked in by ryandesign@…, 8 years ago

hadoop: check OS version before fetching distfile; simplify how OS version is checked (using ${os.major})

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2# $Id: Portfile 94077 2012-06-08 18:57:32Z ryandesign@macports.org $
3
4PortSystem          1.0
5
6name                hadoop
7version             1.0.3
8revision            1
9categories          java devel science
10maintainers         hum openmaintainer
11
12description         Open-source software for reliable, scalable, distributed computing
13long_description    Hadoop is a distributed computing platform written in Java. \
14                    It incorporates features similar to those of the Google File System \
15                    and of MapReduce.
16
17homepage            http://hadoop.apache.org/
18platforms           darwin
19supported_archs     noarch
20license             Apache-2.0
21
22master_sites        apache:hadoop/common/${distname}
23distfiles           ${distname}-bin${extract.suffix}
24checksums           rmd160  a98ca552a8a6dfcc6455b53cfd7988d562c265d1 \
25                    sha256  a33d07ece0e9b7e1ecf32670cac28444ba8f56b3360548d96b56964facc2d1ef
26
27pre-fetch {
28    # This port works on Mac OS X 10.6 or later, because 'sudo option -E'
29    # is not available on Mac OS X 10.5 or earlier. See #34665.
30    if {${os.platform} == "darwin" && ${os.major} <= 9} {
31        ui_error "This port works on Mac OS X 10.6 (Snow Leopard) or later"
32        return -code error "Mac OS X 10.6 (Snow Leopard) or later is required"
33    }
34}
35
36patchfiles          patch-hadoop-env.sh.diff
37
38use_configure       no
39
40build {}
41
42set hadoopuser      hadoop
43
44set java_home       /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
45
46pre-configure {
47    if {![file exists ${java_home}]} {
48        ui_error "Java 1.6 is required, but not located at ${java_home}"
49        return -code error "Java 1.6 missing"
50    }
51}
52
53# Hadoop home and conf directories.
54set hadoop_basedir  ${prefix}/share/java
55set hadoop_home     ${hadoop_basedir}/${distname}
56set hadoop_conf_dir ${hadoop_home}/conf
57
58# Working directories.
59set hadoop_var_dir  ${prefix}/var/${name}
60set hadoop_log_dir  ${hadoop_var_dir}/log
61set hadoop_pid_dir  ${hadoop_var_dir}/run
62
63destroot {
64    # Copy the distribution to Hadoop home directory.
65    xinstall -m 755 -${destroot}${hadoop_basedir}
66    copy ${worksrcpath} ${destroot}${hadoop_basedir}
67
68    # Patch for Mahout 0.4 to suppress warnings.
69    xinstall -m 755 -d \
70        ${destroot}${hadoop_home}/webapps/secondary/WEB-INF
71
72    # Install an extra script for this port.
73    set hadoop_bin ${destroot}${prefix}/bin/hadoop-bin
74    xinstall -m 755 ${filespath}/hadoop-bin      ${hadoop_bin}
75    reinplace "s|@hadoop_home@|${hadoop_home}|g" ${hadoop_bin}
76    reinplace "s|@java_home@|${java_home}|g"     ${hadoop_bin}
77    reinplace "s|@hadoopuser@|${hadoopuser}|g"   ${hadoop_bin}
78
79    # Setup 'hadoop-env.sh' in conf.
80    set env_sh ${destroot}${hadoop_conf_dir}/hadoop-env.sh
81    reinplace "s|@java_home@|${java_home}|g"           ${env_sh}
82    reinplace "s|@hadoop_log_dir@|${hadoop_log_dir}|g" ${env_sh}
83    reinplace "s|@hadoop_pid_dir@|${hadoop_pid_dir}|g" ${env_sh}
84
85    add_hadoop_user_and_group
86
87    # Create working directories.
88    xinstall -m 755 -o ${hadoopuser} -g ${hadoopuser} -d \
89        ${destroot}${hadoop_var_dir} \
90        ${destroot}${hadoop_log_dir} \
91        ${destroot}${hadoop_pid_dir}
92    destroot.keepdirs-append \
93        ${destroot}${hadoop_var_dir} \
94        ${destroot}${hadoop_log_dir} \
95        ${destroot}${hadoop_pid_dir}
96}
97
98pre-activate {
99    add_hadoop_user_and_group
100}
101
102proc add_hadoop_user_and_group {} {
103    global hadoopuser hadoop_var_dir
104    if {![existsgroup ${hadoopuser}]} {
105        addgroup ${hadoopuser}
106        adduser ${hadoopuser} \
107            gid=[existsgroup ${hadoopuser}] \
108            realname=Hadoop\ Server \
109            home=${hadoop_var_dir} \
110            shell=/bin/bash
111    }
112}
113
114post-deactivate {
115    ui_msg "********************************************************"
116    ui_msg "* To revert the system after uninstalling the port:"
117    ui_msg "* 1) Delete Hadoop working directory:"
118    ui_msg "*  $ sudo rm -rf ${hadoop_var_dir}"
119    ui_msg "* 2) Delete Hadoop user and group:"
120    ui_msg "*  $ sudo dscl . -delete /Users/${hadoopuser}"
121    ui_msg "*  $ sudo dscl . -delete /Groups/${hadoopuser}"
122    ui_msg "********************************************************"
123}
124
125default_variants    +pseudo
126
127set hadoop_tmp_dir  ${hadoop_var_dir}/cache
128
129variant pseudo description {Run on a single-node in a pseudo-distributed mode} {
130    patchfiles-append  patch-conf.diff
131
132    post-destroot {
133        # Set conf directory for a pseudo-distributed mode.
134        copy ${destroot}${hadoop_conf_dir} ${destroot}${hadoop_conf_dir}.pseudo
135        move ${destroot}${hadoop_conf_dir} ${destroot}${hadoop_conf_dir}.local
136        ln -s conf.pseudo ${destroot}${hadoop_conf_dir}
137
138        # Set the maximum number of tasks based on the number of the CPUs (cores).
139        regexp {\d+} [exec sysctl hw.ncpu] ncpu
140        set tasks_max [expr $ncpu + 2]
141
142        # Setup configuration files.
143        reinplace "s|@tasks_max@|${tasks_max}|g" \
144            ${destroot}${hadoop_conf_dir}.pseudo/mapred-site.xml
145        reinplace "s|@hadoop_tmp_dir@|${hadoop_tmp_dir}|" \
146            ${destroot}${hadoop_conf_dir}.pseudo/core-site.xml
147
148        # Create a temporary directory.
149        xinstall -m 755 -o ${hadoopuser} -g ${hadoopuser} -d \
150            ${destroot}${hadoop_tmp_dir}
151        destroot.keepdirs-append \
152            ${destroot}${hadoop_tmp_dir}
153    }
154
155    post-activate {
156        # Setup passphraseless ssh.
157        set ssh_dir ${hadoop_var_dir}/.ssh
158        if {![file exists ${ssh_dir}]} {
159            xinstall -m 700 -o ${hadoopuser} -g ${hadoopuser} -d ${ssh_dir}
160            system "sudo -u ${hadoopuser} ssh-keygen -t rsa -P '' -f ${ssh_dir}/id_rsa"
161            xinstall -m 644 -o ${hadoopuser} -g ${hadoopuser} \
162                ${ssh_dir}/id_rsa.pub \
163                ${ssh_dir}/authorized_keys
164        }
165
166        ui_msg "********************************************************"
167        ui_msg "* To run on a single-node in a pseudo-distributed mode:"
168        ui_msg "* 1) Turn on Remote Login (sshd):"
169        ui_msg "*  check 'System Preferences > Sharing > Remote Login'"
170        ui_msg "* 2) Format a new distributed-filesystem:"
171        ui_msg "*  $ hadoop-bin hadoop namenode -format"
172        ui_msg "* 3) Start the hadoop daemons:"
173        ui_msg "*  $ hadoop-bin start-all.sh"
174        ui_msg "* 4) Perform operations you like. To see examples:"
175        ui_msg "*  $ open file://${hadoop_home}/docs/single_node_setup.html"
176        ui_msg "* 5) When you're done, stop the daemons with:"
177        ui_msg "*  $ hadoop-bin stop-all.sh"
178        ui_msg "********************************************************"
179    }
180}
181
182livecheck.type      regex
183livecheck.url       http://www.apache.org/dist/hadoop/common/
184livecheck.regex     ${name}-(1.\[0-9.\]+)
Note: See TracBrowser for help on using the repository browser.