Skip to content

Instantly share code, notes, and snippets.

@hilotech
Created August 4, 2015 05:58
Show Gist options
  • Save hilotech/beea651457d43bc623f8 to your computer and use it in GitHub Desktop.
Save hilotech/beea651457d43bc623f8 to your computer and use it in GitHub Desktop.
Let's Chatのインストールスクリプト(CentOS 6.x w/ bash)
#!/bin/bash
set -e
set -u
# must replace with your own configuration
FQDN='letschat.your.domain'
yum -y install httpd git
cat <<'_EOF_' > /etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
_EOF_
yum -y install mongodb-org
cat <<'_EOF_' >> /etc/mongod.conf
journal=true
smallfiles=true
_EOF_
chkconfig mongod on
service mongod start
yum -y install epel-release
yum -y --enablerepo=epel install nodejs npm
yum -y install icu libicu-devel
npm install -g forever
[ ! -d /opt ] && mkdir /opt
cd /opt && git clone https://github.com/sdelements/lets-chat.git
cd lets-chat
npm update
npm install
cp settings.yml{.sample,}
sed -i -e '/^ *host: .*localhost.*$/d' settings.yml
echo -e '\ni18n:\n locale: ja\n' >> settings.yml
npm run migrate
cat <<_EOF_ > /etc/httpd/conf.d/vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName $FQDN
ProxyPass / http://$FQDN:5000/
ProxyPassReverse / http://$FQDN:5000/
</VirtualHost>
_EOF_
/bin/rm /etc/httpd/conf.d/welcome.conf
chkconfig httpd on
service httpd restart
cat <<'_EOF_' > /etc/init.d/letschat
#! /bin/sh
### BEGIN INIT INFO
# Provides: Lets chat
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Chatting Platform
# Description: Lets chat: Chatting Platform
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
APP_NAME='letschat'
DIR_VAR=/var/run/forever/letschat
DIR_APP_ROOT=/opt/lets-chat
FILE_LOG=/var/log/letschat
FILE_EXEC=app.js
export FOREVER_ROOT="$DIR_VAR"
export NODE_ENV=production
[[ ! -d "$DIR_VAR" ]] && mkdir -p "$DIR_VAR"
do_start() {
cd "$DIR_APP_ROOT" && \
forever start \
-l "$FILE_LOG" -e "$FILE_LOG" --append \
-p "$DIR_APP_ROOT" \
"$FILE_EXEC" \
|& logger
return $?
}
do_stop() {
cd "$DIR_APP_ROOT" && \
forever stopall \
|& logger
return $?
}
do_reload() {
cd "$DIR_APP_ROOT" && \
forever restart 0 \
|& logger
return $?
}
case "$1" in
start)
do_start
if [[ $? -ne 0 ]]; then
echo "[ $APP_NAME ] ERROR: Cannot start" >&2
exit 1
fi
echo "[ $APP_NAME ] Started" >&2
;;
stop)
do_stop
if [[ $? -ne 0 ]]; then
echo "[ $APP_NAME ] ERROR: Cannot stop" >&2
exit 1
fi
echo "[ $APP_NAME ] Stopped" >&2
;;
status)
cd "$DIR_APP_ROOT" && \
forever list
;;
restart|reload)
do_reload
if [[ $? -ne 0 ]]; then
echo "[ $APP_NAME ] ERROR: Cannot restart" >&2
exit 1
fi
echo "[ $APP_NAME ] Restarted" >&2
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
exit 3
;;
esac
:
_EOF_
chmod +x /etc/init.d/letschat
chkconfig letschat on
service letschat start
iptables -I INPUT -p tcp --dport http -j ACCEPT
service iptables save && service iptables restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment