default file creation when using reactor.spawnProcess
I'm attempting to move over PERL code to python code using the twisted framework. so far a few hiccups but this mailing list has helped me quite figure it out. I have a few few more hurdles, one being that since moving from Perl's my $cmd = "xvfb-run --auto-servernum firefox -P $profile_id"; $pid = open2($infh, $outfh, $cmd); to twisted's reactor.spawnProcess: subprocess = reactor.spawnProcess(self.pp, args[0], args, env = os.environ, usePTY=1, childFDs=None) when the xvfb/firefox processes create files they do so with root read/write, owner no permissions and group no permissions, using the the perl implementation the twisted daemon is run as a particular user and the file creation via firefox is rw rw rw which is what my goal is. What code would help those on the list willing to help? the daemon script code in init.d? Thanks in advance, so far this list has been golden! Stephan
I still have the issue, but I've found out that it has something to do with the fact that the twisted daemon isn't starting as the user I've asked it to start as. I know this because I dumped os.environ 145 for k,v in os.environ.items(): 146 logging.debug("%s : %s", k, v) 147 148 subprocess = reactor.spawnProcess(self.pp, args[0], args, env = os.environ, usePTY=1) and this is what I see: 2011-08-29 08:07:58,263 DEBUG:USERNAME : root 2011-08-29 08:07:58,263 DEBUG:LANG : en_US.UTF-8 2011-08-29 08:07:58,263 DEBUG:SUDO_GID : 1000 2011-08-29 08:07:58,263 DEBUG:SHELL : /bin/bash 2011-08-29 08:07:58,263 DEBUG:SUDO_COMMAND : /etc/init.d/fireshark start 2011-08-29 08:07:58,263 DEBUG:PYTHONPATH : 2011-08-29 08:07:58,263 DEBUG:SUDO_UID : 1000 2011-08-29 08:07:58,263 DEBUG:TERM : xterm 2011-08-29 08:07:58,263 DEBUG:PATH : /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 2011-08-29 08:07:58,263 DEBUG:PWD : /usr/sbin 2011-08-29 08:07:58,263 DEBUG:LOGNAME : root 2011-08-29 08:07:58,264 DEBUG:USER : root 2011-08-29 08:07:58,264 DEBUG:HOME : /home/fireshark 2011-08-29 08:07:58,264 DEBUG:MAIL : /var/mail/stephan 2011-08-29 08:07:58,264 DEBUG:SUDO_USER : stephan The daemon should be running as user fireshark, as that's what I have it start as in the /etc/init.d/fireshark script (shown below) does twisted follow a different convention for me to start the daemon as a different user? code from /etc/init.d/fireshark: 14 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 15 DAEMON=/usr/bin/twistd 16 RUNAS=fireshark 17 SERVICE_NAME=fireshark 18 SERVICE_PATH=/usr/sbin/fireshark.py 19 PIDFILE=/home/fireshark/fireshark.pid 20 LOGFILE=/home/fireshark/fireshark.log 21 DAEMON_OPTS="--pidfile=${PIDFILE} --logfile=${LOGFILE} --python ${SERVICE_PA TH}" 22 23 # Set python path so twistd can find the plugin 24 # See: http://twistedmatrix.com/projects/core/documentation/howto/plugin.htm l 25 export PYTHONPATH=$SERVICE_DIR 26 27 if [ ! -x $DAEMON ]; then 28 echo "ERROR: Can't execute $DAEMON." 29 exit 1 30 fi 31 32 if [ ! -x $SERVICE_PATH ]; then 33 echo "ERROR: Can't execute: $SERVICE_PATH" 34 exit 1 35 fi 36 37 start_service() { 38 echo -n " * Starting $SERVICE_NAME... " 39 start-stop-daemon -Sq --chuid ${RUNAS} --group ${RUNAS} -p $PIDFILE -x $DA EMON -- $DAEMON_OPTS 40 e=$? 41 if [ $e -eq 1 ]; then 42 echo "already running" 43 return On Sun, Aug 28, 2011 at 11:50 PM, Stephan <schenette@gmail.com> wrote:
I'm attempting to move over PERL code to python code using the twisted framework. so far a few hiccups but this mailing list has helped me quite figure it out.
I have a few few more hurdles, one being that since moving from Perl's
my $cmd = "xvfb-run --auto-servernum firefox -P $profile_id"; $pid = open2($infh, $outfh, $cmd);
to twisted's reactor.spawnProcess:
subprocess = reactor.spawnProcess(self.pp, args[0], args, env = os.environ, usePTY=1, childFDs=None)
when the xvfb/firefox processes create files they do so with root read/write, owner no permissions and group no permissions,
using the the perl implementation the twisted daemon is run as a particular user and the file creation via firefox is rw rw rw which is what my goal is.
What code would help those on the list willing to help? the daemon script code in init.d?
Thanks in advance, so far this list has been golden! Stephan
On Aug 29, 2011, at 8:20 AM, Stephan wrote:
I still have the issue, but I've found out that it has something to do with the fact that the twisted daemon isn't starting as the user I've asked it to start as.
The --chuid flag to start-stop-daemon is not seen by twistd; twistd is started by start-stop-daemon allegedly already running as that user. If this is a bug, it's a bug in your platform's startup-management tools, not Twisted itself. Note that os.environ['USER'] is informational only and does not represent the actual current user. Look at os.getuid() for the real number.
HI Glypyh, I'm using Ubuntu currently, what I'm trying to accomplish is changing the default file creation for the daemon, which from what I'm reading was changed some time ago. http://twistedmatrix.com/trac/ticket/966 what I'd like is for the twistd daemon to create files with a certain default file creation permission, so I'm looking at changing the umask, but so far I can't get the format correctly, as I'm trying to use what I'd normally use for chmod when starting twistd what is the correct format for umask? is what I have correct? desired result is rw for owner, group and world. 21 DAEMON_OPTS="--umask=0666 --pidfile=${PIDFILE} --logfile=${LOGFILE} --python ${SERVICE_PATH}" 22 23 # Set python path so twistd can find the plugin 24 # See: http://twistedmatrix.com/projects/core/documentation/howto/plugin.htm l 25 export PYTHONPATH=$SERVICE_DIR 26 27 if [ ! -x $DAEMON ]; then 28 echo "ERROR: Can't execute $DAEMON." 29 exit 1 30 fi 31 32 if [ ! -x $SERVICE_PATH ]; then 33 echo "ERROR: Can't execute: $SERVICE_PATH" 34 exit 1 35 fi 36 37 start_service() { 38 echo -n " * Starting $SERVICE_NAME... " 39 start-stop-daemon -Sq --chuid ${RUNAS} --group ${RUNAS} -p $PIDFILE -x $DA EMON -- $DAEMON_OPTS On Mon, Aug 29, 2011 at 9:45 AM, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:
On Aug 29, 2011, at 8:20 AM, Stephan wrote:
I still have the issue, but I've found out that it has something to do with the fact that the twisted daemon isn't starting as the user I've asked it to start as.
The --chuid flag to start-stop-daemon is not seen by twistd; twistd is started by start-stop-daemon allegedly already running as that user. If this is a bug, it's a bug in your platform's startup-management tools, not Twisted itself. Note that os.environ['USER'] is informational only and does not represent the actual current user. Look at os.getuid() for the real number.
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
On Aug 29, 2011, at 9:50 AM, Stephan wrote:
what I'd like is for the twistd daemon to create files with a certain default file creation permission, so I'm looking at changing the umask, but so far I can't get the format correctly, as I'm trying to use what I'd normally use for chmod
when starting twistd what is the correct format for umask? is what I have correct? desired result is rw for owner, group and world.
Not just in twistd, the terms "umask" and "chmod" are basically inverses. chmod sets the permissions of a file to a particular set of bits, but umask _masks out_ those bits on newly created files. The mask you want is "execute for everybody" (0b001001001) but you're currently specifying "everything but execute for everybody" (0b110110110). The Python interpreter can help you coerce this to octal, for use as a --umask command line option:
oct(0b001001001) '0111'
Hope this helps, -glyph
Thanks Glyph, I've been coding all night, I should have known umask from chmod but in order to accomplish the correct chmod I believe this is what I need: unmask=000 results in chmod = 666 (rw-rw-rw-) right? I realize this is now off topic, but just wanted to make sure it was correct. explicitly setting the umask I believe will fix the issue, testing now... Stephan On Mon, Aug 29, 2011 at 10:03 AM, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:
On Aug 29, 2011, at 9:50 AM, Stephan wrote:
what I'd like is for the twistd daemon to create files with a certain default file creation permission, so I'm looking at changing the umask, but so far I can't get the format correctly, as I'm trying to use what I'd normally use for chmod
when starting twistd what is the correct format for umask? is what I have correct? desired result is rw for owner, group and world.
Not just in twistd, the terms "umask" and "chmod" are basically inverses. chmod sets the permissions of a file to a particular set of bits, but umask _masks out_ those bits on newly created files. The mask you want is "execute for everybody" (0b001001001) but you're currently specifying "everything but execute for everybody" (0b110110110). The Python interpreter can help you coerce this to octal, for use as a --umask command line option:
oct(0b001001001) '0111' Hope this helps, -glyph
Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (2)
-
Glyph Lefkowitz
-
Stephan