Here are the patches for a VServer adaption. Most are applied to the
VServer host. Some are applied to the X2Go Servers running as VServer
guests. It is explained in the documentation mailed previously. Thanks
- John
CREATE SCHEMA postgres;
create table postgres.sessions(
session_id varchar(500) primary key,
display integer not null,
uname varchar(100) not null,
server varchar(100) not null,
client inet,
status char(1) not null default 'R',
init_time timestamp not null default now(),
last_time timestamp not null default now(),
cookie char(33),
agent_pid int,
gr_port int,
sound_port int,
fs_port int,
unique(display)
);
CREATE LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION public.syncschema() RETURNS trigger AS '
DECLARE old_path TEXT;
BEGIN
-- Save old search_path; notice we must qualify current_setting
-- to ensure we invoke the right function
old_path := pg_catalog.current_setting(''search_path'');
-- Set a secure search_path: trusted schemas, then pg_temp.
-- We set is_local = true so that the old value will be restored
-- in event of an error before we reach the function end.
PERFORM pg_catalog.set_config(''search_path'', ''postgres, pg_temp'', true);
IF tg_op = ''INSERT'' THEN
insert into postgres.sessions (session_id,display,uname,server,client,status,init_time,last_time,cookie,agent_pid,gr_port,sound_port,fs_port) values (new.session_id,new.display,new.uname,new.server,new.client,new.status,new.init_time,new.last_time,new.cookie,new.agent_pid,new.gr_port,new.sound_port,new.fs_port);
ELSEIF tg_op = ''DELETE'' THEN
delete from postgres.sessions where session_id=old.session_id;
ELSEIF tg_op = ''UPDATE'' THEN
update postgres.sessions set display=new.display,uname=new.uname,server=new.server,client=new.client,status=new.status,init_time=new.init_time,last_time=new.last_time,cookie=new.cookie,agent_pid=new.agent_pid,gr_port=new.gr_port,sound_port=new.sound_port,fs_port=new.fs_port where session_id=old.session_id;
END IF;
-- Restore the search_path of the caller
PERFORM pg_catalog.set_config(''search_path'', old_path, true);
RETURN NULL;
END ' LANGUAGE plpgsql SECURITY DEFINER;
-- Add TRIGGER with a statement such as the following:
-- CREATE TRIGGER syncschema AFTER INSERT OR DELETE OR UPDATE ON <schema name>.sessions FOR EACH ROW EXECUTE PROCEDURE public.syncschema();
--- x2gocleansessions 2010-03-09 00:03:33.897612032 -0500
+++ x2gocleansessions.vs 2010-07-02 07:16:01.192016639 -0400
@@ -7,13 +7,15 @@
my $pid=shift;
my $sess=shift;
my $sec=shift;
+ my $guest=shift;
if($sec < 30)
{
return 1;
}
- open (F,"</proc/$pid/cmdline") or return 0;
- my $text=<F>;
- close (F);
+ $guest=~s/(.*?)\..*/$1/;
+ my $text=`vserver $guest exec cat /proc/$pid/cmdline`;
+ $?==0 or return 0;
+ chomp($text);
if($text =~ m/$sess/)
{
return 1;
@@ -25,7 +27,11 @@
{
my $sess=shift;
my $user=shift;
- my $log="~$user/.x2go/C-$sess/session.log";
+ my $guest=shift;
+ $guest=~s/(.*?)\..*/$1/;
+# EDIT THIS LINE ***********************
+# $log must be set to find the x2go session log in the user's home directory
+ my $log="/vservers/$guest/data/users/$user/.x2go/C-$sess/session.log";
my $text=`tail -1 $log`;
if($text =~ m/Session suspended/)
{
@@ -37,12 +43,27 @@
sub catch_term
{
- unlink("/var/run/x2goserver.pid");
+ unlink("/var/run/x2govscleanup.pid");
exit;
}
+sub set_state
+{
+ my $mode=shift;
+ my $user=shift;
+ my $guest=shift;
+ $guest=~s/(.*?)\..*/$1/;
+
+ my $stateflag="/vservers/$guest/data/users/$user/.x2go/.sflag";
+
+ if ($mode =~ /create_lock/) {
+ open(FH,">$stateflag"); close(FH);
+ } else {
+ unlink($stateflag);
+ }
+}
+
my $uname;
-#my $serv=$ENV{'HOSTNAME'};
my $serv = hostname;
my $pid = fork();
if (not defined $pid)
@@ -51,13 +72,12 @@
}
elsif ($pid != 0)
{
- open (F,">/var/run/x2goserver.pid");
+ open (F,">/var/run/x2govscleanup.pid");
print F "$pid\n";
close(F);
}
elsif ($pid == 0 )
{
-
close(STDIN);
close(STDOUT);
close(STDERR);
@@ -66,9 +86,7 @@
while(sleep 5)
{
- $serv=`hostname`;
- my $outp=`x2golistsessions_sql $serv 2>/dev/null`;
-
+ my $outp=`x2golistsessions_sql --all-servers 2>/dev/null`;
my @outp=split("\n","$outp");
for(my $i=0;$i<@outp;$i++)
@@ -78,28 +96,42 @@
{
#print "@sinfo[1], is blocked\n";
#print "(@sinfo[1])Unmounting all shares\n";
- system( "su @sinfo[11] -c \"export HOSTNAME && x2goumount_session @sinfo[1]\" 2> /dev/null");
+ set_state ("create_lock",@sinfo[11],@sinfo[3]);
+ system( "x2goumount_session @sinfo[1] @sinfo[3] @sinfo[11] 2> /dev/null");
+ set_state ("remove_lock",@sinfo[11],@sinfo[3]);
}
- elsif(! check_pid (@sinfo[0],@sinfo[1],@sinfo[12]))
+ elsif(! check_pid (@sinfo[0],@sinfo[1],@sinfo[12],@sinfo[3]))
{
- system("su @sinfo[11] -c \"sudo x2gopgwrapper changestatus 'F' @sinfo[1] \" > /dev/null");
+ set_state ("create_lock",@sinfo[11],@sinfo[3]);
+ system("x2gopgwrapper changestatus 'F' @sinfo[1] @sinfo[3] @sinfo[11] > /dev/null");
#print "@sinfo[1], pid @sinfo[0] not exist, changing status from @sinfo[4] to F\n";
#print "(@sinfo[1])Unmounting all shares\n";
- system( "su @sinfo[11] -c \"export HOSTNAME && x2goumount_session @sinfo[1]\" 2> /dev/null");
+ system( "x2goumount_session @sinfo[1] @sinfo[3] @sinfo[11] 2> /dev/null");
+ set_state ("remove_lock",@sinfo[11],@sinfo[3]);
+ }
+ elsif(@sinfo[4]eq 'S')
+ # The client suspend routing normally umounts but fails for lack of permissions in the vserver environment
+ # Thus, we must do the umount from the vserver host
+ {
+ set_state ("create_lock",@sinfo[11],@sinfo[3]);
+ system( "x2goumount_session @sinfo[1] @sinfo[3] @sinfo[11] 2> /dev/null");
+ set_state ("remove_lock",@sinfo[11],@sinfo[3]);
}
else
{
if(@sinfo[4]eq 'R')
{
- if(!check_stat(@sinfo[1],@sinfo[11]))
+ if(!check_stat(@sinfo[1],@sinfo[11],@sinfo[3]))
{
- system("su @sinfo[11] -c \"sudo x2gopgwrapper changestatus 'S' @sinfo[1] \" > /dev/null");
+ set_state ("create_lock",@sinfo[11],@sinfo[3]);
+ system("x2gopgwrapper changestatus 'S' @sinfo[1] @sinfo[3] @sinfo[11] > /dev/null");
#print "@sinfo[1], is suspended, changing status from @sinfo[4] to S\n";
#print "(@sinfo[1])Unmounting all shares\n";
- system( "su @sinfo[11] -c \"export HOSTNAME && x2goumount_session @sinfo[1]\" 2> /dev/null");
+ system( "x2goumount_session @sinfo[1] @sinfo[3] @sinfo[11] 2> /dev/null");
+ set_state ("remove_lock",@sinfo[11],@sinfo[3]);
}
}
}
}
}
-}
\ No newline at end of file
+}
--- x2golistsessions.orig 2010-07-02 06:17:43.060016728 -0400
+++ x2golistsessions 2010-07-02 06:19:29.109016696 -0400
@@ -31,6 +31,8 @@
$outp=`sudo x2gopgwrapper listsessions $serv`;
}
+my $stateflag="$ENV{'HOME'}/.x2go/.sflag";
+
my @outp=split("\n","$outp");
for(my $i=0;$i<@outp;$i++)
{
@@ -43,16 +45,7 @@
}
else
{
- if(@sinfo[4]eq 'R')
- {
- if(!check_stat(@sinfo[1]))
- {
- system("sudo x2gopgwrapper changestatus 'S' @sinfo[1] > /dev/null");
- @outp[$i] =~ s/\|R\|/\|S\|/;
- system( "x2goumount_session @sinfo[1]");
-
- }
- }
+ while ( -f "$stateflag" ) { sleep(1); }
print "@outp[$i]\n";
}
}
--- x2golistsessions_sql 2010-03-09 00:13:17.878612045 -0500
+++ x2golistsessions_sql.vs 2010-03-09 00:13:38.891605695 -0500
@@ -2,14 +2,7 @@
use strict;
my $serv=shift;
my $outp;
-if($serv eq "--all-servers")
-{
- $outp=`sudo x2gopgwrapper listsessionsroot_all`;
-}
-else
-{
- $outp=`sudo x2gopgwrapper listsessionsroot $serv`;
-}
+$outp=`x2gopgwrapper listsessionsroot_all`;
$outp =~ s/ //g;
$outp =~ s/\*/ /g;
@@ -21,7 +14,7 @@
my @ln=split('\|',@array[$i]);
if(@ln[4] eq "F")
{
- system("sudo x2gopgwrapper rmsessionsroot @ln[1]");
+ system("x2gopgwrapper rmsessionsroot @ln[1] @ln[3]");
}
print "@array[$i]\n";
}
--- x2gopgwrapper_net 2010-03-09 00:22:29.376611904 -0500
+++ x2gopgwrapper_net.vs 2010-03-09 00:23:11.016611953 -0500
@@ -1,60 +1,19 @@
#!/bin/bash
cd ~
-#use only with sudo !!
. /etc/x2go/x2godb.conf
SERVER=$1
-UNAME=$SUDO_USER
DBNAME=${DBNAME:-x2go_sessions}
+DBUSER=${DBUSER:-postgres}
+SCHEMA=""
case "$2" in
-getdisplays)
- echo "select '|'||display||'|' from sessions;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-getports)
- echo "select '|'||port||'|' from used_ports;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-getservers)
- echo "select server,count(*) from sessions where status != 'F' group by server;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-listsessions)
- echo "select agent_pid, session_id, display, server, status,\
- to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
- sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
- to_char(now()-init_time,'SSSS'),fs_port from sessions \
- where status !='F' and server='$3' and uname='$UNAME' order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-listsessions_all)
- echo "select agent_pid, session_id, display, server, status,\
- to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
- sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
- to_char(now()-init_time,'SSSS'),fs_port from sessions \
- where status !='F' and uname='$UNAME' order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-listsessionsroot)
- if [ "$UNAME" != "root" ]
- then
- echo "$UNAME, You have not permission to do this job!"
- exit
- fi
- echo "select agent_pid, session_id, display, server, status,\
- to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
- sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
- to_char(now()-init_time,'SSSS'),fs_port from sessions \
- where server='$3' order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
listsessionsroot_all)
- if [ "$UNAME" != "root" ]
+ if [ $(id -u) -ne 0 ]
then
- echo "$UNAME, You have not permission to do this job!"
+ echo "${USER}, You have not permission to do this job!"
exit
fi
echo "select agent_pid, session_id, display, server, status,\
@@ -64,117 +23,36 @@
order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
;;
-listsusp)
- if [ "$UNAME" != "root" ]
- then
- echo "$UNAME, You have not permission to do this job!"
- exit
- fi
- echo "select session_id, display, uname, server,extract( day from now()-last_time)*24*60+extract(hour from now()-last_time)*60+extract(minute from now()-last_time)\
- from sessions where server='$3' and status='S';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-
-listallrunning)
- if [ "$UNAME" != "root" ]
- then
- echo "$UNAME, You have not permission to do this job!"
- exit
- fi
- echo "select agent_pid, session_id, display, server, status,\
- to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
- sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
- to_char(now()-init_time,'SSSS'),fs_port from sessions \
- where status='R';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-listmails)
- if [ "$UNAME" != "root" ]
- then
- echo "$UNAME, You have not permission to do this job!"
- exit
- fi
- echo "select user_messages.mess_id,sessions.session_id,\
- sessions.uname,sessions.display from sessions,user_messages,\
- messages where sessions.uname=user_messages.uname and sessions.status!='F'\
- and messages.mess_id=user_messages.mess_id and sessions.server='$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-getmail)
- if [ "$UNAME" != "root" ]
- then
- echo "$UNAME, You have not permission to do this job!"
- exit
- fi
- echo "select message\
- from messages where mess_id='$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-
-rmmail)
- if [ "$UNAME" != "root" ]
- then
- echo "$UNAME, You have not permission to do this job!"
- exit
- fi
- echo "delete from \
- user_messages where mess_id='$3' and uname='$4';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-
rmsessionsroot)
- if [ "$UNAME" != "root" ]
+ if [ $(id -u) -ne 0 ]
then
- echo "$UNAME, You have not permission to do this job!"
+ echo "${USER}, You have not permission to do this job!"
exit
fi
- echo "delete from sessions \
+# ${4} is the server name
+ SCHEMA=${4//./___}
+ echo "delete from ${SCHEMA}.sessions \
where session_id='$3' ;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
;;
-
-getagent)
- echo "select agent_pid from sessions where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
getdisplay)
- echo "select display from sessions where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
+ SCHEMA=${4}
+ echo "select display from ${SCHEMA}.sessions where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
;;
changestatus)
- echo "update sessions set last_time=now(),status='$3' where session_id = '$4' and uname='$UNAME';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-resume)
- echo "update sessions set last_time=now(),status='R',client='$3' where session_id = '$4' and uname='$UNAME';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
- ;;
-
-insertsession)
- echo "insert into sessions (display,server,uname,session_id) values \
- ('$3','$4','$UNAME','$5');"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
- ;;
-
-createsession)
- echo "update sessions set status='R',last_time=now(),cookie='$3',agent_pid='$4',\
- client='$5',gr_port='$6',sound_port='$7',fs_port='$8' where session_id='$9' and uname='$UNAME';"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
- ;;
-
-insertport)
- echo "insert into used_ports (server,session_id,port) values \
- ('$3','$4','$5');"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
- ;;
-
-insertmount)
- echo "insert into mounts (session_id,path,client) values \
- ('$3','$4','$5');"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
+ SCHEMA=${5//./___}
+ echo "update ${SCHEMA}.sessions set last_time=now(),status='$3' where session_id = '$4' and uname='${6}';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
;;
deletemount)
- echo "delete from mounts where session_id='$3' and path='$4';"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
+ SCHEMA=${5}
+ echo "delete from ${SCHEMA}.mounts where session_id='$3' and path='$4';"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
;;
getmounts)
- echo "select client,path from mounts where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
+ SCHEMA=${4}
+ echo "select client,path from ${SCHEMA}.mounts where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
;;
*)
--- x2goumount_session 2010-03-09 00:33:09.061611889 -0500
+++ x2goumount_session.vs 2010-04-23 06:47:50.924797586 -0400
@@ -3,33 +3,26 @@
use strict;
my $session=shift;
-my $only_path=shift;
+# Since we could have any server we must pass in the server value
+my $serv=shift;
+my $schema=$serv;
+$schema=~s/\./___/g;
+$serv=~s/(.*?)\..*/$1/; # Take just the uid
+my $uname=shift;
-my $uname=$ENV{'USER'};
-my $serv=hostname;
-
-if($only_path)
-{
- $only_path=~s/\/ramdrive\/mnt\///;
- $only_path=~ s/\//_/g;
- my $end="_media";
- $only_path="$ENV{'HOME'}/media/$only_path";
-}
-
-
-my $outp=`sudo x2gopgwrapper getdisplay $session`;
+my $outp=`x2gopgwrapper getdisplay $session $schema`;
$outp=~s/ //g;
my $display=$outp;
-$outp=`sudo x2gopgwrapper getmounts $session`;
+$outp=`x2gopgwrapper getmounts $session $schema`;
my @outp=split("\n","$outp");
my $i;
-open (F,"</etc/mtab") or die "Can't open /etc/mtab for reading";
+open (F,"</vservers/$serv/etc/mtab") or die "Can't open /vservers/$serv/etc/mtab for reading";
my @mounts=<F>;
close(F);
@@ -49,13 +42,6 @@
chomp(@outp[$i]);
my @line=split('\|',"@outp[$i]");
my $path="@line[0]:@line[1]";
- if($only_path)
- {
- if (@line[1] ne $only_path)
- {
- goto cont;
- }
- }
my $j;
my $found=0;
my $remote;
@@ -71,20 +57,20 @@
break:
if($found)
{
- if(system( "fusermount -u @line[1]" ) == 0)
+ if(system( "vserver $serv exec umount @line[1]" ) == 0)
{
$found=0;
}
else
{
- $ENV{'DISPLAY'}=":$display";
+ system("logger -t \"X2GOUMOUNT ERROR \" \"Failed to unmount @line[1] on $serv\"");
if($use_zenity == 0)
{
- system("kdialog --error \"@line[1]\"&");
- }
+ system("vserver $serv exec kdialog --display :$display --error \"@line[1]\"&");
+ }
else
{
- system("zenity --error --text \"@line[1]\"&");
+ system("vserver $serv exec zenity --display :$display --error --text \"@line[1]\"&");
}
}
}
@@ -92,7 +78,7 @@
{
$remote=~s/\//_/g;
$remote=(split(":","$remote"))[1];
- $remote="$ENV{'HOME'}/Desktop/$remote";
+ $remote="/vservers/$serv/data/users/$uname/Desktop/$remote";
if( -e "$remote(sshfs-disk)")
{
unlink("$remote(sshfs-disk)");
@@ -108,7 +94,7 @@
unlink("$remote(sshfs-cdrom)");
}
#print "$session \"@line[1]\"\n";
- system("sudo x2gopgwrapper deletemount $session \"@line[1]\"> /dev/null");
+ system("x2gopgwrapper deletemount $session \"@line[1]\" $schema > /dev/null");
rmdir (@line[1]);
}
cont:
_______________________________________________
X2go-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/x2go-dev