qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Starting QEMU by PHP/Apache
@ 2009-10-13 11:26 Bolle
  2009-10-13 13:12 ` François Revol
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bolle @ 2009-10-13 11:26 UTC (permalink / raw)
  To: qemu-devel

Hello

Did anybody had success to start a QEMU instance by a PHP 
script under the Apache web server ?

I allow the Apache user with the help of sudoers to start 
the QEMU binary as root. I've hacked the "qemu-socket.c" 
to set the access mode to allow communication for the 
monitor socket (only add "chmod(path, <needed file mode 
bits>)").

I'm able to successfully start the QEMU instance from a 
PHP CLI script as the user under which Apache is running 
like "sudo -u <Apache user> sudo <qemu + args>". But when 
I run the same script by the web server, QEMU starts up to 
the BIOS, telling me to press F12 for a start device. The 
"info cpus" tells "CPU #0: pc=0x000f08b5 (halted)".

The full command executed by PHP is:
/usr/bin/sudo /usr/bin/qemu -L /usr/share/qemu -M isapc -m 
16 -hda </path/and/name/to/image> -net none -serial none 
-parallel none -vnc :0,password -monitor 
unix:</path/and/name/to/socket>,server,nowait -name "QEMU 
TEST" -pidfile </path/and/name/to/pid> -chroot 
</path/to/image> -runas <service user> > /dev/null &

Any idea about where to look for more information ?

Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] Starting QEMU by PHP/Apache
  2009-10-13 11:26 [Qemu-devel] Starting QEMU by PHP/Apache Bolle
@ 2009-10-13 13:12 ` François Revol
  2009-10-14  5:12 ` [Qemu-devel] " Bolle
  2009-10-20 10:10 ` [Qemu-devel] " Richard W.M. Jones
  2 siblings, 0 replies; 5+ messages in thread
From: François Revol @ 2009-10-13 13:12 UTC (permalink / raw)
  To: qemu-devel

Hi,

> Did anybody had success to start a QEMU instance by a PHP
> script under the Apache web server ?

see
http://dev.haiku-os.org/browser/haiku/trunk/3rdparty/mmu_man/onlinedemo/haiku.php

>
> I allow the Apache user with the help of sudoers to start
> the QEMU binary as root. I've hacked the "qemu-socket.c"
> to set the access mode to allow communication for the
> monitor socket (only add "chmod(path, <needed file mode
> bits>)").

Though I never neeeded to start it as root. It's probably a bad idea
anyway.

You might also ask the Free Live OS Zoo team, though I think they use
perl:
http://www.oszoo.org/wiki/index.php/Free_Live_OS_Zoo

>
> I'm able to successfully start the QEMU instance from a
> PHP CLI script as the user under which Apache is running
> like "sudo -u <Apache user> sudo <qemu + args>". But when
> I run the same script by the web server, QEMU starts up to
> the BIOS, telling me to press F12 for a start device. The
> "info cpus" tells "CPU #0: pc=0x000f08b5 (halted)".
>
> The full command executed by PHP is:
> /usr/bin/sudo /usr/bin/qemu -L /usr/share/qemu -M isapc -m
> 16 -hda </path/and/name/to/image> -net none -serial none
> -parallel none -vnc :0,password -monitor
> unix:</path/and/name/to/socket>,server,nowait -name "QEMU
> TEST" -pidfile </path/and/name/to/pid> -chroot
> </path/to/image> -runas <service user> > /dev/null &
>
> Any idea about where to look for more information ?

You might want to use a wrapper script instead...

François.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] Re: Starting QEMU by PHP/Apache
  2009-10-13 11:26 [Qemu-devel] Starting QEMU by PHP/Apache Bolle
  2009-10-13 13:12 ` François Revol
@ 2009-10-14  5:12 ` Bolle
  2009-10-16  4:49   ` [Qemu-devel] Re: [REASON][PATCH-REQUEST] " Bolle
  2009-10-20 10:10 ` [Qemu-devel] " Richard W.M. Jones
  2 siblings, 1 reply; 5+ messages in thread
From: Bolle @ 2009-10-14  5:12 UTC (permalink / raw)
  To: qemu-devel

qemu-devel@nongnu.org
Re: Starting QEMU by PHP/Apache

Hello all

First, I forgot to say, that I use the QEMU stable version 
11.0 on a Gentoo box. I did some more testings. The QEMU 
instance is starting and sometimes the OS starts to load, 
but then QEMU stucks and consumes 100% CPU.

I checked the startup it with strace. The start of QEMU 
itself produces the same output in strace, regardless if 
started by the PHP CLI or by mod_php from Apache.

I then attached strace to the QEMU process, and there is a 
big difference.

When starting QEMU with the PHP script from the CLI (as 
the same user as the web server), it works and I get 
something like that:
...
select(12, [6 11], [], [], {4, 993369}) = ? ERESTARTNOHAND 
(To be restarted)
--- SIGALRM (Alarm clock) @ 0 (0) ---
write(7, "\0"..., 1)                    = 1
sigreturn()                             = ? (mask now [])
clock_gettime(CLOCK_MONOTONIC, {2818001, 146485529}) = 0
clock_gettime(CLOCK_MONOTONIC, {2818001, 146548886}) = 0
timer_gettime(0, {it_interval={0, 0}, it_value={0, 0}}) = 
0
timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 
250000}}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC, {2818001, 146758750}) = 0
clock_gettime(CLOCK_MONOTONIC, {2818001, 146819115}) = 0
clock_gettime(CLOCK_MONOTONIC, {2818001, 146879549}) = 0
clock_gettime(CLOCK_MONOTONIC, {2818001, 146938839}) = 0
--- SIGALRM (Alarm clock) @ 0 (0) ---
write(7, "\0"..., 1)                    = 1
sigreturn()                             = ? (mask now [])
...

If QEMU has been started by the web server with the same 
script and user, I get:
...
select(11, [5 10], [], [], {3, 767239}) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {2817617, 818297714}) = 0
clock_gettime(CLOCK_MONOTONIC, {2817617, 818382772}) = 0
clock_gettime(CLOCK_MONOTONIC, {2817617, 818444894}) = 0
timer_gettime(0, {it_interval={0, 0}, it_value={0, 0}}) = 
0
timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 
250000}}, NULL) = 0
clock_gettime(CLOCK_MONOTONIC, {2817617, 818698197}) = 0
clock_gettime(CLOCK_MONOTONIC, {2817617, 818759263}) = 0
timer_gettime(0, {it_interval={0, 0}, it_value={0, 
67453}}) = 0
clock_gettime(CLOCK_MONOTONIC, {2817617, 818894002}) = 0
clock_gettime(CLOCK_MONOTONIC, {2817617, 818954673}) = 0
timer_gettime(0, {it_interval={0, 0}, it_value={0, 0}}) = 
0
timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 
250000}}, NULL) = 0
...

There are no SIGALRM executed. What can be the reason for 
that ?

Andreas



On Tue, 13 Oct 2009 13:26:25 +0200
  "Bolle" <bolle@geodb.org> wrote:
> Hello
> 
> Did anybody had success to start a QEMU instance by a 
>PHP script under the Apache web server ?
> 
> I allow the Apache user with the help of sudoers to 
>start the QEMU binary as root. I've hacked the 
>"qemu-socket.c" to set the access mode to allow 
>communication for the monitor socket (only add 
>"chmod(path, <needed file mode bits>)").
> 
> I'm able to successfully start the QEMU instance from a 
>PHP CLI script as the user under which Apache is running 
>like "sudo -u <Apache user> sudo <qemu + args>". But when 
>I run the same script by the web server, QEMU starts up 
>to the BIOS, telling me to press F12 for a start device. 
>The "info cpus" tells "CPU #0: pc=0x000f08b5 (halted)".
> 
> The full command executed by PHP is:
> /usr/bin/sudo /usr/bin/qemu -L /usr/share/qemu -M isapc 
>-m 16 -hda </path/and/name/to/image> -net none -serial 
>none -parallel none -vnc :0,password -monitor 
>unix:</path/and/name/to/socket>,server,nowait -name "QEMU 
>TEST" -pidfile </path/and/name/to/pid> -chroot 
></path/to/image> -runas <service user> > /dev/null &
> 
> Any idea about where to look for more information ?
> 
> Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] Re: [REASON][PATCH-REQUEST] Starting QEMU by PHP/Apache
  2009-10-14  5:12 ` [Qemu-devel] " Bolle
@ 2009-10-16  4:49   ` Bolle
  0 siblings, 0 replies; 5+ messages in thread
From: Bolle @ 2009-10-16  4:49 UTC (permalink / raw)
  To: qemu-devel

After some research, I think that Apache with mod_php is 
blocking the SIGALRM.

This is not the fault of QEMU. But maybe, QEMU could check 
on the start-up, if SIGALRM is enabled and usable. If not, 
then it can bail out and inform the user about this.

I believe, there are other environments where SIGALRM is 
blocked too.

Andreas

PS: Sorry for not being able to provide a patch by my 
self.


On Wed, 14 Oct 2009 07:12:56 +0200
  "Bolle" <bolle@geodb.org> wrote:
> Hello all
> 
>First, I forgot to say, that I use the QEMU stable 
>version 11.0 on a Gentoo box. I did some more testings. 
>The QEMU instance is starting and sometimes the OS starts 
>to load, but then QEMU stucks and consumes 100% CPU.
> 
> I checked the startup it with strace. The start of QEMU 
>itself produces the same output in strace, regardless if 
>started by the PHP CLI or by mod_php from Apache.
> 
> I then attached strace to the QEMU process, and there is 
>a big difference.
> 
> When starting QEMU with the PHP script from the CLI (as 
>the same user as the web server), it works and I get 
>something like that:
> ...
> select(12, [6 11], [], [], {4, 993369}) = ? 
>ERESTARTNOHAND (To be restarted)
> --- SIGALRM (Alarm clock) @ 0 (0) ---
> write(7, "\0"..., 1)                    = 1
> sigreturn()                             = ? (mask now 
>[])
> clock_gettime(CLOCK_MONOTONIC, {2818001, 146485529}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2818001, 146548886}) = 0
> timer_gettime(0, {it_interval={0, 0}, it_value={0, 0}}) 
>= 0
> timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 
>250000}}, NULL) = 0
> clock_gettime(CLOCK_MONOTONIC, {2818001, 146758750}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2818001, 146819115}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2818001, 146879549}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2818001, 146938839}) = 0
> --- SIGALRM (Alarm clock) @ 0 (0) ---
> write(7, "\0"..., 1)                    = 1
> sigreturn()                             = ? (mask now 
>[])
> ...
> 
> If QEMU has been started by the web server with the same 
>script and user, I get:
> ...
> select(11, [5 10], [], [], {3, 767239}) = 0 (Timeout)
> clock_gettime(CLOCK_MONOTONIC, {2817617, 818297714}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2817617, 818382772}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2817617, 818444894}) = 0
> timer_gettime(0, {it_interval={0, 0}, it_value={0, 0}}) 
>= 0
> timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 
>250000}}, NULL) = 0
> clock_gettime(CLOCK_MONOTONIC, {2817617, 818698197}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2817617, 818759263}) = 0
> timer_gettime(0, {it_interval={0, 0}, it_value={0, 
>67453}}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2817617, 818894002}) = 0
> clock_gettime(CLOCK_MONOTONIC, {2817617, 818954673}) = 0
> timer_gettime(0, {it_interval={0, 0}, it_value={0, 0}}) 
>= 0
> timer_settime(0, 0, {it_interval={0, 0}, it_value={0, 
>250000}}, NULL) = 0
> ...
> 
> There are no SIGALRM executed. What can be the reason 
>for that ?
> 
> Andreas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] Starting QEMU by PHP/Apache
  2009-10-13 11:26 [Qemu-devel] Starting QEMU by PHP/Apache Bolle
  2009-10-13 13:12 ` François Revol
  2009-10-14  5:12 ` [Qemu-devel] " Bolle
@ 2009-10-20 10:10 ` Richard W.M. Jones
  2 siblings, 0 replies; 5+ messages in thread
From: Richard W.M. Jones @ 2009-10-20 10:10 UTC (permalink / raw)
  To: Bolle; +Cc: qemu-devel

On Tue, Oct 13, 2009 at 01:26:25PM +0200, Bolle wrote:
> Did anybody had success to start a QEMU instance by a PHP script under 
> the Apache web server ?
>
> I allow the Apache user with the help of sudoers to start the QEMU binary 
> as root. I've hacked the "qemu-socket.c" to set the access mode to allow 
> communication for the monitor socket (only add "chmod(path, <needed file 
> mode bits>)").

I don't understand why you want to start qemu as root.  It doesn't
need to be root (even for KVM support) and we run it as non-root all
the time in http://libguestfs.org/

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-10-20 10:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-13 11:26 [Qemu-devel] Starting QEMU by PHP/Apache Bolle
2009-10-13 13:12 ` François Revol
2009-10-14  5:12 ` [Qemu-devel] " Bolle
2009-10-16  4:49   ` [Qemu-devel] Re: [REASON][PATCH-REQUEST] " Bolle
2009-10-20 10:10 ` [Qemu-devel] " Richard W.M. Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).