Created
May 13, 2015 20:01
-
-
Save hilotech/e5b073dfe8745d1d4fc8 to your computer and use it in GitHub Desktop.
ConoHa [VPSでコラボ]Slackライクなチャット構築スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
set -u | |
FQDN='chat.ml.example.com' | |
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 | |
cat <<_EOF_ > /etc/httpd/vhosts/$FQDN.conf | |
<VirtualHost *:80> | |
ServerName $FQDN | |
ProxyPass / http://$FQDN:5000/ | |
ProxyPassReverse / http://$FQDN:5000/ | |
</VirtualHost> | |
_EOF_ | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment