how is amber related?

how is amber related? what on earth is this doing? does amber depend on cuda? how about tensorflow?


#!/usr/bin/env bash

if [ $# = 0 ]; then
    # circleci build
    echo "CIRCLE_BRANCH", $CIRCLE_BRANCH
    buildfull=`python -c "import os;  print(os.getenv('CIRCLE_BRANCH').startswith('circleci_'))"`
    echo 'buildfull = ' $buildfull

    if [ "$buildfull" == "True" ]; then
        AMBER_BUILD_TASK='ambertools'
        pyversion=`python -c "import os; env=os.getenv('CIRCLE_BRANCH'); print(env.strip('circleci_'))"`
        echo "pyversion = " $pyversion
    else
        AMBER_BUILD_TASK='ambermini'
    fi
else
    # e.g: build ambertools with python=2.7
    # bash scripts/run_docker_build.sh ambertools 2.7
    AMBER_BUILD_TASK=$1 # ambertools or ambermini
    pyversion=$2
fi

echo "AMBER_BUILD_TASK = " $AMBER_BUILD_TASK
echo "Python version = " $pyversion

FEEDSTOCK_ROOT=$(cd "$(dirname "$0")/.."; pwd;)
echo "FEEDSTOCK_ROOT" $FEEDSTOCK_ROOT
DOCKER_IMAGE=ambermd/amber-build-box
BZ2FILE=/root/miniconda3/conda-bld/linux-64/amber*.tar.bz2

docker info

cat << EOF | docker run -i \
                        --rm \
                        -v ${FEEDSTOCK_ROOT}:/feedstock_root \
                        -a stdin -a stdout -a stderr \
                        $DOCKER_IMAGE \
                        bash || exit $?
    export PATH=/root/miniconda3/bin:\$PATH
    conda update --all --yes
    export AMBER_BUILD_TASK=${AMBER_BUILD_TASK}
    echo "Building" \${AMBER_BUILD_TASK}
    export SKIP_REGISTRATION=True
    if [ "\${AMBER_BUILD_TASK}" == 'ambermini' ]; then
        # build in a single containter
        conda build /feedstock_root/recipe --py 2.7 --quiet || exit 1
        conda build /feedstock_root/recipe --py 3.4 --quiet || exit 1
        conda build /feedstock_root/recipe --py 3.5 --quiet || exit 1
    else
        # build whole ambertools, for a single python version
        # should build each ambertools python version on each branch
        conda build /feedstock_root/recipe --py $pyversion --quiet || exit 1
    fi
    cp $BZ2FILE /feedstock_root/
    echo "done. Please check amber*tar.bz2 files in " $FEEDSTOCK_ROOT
EOF

docker2

~# nvidia-docker run -it -p 8888:8888 tensorflow/tensorflow:1.1.0-devel-gpu-py3
1.1.0-devel-gpu-py3: Pulling from tensorflow/tensorflow
c62795f78da9: Pull complete
d4fceeeb758e: Pull complete
5c9125a401ae: Pull complete
0062f774e994: Pull complete
6b33fd031fac: Pull complete
7ab5dd833cf2: Pull complete
df9cc763fcde: Pull complete
9b0174a3640e: Pull complete
1efd10acdd72: Pull complete
f77b671e3092: Pull complete
af9093817c44: Pull complete
b2fb381211f0: Pull complete
af9e216e9ceb: Pull complete
09860f91cae6: Pull complete
9f0f8d45045d: Pull complete
0467b7b5b3c8: Pull complete
311d6a376dba: Pull complete
d775db884640: Pull complete
befeab6b5e5d: Pull complete
7dd802ca32d9: Pull complete
d1a48577f024: Pull complete
9e3601307c1a: Pull complete
057615e69ff0: Pull complete
Digest: sha256:8eaa148ede85f6689aa3ee5c6d6d34e5b05fdc9af7c293a56f59887aedb851d2
Status: Downloaded newer image for tensorflow/tensorflow:1.1.0-devel-gpu-py3
nvidia-docker | 2017/10/17 10:32:09 Error: unsupported CUDA version: driver 6.5 < image 8.0.61

docker

when i do

~$ docker build –pull -t $USER/tensorflow-serving-devel -f Dockerfile.devel .

it doesn’t finish…stole Dockerfile.devel fromhttps://github.com/tensorflow/serving/blob/master/tensorflow_serving/tools/docker/Dockerfile.devel



FROM ubuntu:16.04

MAINTAINER Jeremiah Harmsen <[email protected]>

RUN apt-get update && apt-get install -y \
        build-essential \
        curl \
        git \
        libfreetype6-dev \
        libpng12-dev \
        libzmq3-dev \
        mlocate \
        pkg-config \
        python-dev \
        python-numpy \
        python-pip \
        software-properties-common \
        swig \
        zip \
        zlib1g-dev \
        libcurl3-dev \
        openjdk-8-jdk\
        openjdk-8-jre-headless \
        wget \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Set up grpc

RUN pip install mock grpcio

# Set up Bazel.

ENV BAZELRC /root/.bazelrc
# Install the most recent bazel release.
ENV BAZEL_VERSION 0.5.1
WORKDIR /
RUN mkdir /bazel && \
    cd /bazel && \
    curl -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \
    curl -fSsL -o /bazel/LICENSE.txt https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE && \
    chmod +x bazel-*.sh && \
    ./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \
    cd / && \
    rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh

CMD ["/bin/bash"]

</[email protected]>

but its pulled…

# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvidia/cuda latest 9d3688f974a1 4 days ago 1.73GB
hello-world latest 05a3bd381fc2 4 weeks ago 1.84kB
tensorflow/tensorflow latest-gpu 4ca1d30fcd9b 2 months ago 3.28GB
nvidia/cuda 6.5 794ce05b823b 10 months ago 1.02GB

because i using cuda 6.5 on my “host” the latest one doesnt work, have to get the one tagged 6.5

# nvidia-docker run –rm -ti nvidia/cuda:6.5 nvcc –version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2014 NVIDIA Corporation
Built on Wed_Aug_27_10:36:36_CDT_2014
Cuda compilation tools, release 6.5, V6.5.16

so what next?

cudnn90

shucks this is the max cuda for your nvidia driver version..
at least 361.00 is required for CUDA 8.0
at least 352.00 is required for CUDA 7.5
at least 346.00 is required for CUDA 7.0
at least 340.00 is required for CUDA 6.5
at least 331.00 is required for CUDA 6.0
at least 319.00 is required for CUDA 5.5

  • apt-get install ansible

and then

  • maybe save the below as cuda.yml and run ansible-playbook cuda.yml ?

- hosts: localhost
  #user: somebody
  #sudo: yes
  tasks:
    - name: register CUDA repository
      shell: wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64-deb && dpkg -i local_installers/cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb

    - name: install CUDA
      apt: name=cuda update_cache=yes

    - name: write environmant variables to bash profile
      copy: src=./cuda.sh dest=/etc/profile.d/

    - pip:
        name: numpy

    - pip:
        name: Keras

    - pip:
        name: tensorflow-gpu

    #- pip:
    #    name: --upgrade $TF_BINARY_URL
    #  environment:
    #    CUDA_HOME: /cluster/apps/x86_64/packages/cuda_8.0
    #    TF_BINARY_URL: https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0rc1-cp27-none-linux_x86_64.whl

  • install cudnn

cudnn-9.0-linux-x64-v7

libcudnn7_7.0.2.43-1+cuda9.0_amd64

libcudnn7-dev_7.0.2.43-1+cuda9.0_amd64

cudnn-6.5-linux-x64-v2

cudnn-sample-v2

postfix

we have a problem in that we backscatter. so we get on blacklist.
so a few things we can do to reduce the issue.

  • we are more strict with what mails get sent..

in main.cf

reject_invalid_hostname,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unlisted_recipient,
reject_unknown_sender_domain,
reject_unknown_recipient_domain,

  • we don’t send email if the client is on a rbl..

reject_rbl_client zen.spamhaus.org,
reject_rbl_client bl.spamcop.net,
reject_rbl_client b.barracudacentral.org,

#reject_rbl_client dnsbl.sorbs.net

#i don’t like sorbs, think too many false positives
smtpd_client_restrictions = reject_unknown_client_hostname, sleep 3, reject_unauth_pipelining
smtpd_sender_restrictions = reject_unknown_sender_domain

Reject_unknown_client_hostname is the most effective, but also the most stringent. It blocks connections from any machine that does not have proper DNS resolution. Nearly every legitimate mail server has correct forward and reverse resolution configured these days, so the likelihood of false positives is still pretty low.

The “sleep3, reject_unauth_pipelining” pair tell the server to wait three seconds after the client connects before displaying its “banner” in the SMTP exchange. Though their numbers are declining, some spam programs don’t wait for the banner and start spewing right away. “Reject_unauth_pipelining” tells Postfix to hang up the phone of any such clients.

“Reject_unknown_sender_domain” applies to the email address sent with the “MAIL FROM” command in the SMTP dialogue (known as the “envelope sender”). That rule requires the email address be @ a valid domain. Non-deliverable notices are sent to that address so it could have some, though I suspect small, effect of reducing NDNs to bogus addressees. Note that the sending server isn’t asked to validate that the message comes from a workign address (since it often can’t); the only check is whether the sender’s domain exists.

You should also browse the possibilities in: http://www.postfix.org/ADDRESS_VERIFICATION_README.html

  • we give up trying to resend bounces sooner?

and shorten bounce queue to 1m

and

  • we try to not respond to dsn?

in master.cf
-o smtpd_discard_ehlo_keywords=silent-discard,dsn

or in this case allow local subnet only…

/etc/postfix/main.cf:
smtpd_discard_ehlo_keyword_address_maps =
cidr:/etc/postfix/esmtp_access

/etc/postfix/esmtp_access:

# Allow DSN requests from local subnet only
172.20.0.0/16      silent-discard
0.0.0.0/0           silent-discard, dsn
::/0                silent-discard, dsn
  • we reject DSNs outright..this is still commented off…

In my Postfix configuration, on the machine that acts as MX for my domains — edit ‘/etc/postfix/header_checks’, and add these lines:

/^Content-Type: multipart\/report; report-type=delivery-status\;/ REJECT no third-party DSNs
/^Content-Type: message\/delivery-status; / REJECT no third-party DSNs

Edit ‘/etc/postfix/main.cf’, and ensure it contains:

header_checks = regexp:/etc/postfix/header_checks

Then run:`

sudo /etc/init.d/postfix restart

openafs-part2

  1. iscsiadm -m discovery -t sendtargets -p 172.20.193.40 && sleep 15 && iscsiadm -m node -T iqn.2001-05.com.equallogic:4-42a846-4ee8a9f13-1480000025e58afe-afs50 –login && sleep 15 && mount -a
  2. mailsend.pl
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
#!/usr/bin/perl -w
#
# Program: SMTP mail delivery program
# Date: 17th nov 2008
#
# This script takes an smtp server as its only argument, reads an email
# on standard input, and delivers it to the smtp server for relaying to
# the final destination. For example,
#
# % mailsend.pl smtp.mycompany.com < myemail.txt
#
# Where “myemail.txt” contains the necessary mail headers, as well as
# the body text. For example,
#
# Subject: hello world
# Date: Sun, 16 Nov 2008 16:25:38 +0800
#
# this is my message
#
# Modified by jeffrey 171209
# now can have multiple recipients in the To/Cc field
use Socket ;
# —————————————————————————–
my $timeout = 30 ; # smtp inactivity timeout (seconds)
my $line = “” ; # general purpose line buffer
my $host = “” ; # the remote host that we’ll connect to
my $mail_from = “” ; # “From:” pulled off mail headers
my $rcpt_to = “” ; # “To:” pulled off mail headers
my @header = () ; # array of lines, which form the mail headers
# —————————————————————————–
# This function is supplied a email address in the format
  1. get-mptstatus.sh
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
#!/bin/bash
# This script uses mpt-status to probe /dev/mptctl to find out status of the LSI HW raid array
MPTSTATUS=”/usr/local/bin/mpt-status”
SMTP_SERVER=”smtp.bii-sg.org”
if [ ! -x $MPTSTATUS ]; then
echo “cannot find $MPTSTATUS”
exit
fi
host $SMTP_SERVER | grep “has address”
if [ $? -ne 0 ]; then
SMTP_SERVER=”123.136.68.157″
fi
cat /proc/kallsyms | grep mptctl > /dev/null
# we check the kernel table symbols, not found then try to load as kernel module.
# so there is no need to modprobe if mptctl is compiled in 🙂
if [ $? -ne 0 ]; then
/sbin/modprobe mptctl
if [ $? -ne 0 ]; then
echo “mptctl module not found, please recompile kernel module”
echo “Look at – <kernelsource>/drivers/message/fusion/Kconfig for details”
exit
fi
fi
sleep 2
if [ ! -e /dev/mptctl ]; then
/bin/mknod /dev/mptctl c 10 220
fi
# get the right “-i <controller_id>”
RUNMPT=`$MPTSTATUS -p | grep ‘mpt-status -i’ | sed ‘s/^.*\(mpt-status -i [0-9]\).*$/\1/’`
STATE=`/usr/local/bin/$RUNMPT | grep -w OPTIMAL | sed ‘s/^.*\(OPTIMAL\).*$/\1/’`
if [ “$STATE” != “OPTIMAL” ]; then
echo “hardware raid degraded on `date`” >> /var/log/messages
# we call sendmail.pl here
HOSTNAME=`hostname -f`
echo “From: [email protected]$HOSTNAME” > /root/bin/alertmail.txt
echo “To: [email protected]” >> /root/bin/alertmail.txt
echo “Subject: mpt-status alert – x4100 hardware raid is degraded” >> /root/bin/alertmail.txt
echo ” ” >> /root/bin/alertmail.txt
echo “$HOSTNAME hardware raid in degraded mode – please replace HDD immediately” >> /root/bin/alertmail.txt
/root/bin/mailsend.pl $SMTP_SERVER < /root/bin/alertmail.txt
fi
  1. iscsi.sh
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
mount | grep sdc1 || /root/bin/mailsend.pl 123.136.68.157 < /root/bin/iscsinotmounted.txt
sleep 30 && echo $(date) > /vicepa/date || /root/bin/mailsend.pl 123.136.68.157 < /root/bin/cannotwrite2iscsi.txt
sleep 60 && rm -f /vicepa/date || /root/bin/mailsend.pl 123.136.68.157 < /root/bin/cannotwrite2iscsi.txt
# Joe Smith <[email protected]>
# and it returns :
sub f_email_addr
{
my $addr = $_[0] ;
$addr =~ s/^.+\<//g ;
$addr =~ s/\>.*$//g ;
return ($addr) ;
}
# This function sends a line to the remote smtp server, and reads a reply.
# The first argument is expected to be an established tcp connection. The
# line is supplied as the second argument, and the expected smtp reply
# code (number) is specified as the third argument. If the supplied smtp
# code is received, we return an empty string, otherwise something is
# presumed to have gone wrong and we return the entire reply string.
# Finally, an inactivity timeout is enforced. If triggered, the string
# “inactivity timed out” is returned.
sub f_smtp_dialog
{
my $fd = $_[0] ;
my $msg = $_[1] ;
my $expect = $_[2] ;
my $buf = “” ;
# deliver a message to the remote smtp server, if one is specified.
if (length ($msg) > 0)
{ printf ($fd “$msg”) ; }
eval
{
alarm ($timeout) ;
$buf = <$fd> ;
alarm (0) ;
} ;
if ($buf =~ /^$expect/)
{ return (“”) ; }
chomp ($buf) ;
return ($buf) ;
}
# —————————————————————————–
# check usage first …
if ($#ARGV != 0)
{
printf (“Usage : %s <smtp server> < mail.txt\n”, $0) ;
exit (1) ;
}
# try to read in mail header from stdin.
while ($line = <STDIN>)
{
chomp ($line) ;
if ($line =~ /^To:/)
{
$rcpt_to = $line ;
$rcpt_to =~ s/To: // ;
[email protected]=split(/,/,$rcpt_to);
foreach(@recp){
push(@recp_to, f_email_addr($_));
}
}
if ($line =~ /^Cc:/)
{
my$tline;
$tline=$line ;
$tline=~ s/Cc: // ;
[email protected]=split(/,/,$tline);
foreach(@recp){
push(@recp_to, f_email_addr($_));
}
}
if ($line =~ /^From:/)
{
$mail_from = $line ;
$mail_from =~ s/From: // ;
$mail_from = f_email_addr ($mail_from) ;
}
if ($line =~ /^$/)
{
last ;
}
$header[$#header+1] = $line ;
}
# check that we know who we’re sending mail from, and to.
if (length ($mail_from) < 1)
{
printf (“FATAL! Do not know who this mail is from. No ‘From: xx’.\n”) ;
exit (1) ;
}
if ($#recp_to < 0)
{
printf (“FATAL! Do not know who this mail is to. No ‘To: xx’.\n”) ;
exit (1) ;
}
# now attempt to connect to smtp server.
$host = inet_aton ($ARGV[0]) ||
die (“FATAL! Host not found $ARGV[0],$!”) ;
socket ($SD, PF_INET, SOCK_STREAM, getprotobyname (“tcp”)) ||
die (“FATAL! socket() failed,$!”) ;
eval
{
local $SIG{ALRM} = sub
{ printf (“FATAL! Connect to $ARGV[0] timed out.\n”) ; exit (1) ; } ;
alarm ($timeout) ;
connect ($SD, sockaddr_in (25, inet_aton ($ARGV[0]))) ||
die (“FATAL! Cannot connect to $ARGV[0] on port 25,$!”) ;
alarm (0) ;
} ;
select ($SD) ;
$| = 1 ;
select (STDOUT) ;
# perform the standard dialog with the smtp server.
$line = f_smtp_dialog ($SD, “”, 220) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
$line = f_smtp_dialog ($SD, “HELO localhost\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
$line = f_smtp_dialog ($SD, “MAIL FROM: $mail_from\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
#$line = f_smtp_dialog ($SD, “RCPT TO: $rcpt_to\n”, 250) ;
#if (length ($line) > 0)
# { printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
foreach(@recp_to){
my$k=$_;
#print “k $k\n”;
$line = f_smtp_dialog ($SD, “RCPT TO: $k\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
}
$line = f_smtp_dialog ($SD, “DATA\n”, 354) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; exit (1) ; }
# now print out the mail header and read the rest of the mail body.
foreach (@header)
{ print ($SD “$_\n”) ; }
print ($SD “\n”) ;
while ($line = <STDIN>)
{ print ($SD “$line”) ; }
$line = f_smtp_dialog ($SD, “.\n”, 250) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; }
$line = f_smtp_dialog ($SD, “QUIT\n”, 221) ;
if (length ($line) > 0)
{ printf (“FATAL! $ARGV[0] said: %s\n”, $line) ; }
exit (0) ;

openafs-part1

  1. yum groupinstall -y “Development Tools”, on my vagrant box scalefactory/centos6 , need to isntall ncurses too.
  2. yum update -y
  3. download openafs server from openafs website OpenAFS 1.6.20.1, 16MB
  4. ./configure –prefix=/usr/local/packages/openafs
  5. make, make install
  6. copy /etc/openafs from existing server
  7. in /etc/openafs/server, there is
    1
    2
    3
    4
    5
    6
    7
    i. CellServDB
    >example.com
    10.0.2.15
    ii. ThisCell
    srv.example.com
    iii.UserList
    afsadmin
  8. in /etc/openafs there is cacheinfo
    1
    /afs:/usr/local/packages/cache:500000

    might want to make a folder called /usr/local/packages/cache for it..

  9. its dangerous to go alone, take this:
    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
    #!/bin/bash
    #
    # Graceful AFS start and stop script.
    # Written by: [email protected]
    # Date 5th July 2008
    STOP_RETRIES=10 # seconds to attempt afs shutdown
    AFS=/usr/local/packages/openafs # where afs lives – symblink to current afs ver
    AFS_DB=”afs60 afs61 afs62″ # list of afs database servers
    case $1 in
    ‘start’)
    # Get a list of afs database servers first.
    DB=””
    REACHABLE=0
    CELLSERVDB=”$AFS/etc/openafs/CellServDB”
    for I in $AFS_DB ; do
    HOST=`grep $I $CELLSERVDB | awk ‘{print $1}’`
    if [ -z “$HOST” ] ; then
    echo “FATAL! Cannot locate $I in $CELLSERVDB”
    exit 1
    fi
    # do a simple ping test first.
    if [ “`uname -s`” = “SunOS” ] ; then
    ping -n -s $HOST 40 3 >/dev/null 2>/dev/null
    else
    ping -n -c 3 $HOST >/dev/null 2>/dev/null
    fi
    if [ $? -eq 0 ] ; then
    echo “$HOST ping test passed.”
    # use “bos” to test if afs database services are running.
    BOS=$AFS/bin/bos
    N=`$BOS status $HOST -noauth | grep running | wc -l | awk ‘{print $1}’`
    if [ $N -ge 4 ] ; then
    echo “$HOST bos status passed.”
    REACHABLE=1
    break
    else
    echo “WARNING! AFS services not running normally on $HOST.”
    fi
    else
    echo “WARNING! $HOST is not responding to ping.”
    fi
    done
    # only fire up AFS if at least 1 database server is reachable.
    if [ $REACHABLE -eq 0 ] ; then
    echo “FATAL! No AFS database servers reachable.”
    exit 1
    fi
    # check afs system call number (Solaris only) and load kernel module.
    if [ “`uname -s`” = “SunOS” ] ; then
    SYSNUM=`grep afs /etc/name_to_sysnum | awk ‘{print $2}’`
    if [ -z “$SYSNUM” ] ; then
    echo “FATAL! AFS name_to_sysnum not configured.”
    exit 1
    else
    if [ $SYSNUM -ne 65 ] ; then
    echo “FATAL! AFS name_to_sysnum not 65.”
    exit 1
    fi
    fi
    modload /kernel/fs/afs
    if [ $? -ne 0 ] ; then
    echo “FATAL! Failed to load AFS kernel module.”
    exit 1
    fi
    fi
    # on Linux we do a insmod
    if [ “`uname -s`” = “Linux” ] ; then
    insmod $AFS/lib/openafs/libafs.ko
    if [ $? -ne 0 ] ; then
    echo “FATAL! Failed to load AFS kernel module.”
    exit 1
    fi
    fi
    # the very last check is to make sure that /afs exists.
    if [ ! -d /afs ] ; then
    mkdir /afs
    if [ $? -ne 0 ] ; then
    exit 1
    fi
    fi
    # if we have a dedicated afs cache filesystem, mount it now,
    if [ -b /dev/zvol/dsk/mud/afs-cache ] ; then
    if [ ! -d /var/afs-cache ] ; then
    mkdir /var/afs-cache
    chmod 700 /var/afs-cache
    fi
    mount -o nologging /dev/zvol/dsk/mud/afs-cache /var/afs-cache
    fi
    # finally, check whether to use memory cache or not.
    mount | grep ‘/var/afs-cache’ >/dev/null
    if [ $? -eq 0 ] ; then
    $AFS/sbin/afsd
    else
    echo “starting with memcache”
    $AFS/sbin/afsd -memcache
    fi
    # allow setuid bit on /afs.
    if [ $? -eq 0 ] ; then
    $AFS/bin/fs setcell bii.a-star.edu.sg -suid
    fi
    ;;
    ‘stop’)
    # check if /afs is mounted, if not mounted, don’t bother.
    mount | grep AFS >/dev/null
    if [ “$?” != “0” ] ; then
    “FATAL! /afs is not mounted.”
    exit 1
    fi
    # check for processes using /afs, kill them before we continue.
    RETRIES=$STOP_RETRIES
    HALF_WAY=$(($STOP_RETRIES / 2))
    while [ $RETRIES -gt 0 ] ; do
    PIDS=`fuser /afs 2>/dev/null | cut -f 2- -d ‘ ‘ | sed -e ‘s/[^0-9 \t]//g’`
    if [ -z “$PIDS” ] ; then
    break
    fi
    if [ $RETRIES -gt $HALF_WAY ] ; then
    kill $PIDS
    else
    kill -9 $PIDS
    fi
    sleep 1
    RETRIES=$(($RETRIES – 1))
    done
    # at this point, it *should* be safe to umount /afs.
    $AFS/bin/fs flush
    umount /afs
    /sbin/rmmod libafs
    ;;
    ‘check’)
    $AFS/bin/fs checkservers
    $AFS/bin/fs checkvolumes
    ;;
    *)
    echo “Usage : $0 { start | stop | check }”
    ;;
    esac