diff --git a/config/app_config.yml.example b/config/app_config.yml.example index 0bd3771f79c4d55448f9b9b4fe6336863d84ec08..00dcb0b5fcde10b71941496ab8f1efd858b0dbd2 100644 --- a/config/app_config.yml.example +++ b/config/app_config.yml.example @@ -7,6 +7,7 @@ default: debug: false socket_debug : false socket_host: 0.0.0.0 + socket_pidfile: "log/diaspora-wsd.pid" socket_port: 8080 socket_collection_name: 'websocket' pubsub_server: 'https://pubsubhubbub.appspot.com/' @@ -18,7 +19,7 @@ default: smtp_authentication: 'plain' smtp_username: 'no-reply@example.com' smtp_password: 'secret' - + development: diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index eae34862b702e1d09865696ece1b3ef088c2bb08..63cbfba171a2e8fa1fe4dbc805b8cc80867d46a4 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -44,8 +44,7 @@ module Diaspora end def aspects_with_person person - id = person.id.to_id - aspects.select { |g| g.person_ids.include? id} + aspects.all(:person_ids => person.id) end def people_in_aspects aspects diff --git a/pkg/fedora/README.md b/pkg/fedora/README.md index e294302ce1a4a0818b4dce98fce5bed4d04a1028..7c5c9e3a266a5af8a76605e123e855b8ade4ca34 100644 --- a/pkg/fedora/README.md +++ b/pkg/fedora/README.md @@ -12,11 +12,11 @@ aimed for packaging purposes. Prerequisites: - ruby-1.8, rubygem, git and rake as described in - http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora - or http://github.com/diaspora/diaspora/wiki/Installing-on-CentOS-Fedora + [RPM installation Fedora](http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora) + or [Installing-on-CentOS-Fedora](http://github.com/diaspora/diaspora/wiki/Installing-on-CentOS-Fedora) - A personal environment to build RPM:s, also described in - http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora + [RPM installation Fedora](http://github.com/diaspora/diaspora/wiki/Rpm-installation-on-fedora) Install g++ (possibly unnnecessary?): % yum install gcc-c++ @@ -46,7 +46,7 @@ Start development server: cd /usr/share/diaspora/master ./script/server -See http://github.com/diaspora/diaspora/wiki/Using-apache for +See [Using Apache](http://github.com/diaspora/diaspora/wiki/Using-apache) for apache/passenger setup. After configuration, start with: /sbin/service diaspora-wsd start /sbin/service httpd restart @@ -120,7 +120,8 @@ directory, copy-paste previous version nr. It will be updated. This has been confirmed to start up and provide basic functionality both using the thin webserver and apache passenger, on 32/64 bit systems and in the -mock build environment. +mock build environment. Irregular nightly builds are available form time to time +at [ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) #### Implementation diff --git a/pkg/fedora/diaspora-setup b/pkg/fedora/diaspora-setup index 0fa90dc9e4a9435601d14c4ef21681432edeb81f..0214e419aa058ff03ae0944e95146f662cf0ad33 100755 --- a/pkg/fedora/diaspora-setup +++ b/pkg/fedora/diaspora-setup @@ -39,10 +39,11 @@ else exit 1 fi -# %attr(0777, diaspora, diaspora) doesn't work in specfile due to umask 022. -chmod 777 /var/lib/diaspora/uploads chown -R diaspora /var/log/diaspora +sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ + config/app_config.yml + hostname=$( awk '/pod_url:/ { print $2; exit }' <config/app_config.yml) if [ -n "$arg_hostname" ]; then diff --git a/pkg/fedora/diaspora-wsd b/pkg/fedora/diaspora-wsd index 6f0c7593f6daaa60e7c5554b25e84dbd751eb0ba..d4ad5395330179406fc7c4cc547daf2175c7a430 100755 --- a/pkg/fedora/diaspora-wsd +++ b/pkg/fedora/diaspora-wsd @@ -33,9 +33,9 @@ cd /usr/share/diaspora RETVAL=0 prog="Diaspora websocket server" exec="script/websocket_server.rb" -pidfile="/var/run/diaspora-wsd" +pidfile="/var/run/diaspora/diaspora-wsd" lockfile="/var/lock/subsys/diaspora-wsd" -logfile=/var/log/diaspora-wsd.log +logfile="/var/log/diaspora/diaspora-wsd.log" [ -n "$OPTIONS" ] && OPTIONS=" $OPTIONS" ruby_cmd="ruby -C $PWD $exec$OPTIONS" diff --git a/pkg/fedora/diaspora.spec b/pkg/fedora/diaspora.spec index 4c0cca719592fd9201300ce046defff33995b0c4..1d61026e5d29206c9bc3ebee886ac2bd64045aa8 100644 --- a/pkg/fedora/diaspora.spec +++ b/pkg/fedora/diaspora.spec @@ -77,6 +77,7 @@ mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/tmp cp %SOURCE2 $RPM_BUILD_ROOT/%{_datadir}/diaspora mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/log/diaspora +mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/run/diaspora mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/uploads mkdir -p $RPM_BUILD_ROOT/%{_localstatedir}/lib/diaspora/tmp @@ -94,6 +95,8 @@ find -L $RPM_BUILD_ROOT/%{_datadir}/diaspora -type f \ cat files >> dirs && mv -f dirs files sed -i -e '\|.*/master/config.ru"$|d' \ -e '\|.*/master/config/environment.rb"$|d' \ + -e '\|.*/run/diaspora"$|d' \ + -e '\|.*/pkg/fedora/dist"$|d' \ -e 's|%{buildroot}||' -e 's|//|/|' -e '/""/d' \ files @@ -101,6 +104,7 @@ sed -i -e '\|.*/master/config.ru"$|d' \ %post wsd /sbin/chkconfig --add diaspora-wsd || : + %preun wsd if [ $1 -eq 0 ] ; then service diaspora-wsd stop &>/dev/null || : @@ -117,9 +121,11 @@ rm -fr $RPM_BUILD_ROOT %doc AUTHORS README.md GNU-AGPL-3.0 COPYRIGHT README-Fedora.md %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config.ru %attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/config/environment.rb +%attr(-, diaspora, diaspora) %{_datadir}/diaspora/master/pkg/fedora/dist %attr(-, diaspora, diaspora) %{_localstatedir}/log/diaspora %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/uploads %attr(-, diaspora, diaspora) %{_localstatedir}/lib/diaspora/tmp +%attr(-, diaspora, diaspora) %{_localstatedir}/run/diaspora %{_datadir}/diaspora/master/tmp %{_datadir}/diaspora/master/public/uploads diff --git a/pkg/fedora/dist/.gitkeep b/pkg/fedora/dist/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/pkg/fedora/make-dist.sh b/pkg/fedora/make-dist.sh index 6777ae773be9faeeb7a9907e1275883fa516f2f9..ce450a3a7194217fa3e0d6f0119490ad9d4d3a8b 100755 --- a/pkg/fedora/make-dist.sh +++ b/pkg/fedora/make-dist.sh @@ -181,7 +181,6 @@ function make_bundle() # Usage: make_bundle [ commit, defaults to HEAD] # { -set -x checkout ${1:-'HEAD'} >/dev/null bundle_id=$( git_id dist/diaspora/Gemfile) bundle_name="diaspora-bundle-$VERSION-$bundle_id" diff --git a/pkg/ubuntu/README.md b/pkg/ubuntu/README.md index 15a4947dc941419a594437973e0badfd29d1e636..44e83c79bcc0a552f5beab7fc9001eda9b235b7e 100644 --- a/pkg/ubuntu/README.md +++ b/pkg/ubuntu/README.md @@ -5,6 +5,7 @@ work as a first step towards packaging, but should be usable as is. ### Synopsis + Bootstrap the distribution from git: % sudo apt-get install git-core % git clone git://github.com/diaspora/diaspora.git @@ -34,22 +35,17 @@ The normal procedure to update is to just $ ./make-dist.sh bundle $ ./make-dist.sh source -And then use diaspora-install and diaspora-install-bundle as above. +and then use diaspora-install and diaspora-install-bundle as above. It's necessary to always have the correct bundle. The *./make-dist.sh bundle* above will use a cached bundle if it's still valid, else build a new. In most cases only source will need to be built, which is fast. ### Notes -./make-dist.sh bundle|source occasionally fails on bad Gemfile.lock. The -root cause is a bad Gemfile.lock in the git repo. Possible fixes includes -using a older version known to work: - % ./make-dist.sh -c c818885b6 bundle - % ./make-dist.sh -c c818885b6 source - -or forcing a complete update of Gemfile.lock using 'bundle update' (a -potentially problematic operation): - % ./make-dist.sh -f bundle +The diaspora websocket service can be comtrolled through upstart. +To start/stop: + % sudo service diaspora-wsd start + % sudo service diaspora-wsd stop ./make-dist.sh bundle|source occasionally fails on bad Gemfile.lock. The root cause is a bad Gemfile.lock in the git repo. Possible fixes includes @@ -58,7 +54,7 @@ using a older version known to work: % ./make-dist.sh -c c818885b6 source or forcing a complete update of Gemfile.lock using 'bundle update' (a -potential problematic operation): +potentially problematic operation): % ./make-dist.sh -f bundle The application lives in /usr/share/diaspora/master. All writable areas @@ -79,19 +75,11 @@ dependencies lives in the application - nothing is installed by user or on system level. This has been tested on a Ubuntu 32-bit 10.10 , clean server and on 10.04 -Lucid desktop, also clean installation. +Lucid desktop, also clean installation. Irregular nightly builds are +available from time to time at +[ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds](ftp://mumin.dnsalias.net/pub/leamas/diaspora/builds) mongodb is having problems occasionally. Sometimes the dependencies are not installed, and mongod refuses to start. invoke */usr/bin/mongod -f /etc/mongodb.conf* to test. The lockfile /var/lib/mongodb/mongod.conf is also a potential problem. Remove to make it start again. - -The diaspora-wsd is just placeholder FTM, it does **not** work. - - - - - - - - diff --git a/pkg/ubuntu/diaspora-install b/pkg/ubuntu/diaspora-install index e7cef8f31b345fd2f038246459be251dba56fab8..7f7fd8c23241defc4644ccabcd702918f15ac312 100755 --- a/pkg/ubuntu/diaspora-install +++ b/pkg/ubuntu/diaspora-install @@ -30,9 +30,8 @@ sed -i '/BUNDLE_PATH/s|:.*|: /usr/lib/diaspora-bundle/bundle|' \ cp master/GNU-AGPL-3.0 master/COPYRIGHT master/README.md master/AUTHORS . cp master/config/app_config.yml.example ./app_config.yml -cp master/pkg/ubuntu/diaspora-wsd /etc/init.d +cp master/pkg/ubuntu/diaspora-wsd.conf /etc/init -sed -i '/^cd /s|.*|cd /usr/share/diaspora/master|' /etc/init.d/diaspora-wsd cp master/pkg/ubuntu/diaspora.logrotate /etc/logrotate.d/diaspora @@ -41,8 +40,8 @@ cp master/pkg/ubuntu/diaspora-setup . mkdir -p /var/log/diaspora mkdir -p /var/lib/diaspora/uploads mkdir -p /var/lib/diaspora/tmp +mkdir -p /var/run/diaspora mkdir -p /etc/diaspora -mkdir -p /usr/share/diaspora/master/pkg/ubuntu/dist ln -sf /var/log/diaspora ./master/log cp master/config/app_config.yml.example /etc/diaspora/app_config.yml @@ -65,5 +64,6 @@ chown diaspora:diaspora /var/log/diaspora chown diaspora:diaspora /var/lib/diaspora/uploads chown diaspora:diaspora /var/lib/diaspora/tmp chown diaspora:diaspora /var/lib/diaspora +chown diaspora:diaspora /var/run/diaspora chown diaspora:diaspora /usr/share/diaspora/master/pkg/ubuntu/dist diff --git a/pkg/ubuntu/diaspora-setup b/pkg/ubuntu/diaspora-setup index 3f2c0266c3371512b104428b5b2a5cb22e087fcc..32293a2d27170a09de8eeefed8f39a651ced4cc1 100755 --- a/pkg/ubuntu/diaspora-setup +++ b/pkg/ubuntu/diaspora-setup @@ -43,9 +43,11 @@ else exit 1 fi -chmod 777 /var/lib/diaspora/uploads chown -R diaspora /var/log/diaspora +sed -i '/socket_pidfile:/s|:.*|: /var/run/diaspora/diaspora-wsd.pid|' \ + config/app_config.yml + hostname=$( awk '/pod_url:/ { print $2; exit }' <config/app_config.yml) if [ -n "$arg_hostname" ]; then diff --git a/pkg/ubuntu/diaspora-wsd b/pkg/ubuntu/diaspora-wsd deleted file mode 100755 index e80f24f6ea9d40bb9aba5a869cd6b677aec3827a..0000000000000000000000000000000000000000 --- a/pkg/ubuntu/diaspora-wsd +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# -# /etc/rc.d/init.d/diaspora-wsd -# -# SHOULD start the diaspora websocket daemon, but it doesn't. No way. -# -# chkconfig: - 80 80 -# description: Diaspora websocket daemon - -### BEGIN INIT INFO -# Provides: diaspora-wsd -# Required-Start: $local_fs $network -# Required-Stop: $local_fs $network -# Should-Start: $remote_fs -# Should-Stop: $remote_fs -# Default-Start: -# Default-Stop: 0 1 2 3 4 5 6 -# Short-Description: start and stop Diaspora websocket server -# Description: The websocket server provides websocket services for -# diaspora. -### END INIT INFO - -# Source function library. -. /etc/init.d/functions - -if [ -f /etc/sysconfig/diaspora-wsd -a $UID -eq 0 ]; then - . /etc/sysconfig/diaspora-wsd -fi - -# Note: this line is patched by installation scripts. -cd /usr/share/diaspora - -RETVAL=0 -prog="Diaspora websocket server" -exec="script/websocket_server.rb" -pidfile="/var/run/diaspora-wsd" -lockfile="/var/lock/subsys/diaspora-wsd" -logfile=/var/log/diaspora-wsd.log - -[ -n "$OPTIONS" ] && OPTIONS=" $OPTIONS" -ruby_cmd="ruby -C $PWD $exec$OPTIONS" - -start() { - [ $UID -eq 0 ] || exit 4 - [ -f $exec ] || exit 5 - - echo -n $"Starting $prog: " - daemon --pidfile $pidfile "$ruby_cmd >>$logfile 2>&1 &" - RETVAL=$? - echo - if test $RETVAL = 0; then - touch $lockfile - pgrep -f "$ruby_cmd" > $pidfile || { - echo "Warning: cannot find running diaspora-webserver" - exit 7 - } - fi -} - -stop() { - [ $UID -eq 0 ] || exit 4 - echo -n $"Stopping $prog: " - killproc -p $pidfile $exec - RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f $lockfile - echo -} - -# -# See how we were called. -# -case "$1" in - start) - start - ;; - stop) - stop - ;; - force-reload|restart) - stop - sleep 1 - start - RETVAL=$? - ;; - condrestart|try-restart) - if [ -f $lockfile ]; then - stop - sleep 3 - start - fi - ;; - status) - status -p $pidfile $exec - RETVAL=$? - ;; - *) - echo $"Usage: $0 {condrestart|try-restart|start|stop|restart|force-reload|status}" - RETVAL=2 - [ "$1" = 'usage' ] && RETVAL=0 -esac - -exit $RETVAL diff --git a/pkg/ubuntu/diaspora-wsd.conf b/pkg/ubuntu/diaspora-wsd.conf new file mode 100644 index 0000000000000000000000000000000000000000..02956ebd9e86930cdf804314ab9c29b17f9a5d37 --- /dev/null +++ b/pkg/ubuntu/diaspora-wsd.conf @@ -0,0 +1,17 @@ +# Ubuntu upstart file at /etc/init/diaspora-wsd.conf + +start on runlevel [5] +stop on runlevel [06] + +script + if [ -f /etc/default/diaspora ]; then + . /etc/default/diaspora; + fi; + cd /usr/share/diaspora/master; + start-stop-daemon --start \ + --chuid diaspora:diaspora \ + --chdir $PWD \ + --exec "/usr/local/bin/bundle" \ + -- exec ruby -C $PWD script/websocket_server.rb; + +end script diff --git a/pkg/ubuntu/dist/.gitkeep b/pkg/ubuntu/dist/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 65199175e6258e3f06eeebe23dde14171a8f50ea..3b458118b4b9200ef50eb31d79b19dbbcaee8245 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -5,6 +5,25 @@ require File.dirname(__FILE__) + '/../config/environment' require File.dirname(__FILE__) + '/../lib/diaspora/websocket' +at_exit do + begin + File.delete(PID_FILE) + rescue + puts 'Cannot remove pidfile: ' + (PID_FILE ? PID_FILE : "NIL") + end +end + +def write_pidfile + begin + f = File.open(PID_FILE, "w") + f.write(Process.pid) + f.close + rescue => e + puts "Can't write to pidfile!" + puts e.inspect + end +end + CHANNEL = Magent::GenericChannel.new('websocket') def process_message if CHANNEL.queue_count > 0 @@ -36,7 +55,8 @@ begin ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } } end - + PID_FILE = APP_CONFIG[:socket_pidfile] + write_pidfile puts "Websocket server started." process_message } diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index c69954d174058dcdeb686db4c92243afc404377a..7f5c4bdd135fab8647a4d57c907351fa568db1e4 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -8,9 +8,9 @@ describe AspectsController do render_views before do - @user = Factory.create(:user) - @user.aspect(:name => "lame-os") - @person = Factory.create(:person) + @user = Factory.create(:user) + @aspect = @user.aspect(:name => "lame-os") + @person = Factory.create(:person) sign_in :user, @user end @@ -47,6 +47,15 @@ describe AspectsController do end end + describe "#move_friend" do + let(:opts) { {:friend_id => "person_id", :from => "from_aspect_id", :to => {:to => "to_aspect_id"}}} + it 'calls the move_friend_method' do + pending "need to figure out how to stub current_user to return our test @user" + @user.should_receive(:move_friend).with( :friend_id => "person_id", :from => "from_aspect_id", :to => "to_aspect_id") + post :move_friend, opts + end + end + describe "#update" do before do @aspect = @user.aspect(:name => "Bruisers") diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb index 9e6d01200c988136de3501a5cacf957c97a5f932..e52a42e7dfc3a6d3d159468691bc153b87ae3d2b 100644 --- a/spec/models/aspect_spec.rb +++ b/spec/models/aspect_spec.rb @@ -79,13 +79,26 @@ describe Aspect do aspect.people.size.should == 2 end - it 'should be accessible through the user' do - aspects = user.aspects_with_person(friend) - aspects.size.should == 1 - aspects.first.id.should == aspect.id - aspects.first.people.size.should == 2 - aspects.first.people.include?(friend).should be true - aspects.first.people.include?(user2.person).should be true + describe '#aspects_with_person' do + let!(:aspect_without_friend) {user.aspect(:name => "Another aspect")} + it 'should return the aspects with given friend' do + aspects = user.aspects_with_person(friend) + aspects.size.should == 1 + aspects.first.id.should == aspect.id + aspects.first.people.size.should == 2 + aspects.first.people.include?(friend).should be true + aspects.first.people.include?(user2.person).should be true + end + + it 'returns multiple aspects if the person is there' do + user.reload + user.add_person_to_aspect(friend.id, aspect1.id) + aspects = user.aspects_with_person(friend) + aspects.count.should == 2 + aspects.each{ |asp| asp.people.include?(friend) } + aspects.should_not include aspect_without_friend + end + end end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 7b6913c0cb80b9be01329318d8c513ef6a3a595b..70438bbeceef0023d48980d3747aa3c57053fd91 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -72,6 +72,8 @@ describe User do friend_users(user, aspect, user2, aspect2) friend_users(user, aspect, user3, aspect3) friend_users(user, aspect1, user4, aspect4) + user.add_person_to_aspect(user2.person.id, aspect1.id) + user.reload end describe '#push_to_aspects' do @@ -80,7 +82,7 @@ describe User do user.push_to_aspects(post, aspect.id) end - it 'should push a post to all aspects' do + it 'should push a post to friends in all aspects' do user.should_receive(:push_to_person).exactly(3).times user.push_to_aspects(post, :all) end @@ -92,5 +94,6 @@ describe User do user.push_to_people(post, [user2.person, user3.person]) end end + end end