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

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

hadoop: update to 1.0.0; fix master_sites and livecheck; use Tcl 'ln' command instead of 'system'.

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