1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/diaspora_ynh.git synced 2024-09-03 18:26:13 +02:00

isolation and home change

isolation diaspora package natif debian + changement home
This commit is contained in:
Développeur égaré 2015-02-17 11:13:33 +01:00
parent 7878c4d99e
commit d838593f30
7 changed files with 240 additions and 26 deletions

View file

@ -1,6 +1,6 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: diaspora
# Provides: diaspora_ynh
# Required-Start: $remote_fs $syslog mysql redis-server
# Required-Stop: $remote_fs $syslog mysql redis-server
# Default-Start: 2 3 4 5
@ -11,6 +11,7 @@
# Author: FABIAN Tamas Laszlo <giganetom@gmail.com>
# Updated: Pirate Praveen <praveen@debian.org>
# Updated: aymhce <aymhce@gmail.com>
# PATH should only include /usr/* if it runs after the mountnfs.sh script
# Note: /usr/local/bin for foreman gem
@ -71,7 +72,11 @@ do_start()
return 1
fi
. /etc/diaspora.conf
export SERVERNAME=localhost
export ENVIRONMENT_URL=http://localhost
export RAILS_ENV=production
export DB=mysql
cd $DIASPORA_HOME
sudo su - $USER -c " . ~/.bashrc && cd $DIASPORA_HOME && $STARTSCRIPT >> $LOGFILE 2>&1 " &
if [ $? -gt 0 ]

View file

@ -1,4 +0,0 @@
export SERVERNAME=localhost
export ENVIRONMENT_URL=http://localhost
export RAILS_ENV=production
export DB=mysql

View file

@ -139,7 +139,7 @@ configuration: ## Section
server: ## Section
## The port on which the appserver should listen (default=3000):
#port: 3000
port: 3986
## Rails environment (default='development')
## The environment in which the server should be started by default.

221
conf/diaspora_ynh Normal file
View file

@ -0,0 +1,221 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: diaspora
# Required-Start: $remote_fs $syslog mysql redis-server
# Required-Stop: $remote_fs $syslog mysql redis-server
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Diaspora application server
# Description: Start / stop the Diaspora app server
### END INIT INFO
# Author: FABIAN Tamas Laszlo <giganetom@gmail.com>
# Updated: Pirate Praveen <praveen@debian.org>
# PATH should only include /usr/* if it runs after the mountnfs.sh script
# Note: /usr/local/bin for foreman gem
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC="Diaspora application server"
NAME=diaspora
DIASPORA_HOME="/var/www/diaspora"
STARTSCRIPT="./script/server"
LOGFILE=$DIASPORA_HOME/log/startscript.log
SCRIPTNAME=$0
USER=diaspora
STARTUP_TIMEOUT=100
. /lib/init/vars.sh
. /lib/lsb/init-functions
check_unicorn() {
pgrep -f "unicorn_rails master"
}
check_sidekiq() {
pgrep -f "sidekiq 2"
}
check_foreman() {
pgrep -f "foreman-runner"
}
check_foreman_start() {
pgrep -f "foreman start"
}
check_script_server() {
pgrep -f "script/server"
}
do_start()
{
if ! touch $LOGFILE; then
log_failure_msg "Could not touch logfile"
return 2
fi
if ! chown $USER $LOGFILE; then
log_failure_msg "Could not chown logfile"
return 2
fi
if check_unicorn && check_sidekiq; then
log_warning_msg "Diaspora is already running"
return 1
fi
if check_foreman || check_foreman_start || check_script_server; then
log_warning_msg "Diaspora is starting"
return 1
fi
export SERVERNAME=localhost
export ENVIRONMENT_URL=http://localhost
export RAILS_ENV=production
export DB=mysql
cd $DIASPORA_HOME
sudo su - $USER -c " . ~/.bashrc && cd $DIASPORA_HOME && $STARTSCRIPT >> $LOGFILE 2>&1 " &
if [ $? -gt 0 ]
then
log_failure_msg "Could not run start script"
return 2
else
log_success_msg "Starting diaspora server..."
return 0
fi
[ "$VERBOSE" != no ] && log_action_msg "Waiting for Diaspora processes... "
c=0
while ! check_unicorn > /dev/null || ! check_sidekiq > /dev/null; do
if [ $c -gt $STARTUP_TIMEOUT ]; then
log_failure_msg "Timeout waiting for Diaspora processes"
return 2
fi
c=`expr $c + 1`
sleep 1
[ "$VERBOSE" != no ] && echo -n "."
done
[ "$VERBOSE" != no ] && log_action_end_msg 0
}
do_stop()
{
for i in `check_unicorn`; do
[ "$VERBOSE" != no ] && log_action_msg "Killing unicorn master with PID $i"
kill -TERM $i
[ "$VERBOSE" != no ] && log_action_end_msg $?
done
for i in `check_sidekiq`; do
[ "$VERBOSE" != no ] && log_action_msg "Killing sidekiq with PID $i"
kill -TERM $i
[ "$VERBOSE" != no ] && log_action_end_msg $?
done
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
*) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
log_daemon_msg 'Checking for running Diaspora processes'
if ! check_unicorn
then
log_action_msg "unicorn not found"
unicorn_running=false
else
for i in `check_unicorn`; do
log_action_msg "Found unicorn master with PID $i"
unicorn_running=true
done
fi
if ! check_foreman
then
log_action_msg "foreman not found"
foreman_running=false
else
for i in `check_foreman`; do
log_action_msg "Found foreman with pid $i"
foreman_running=true
done
fi
if ! check_sidekiq
then
log_action_msg "sidekiq is not found"
sidekiq_running=false
else
for i in `check_sidekiq`; do
log_action_msg "Found sidekiq with PID $i"
sidekiq_running=true
done
fi
if $foreman_running && ! $unicorn_running; then
log_action_msg "Diaspora is starting, check after some time..."
log_end_msg 0
return 0
fi
if $unicorn_running && $sidekiq_running; then
log_action_msg "Diaspora health is OK"
log_end_msg 0
else
if $unicorn_running; then
log_failure_msg "Unicorn is RUNNING, but sidekiq is DOWN!"
log_end_msg 1
return 1
fi
if $sidekiq_running; then
log_failure_msg "Sidekiq is RUNNING, but unicorn is DOWN!"
log_end_msg 1
return 1
fi
log_daemon_msg "All Diaspora processes are DOWN"
log_end_msg 0
fi
;;
restart|force-reload)
[ "$VERBOSE" != no ] && log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
1) [ "$VERBOSE" != no ] && log_failure_msg "old process is still running" && log_end_msg 1 ;;
*) [ "$VERBOSE" != no ] && log_failure_msg "failed to start" && log_end_msg 1 ;;
esac
;;
*)
[ "$VERBOSE" != no ] && log_failure_msg "failed to stop"
[ "$VERBOSE" != no ] && log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:

View file

@ -26,5 +26,5 @@ location PATHTOCHANGE {
# Add as many server directives as you want
# Also takes a socket, like unix:/path/to/some/socket.sock
upstream diaspora_server {
server 127.0.0.1:3000;
server 127.0.0.1:3986;
}

View file

@ -46,7 +46,7 @@ sudo chown -R diaspora:diaspora $final_path
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
# Use 'diaspora' as database name and user
db_user=diaspora
db_user=diaspora
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd -d diaspora_production
@ -58,18 +58,15 @@ sed -i "s@DBUSERTOCHANGE@$db_user@g" ../conf/database.yml
sed -i "s@DBPASSTOCHANGE@$db_user@g" ../conf/database.yml
sudo cp ../conf/diaspora.yml $final_path/config/
sudo cp ../conf/database.yml $final_path/config/
sudo cp ../conf/diaspora.conf /etc/
sudo chown -R diaspora:diaspora $final_path
# install startup script
sudo cp ../conf/diaspora /etc/init.d/diaspora
sudo chmod 754 /etc/init.d/diaspora
sudo update-rc.d diaspora defaults
sudo cp ../conf/diaspora_ynh /etc/init.d/diaspora_ynh
sudo chmod 754 /etc/init.d/diaspora_ynh
sudo update-rc.d diaspora_ynh defaults
# create and config user
sudo adduser --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --quiet --disabled-login --home /home/yunohost.app/diaspora diaspora
sudo mkdir -p /home/yunohost.app/diaspora
sudo chown -R diaspora:diaspora /home/yunohost.app/diaspora
sudo adduser --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --quiet --disabled-login --home $final_path diaspora
sudo su diaspora
cd ~
@ -93,15 +90,12 @@ RAILS_ENV=production bundle install --without test development
RAILS_ENV=production bundle exec rake db:create db:schema:load
RAILS_ENV=production bundle exec rake assets:precompile
# TODO a startup init.d script !!
#./script/server >/dev/null &
exit
cd $ori_path
# start service
sudo service diaspora start
sudo service diaspora_ynh start
# config nginx
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf

View file

@ -5,18 +5,16 @@ db_name=diaspora
root_pwd=$(sudo cat /etc/yunohost/mysql)
domain=$(sudo yunohost app setting diaspora domain)
sudo service diaspora stop
sudo service diaspora_ynh stop
mysql -u root -p$root_pwd -e "DROP DATABASE $db_name ; DROP USER $db_user@localhost ;"
sudo rm -rf /var/www/diaspora
sudo rm -f /etc/nginx/conf.d/$domain.d/diaspora.conf
sudo service nginx reload
sudo deluser --remove-home diaspora
sudo rm -rf /var/www/diaspora
sudo update-rc.d -f diaspora remove
sudo rm -f /etc/init.d/diaspora
sudo rm -f /etc/diaspora.conf
sudo update-rc.d -f diaspora_ynh remove
sudo rm -f /etc/init.d/diaspora_ynh