[Slashdotjp-dev 924] [442] Fix: slashd daemonizes correctly

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 1月 20日 (日) 07:58:08 JST


Revision: 442
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=slashdotjp&view=rev&rev=442
Author:   tach
Date:     2008-01-20 07:58:08 +0900 (Sun, 20 Jan 2008)

Log Message:
-----------
Fix: slashd daemonizes correctly

Modified Paths:
--------------
    slashjp/trunk/debian/changelog
    slashjp/trunk/debian/slash-backend.init.d
    slashjp/trunk/sbin/slashd


-------------- next part --------------
Modified: slashjp/trunk/debian/changelog
===================================================================
--- slashjp/trunk/debian/changelog	2008-01-19 21:47:08 UTC (rev 441)
+++ slashjp/trunk/debian/changelog	2008-01-19 22:58:08 UTC (rev 442)
@@ -7,8 +7,9 @@
   * Fix: suppress _addGlobjEssentials_journals no nick for journal message by
     tagbox.pl
     - Do not process for deleted journals
+  * Fix: slashd daemonizes correctly
 
- -- Taku YASUI <tach****@osdn*****>  Sun, 20 Jan 2008 05:26:35 +0900
+ -- Taku YASUI <tach****@osdn*****>  Sun, 20 Jan 2008 06:51:13 +0900
 
 slash (2.5.0.189-1) unstable; urgency=low
 

Modified: slashjp/trunk/debian/slash-backend.init.d
===================================================================
--- slashjp/trunk/debian/slash-backend.init.d	2008-01-19 21:47:08 UTC (rev 441)
+++ slashjp/trunk/debian/slash-backend.init.d	2008-01-19 22:58:08 UTC (rev 442)
@@ -62,13 +62,13 @@
 	# the appropriate lines, below.  But why wouldn't you?
 
 	if [ "$MYSUDO" ] ; then
-		TZ=GMT $MYSUDO nice -n $NICE $SLASHD $VIRTUAL_USER_NAME &
+		TZ=GMT $MYSUDO nice -n $NICE $SLASHD $VIRTUAL_USER_NAME
 	elif [ "$OS" = "FreeBSD" ] ; then
-		TZ=GMT su $USERNAME -c "nice -n $NICE $SLASHD $VIRTUAL_USER_NAME" &
+		TZ=GMT su $USERNAME -c "nice -n $NICE $SLASHD $VIRTUAL_USER_NAME"
 	elif [ "$OS" = "Linux" ] ; then 
-		su --shell="/bin/sh" - $USERNAME -c "TZ=GMT nice -n $NICE $SLASHD $VIRTUAL_USER_NAME" &
+		su --shell="/bin/sh" - $USERNAME -c "TZ=GMT nice -n $NICE $SLASHD $VIRTUAL_USER_NAME"
 	else
-		su - $USERNAME -c "TZ=GMT nice -n $NICE $SLASHD $VIRTUAL_USER_NAME" &
+		su - $USERNAME -c "TZ=GMT nice -n $NICE $SLASHD $VIRTUAL_USER_NAME"
 	fi
 }
 
@@ -130,7 +130,8 @@
 			break_parts;
 			echo -n "Starting $PROGNAME $VIRTUAL_USER_NAME: ";
 			start_slashd;
-			echo "ok PID = $!";
+			sleep 1;
+			echo "ok PID = `cat ${RUNNINGPID}`";
 		done
 		;;
 

Modified: slashjp/trunk/sbin/slashd
===================================================================
--- slashjp/trunk/sbin/slashd	2008-01-19 21:47:08 UTC (rev 441)
+++ slashjp/trunk/sbin/slashd	2008-01-19 22:58:08 UTC (rev 442)
@@ -33,6 +33,7 @@
 use XML::Parser::Expat;
 use XML::RSS 0.95;
 use Schedule::Cron;
+use POSIX 'setsid';
 
 use Slash;
 use Slash::Constants ':slashd';
@@ -735,8 +736,20 @@
 
 sub main {
 
+	# daemon initialize: fork and exit
+	open(STDOUT, '+>' . devnull())
+		or die "Can't write to /dev/null: $!";
+	open(STDIN, '+<' . devnull())
+		or die "Can't read /dev/null: $!";
+	defined(my $pid = fork)
+		or die "Can't fork: $!";
+	exit if ($pid);
+	setsid()
+		or die "Can't start a new session: $!";
+
 	# Initialize logging and all the low-level stuff.
 
+	sleep 1; # (2007-01-20; slashjp) Insert this to avoid DB connection reset
 	slashdLogInit();
 	slashdLog("Starting up Slashd (verbosity " . verbosity()
 		. ") with pid $$");


Slashdotjp-dev メーリングリストの案内
Back to archive index