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

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

hadoop: fix 'ln -s' to conf.pseudo; simplify livecheck.url; see http://lists.macosforge.org/pipermail/macports-dev/2012-January/017489.html.

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