From owner-freebsd-emulation@FreeBSD.ORG Fri Apr 29 21:45:07 2011 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 69F5F106566B for ; Fri, 29 Apr 2011 21:45:07 +0000 (UTC) (envelope-from stefan.tollkuehn@editura.de) Received: from mail.editura.de (mail.editura.de [92.198.64.67]) by mx1.freebsd.org (Postfix) with ESMTP id A32AF8FC17 for ; Fri, 29 Apr 2011 21:45:06 +0000 (UTC) Received: from localhost (autoreply [92.198.64.67]) by mail.editura.de (Postfix) with ESMTP id 78677850AAF for ; Fri, 29 Apr 2011 23:27:00 +0200 (CEST) Received: from mail.editura.de ([92.198.64.67]) by localhost (mail.editura.de [92.198.64.67]) (amavisd-maia, port 10024) with ESMTP id 13882-10 for ; Fri, 29 Apr 2011 23:26:54 +0200 (CEST) Received: from [192.168.128.243] (unknown [192.168.128.243]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: stefan.tollkuehn@editura.de) by mail.editura.de (Postfix) with ESMTPSA id 11218850AAD for ; Fri, 29 Apr 2011 23:26:54 +0200 (CEST) Message-ID: <4DBB2D1D.9090106@editura.de> Date: Fri, 29 Apr 2011 23:26:53 +0200 From: =?ISO-8859-1?Q?Stefan_Tollk=FChn?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110419 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: freebsd-emulation@freebsd.org References: <634914A010D0B943A035D226786325D422B76F91CA@EXVMBX020-12.exch020.serverdata.net> <41b7269d367ea0d98c3bd4071358d3ab@bluelife.at> <634914A010D0B943A035D226786325D422B76F9354@EXVMBX020-12.exch020.serverdata.net> <0cd75e5b5debaa8d6a20efeb69af90e9@bluelife.at> <7eb90bc16d977388d722269e4e05b9b7@bluelife.at> In-Reply-To: <7eb90bc16d977388d722269e4e05b9b7@bluelife.at> X-Enigmail-Version: 1.1.2 Content-Type: multipart/mixed; boundary="------------010206050808040903080705" X-Virus-Scanned: Maia Mailguard Subject: Re: AW: rc.d script for running multiple VirtualBox VMs from /etc/rc.conf X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Apr 2011 21:45:07 -0000 This is a multi-part message in MIME format. --------------010206050808040903080705 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi everybody, I tried to install the new vboxheadless script, but there is a problem if the users default shell is /usr/sbin/nologin. This prevents the command from running essential parts of the script in line 49, 83 and 106. First I tried to invoke the su command with -m but this didn't work. So I replaced su with sudo. This means sudo will be a new dependency for the virtualbox port, but this might be a minor problem, since sudo is most likely installed. At the moment I'm unable to test the script in a real life scenario by rebooting the host. I'll test it this weekend. ;) - -- Best regards Stefan Tollkühn Editura GmbH & Co. KG Tempelhofer Damm 2 - 12101 Berlin Telefon +49 (30) 789594981 Telefax +49 (30) 789594990 E-Mail stefan.tollkuehn@editura.de Amtsgericht Charlottenburg, HRA 43189 B, USt.Id. DE217180548 Geschäftsführer: Ralf Szymanski, Stefan Krause On 04/19/2011 07:57 PM, Bernhard Froehlich wrote: > On Mon, 18 Apr 2011 16:29:33 +0200, Bernhard Froehlich wrote: >> On Wed, 13 Apr 2011 05:28:44 -0700, Tobias Oberstein wrote: >>> Hi Bernhard, >>> >>>>> I wanted to configure multiple VirtualBox VMs to startup automatically >>>>> at boot time and generally be a nice citizen to the FreeBSD way of >>>>> starting up stuff. >>>>> >>>>> Using that rc.d script (see attached) you can configure starting up >>>>> multiple VirtualBox VMs from /etc/rc.conf: >>>> >>>> Sorry it's probably my fault because you're the 3rd one who has written such >>>> a script but we already have one for 4.0. >>> >>> Ah, ok;) >>> >>>> >>>> http://svn.bluelife.at/index.cgi/blueports/view/emulators/virtualbox-ose- >>>> devel/files/vboxheadless.in >>>> >>>> It is a bit less complicated and can also manage multiple VMs but it does not >>>> have separated flags per VM. >>> >>> Mine is more complicated, yes .. but it's more or less a direct >>> adaption of the script for apache22. >>> >>> Also, I definitely need flags per VM, since we run each VM >>> >>> i) under a dedicated user >>> ii) on a separate ZFS filesystem >>> iii) with specific VNC port/password >>> >>> i+iii requires flags per VM. >>> >>> iii) is for obvious reasons .. need to connect to each VM on a distinct port. >>> >>> i) is for a) security and b) management of VMs by different "VM >>> admins" which don't have to be root or have a user which would manage >>> all VMs. >>> >>> == >>> >>> I there interest to consolidate our scripts? >> >> I've merged the features together and got the following: >> >> # vboxheadless_enable (bool): Set to "NO" by default. >> # Set it to "YES" to enable >> vboxheadless. >> # vboxheadless_machines (str): Space separated list of machines >> # vboxheadless_user (str): Default user account to run with >> # vboxheadless__name (str): VBox machine name or UUID >> # vboxheadless__user (str): User account to run with >> # vboxheadless__flags (str): Custom flags for VBoxHeadless >> >> simple example: >> >> vboxheadless_enable="YES" >> vboxheadless_machines="FreeBSD Ubuntu1 Machine3" >> >> >> complex example: >> vboxheadless_enable="YES" >> vboxheadless_machines="vm1 vm2 Machine3" >> vboxheadless_user="vboxuser" >> >> vboxheadless_vm1_name="FreeBSD" >> vboxheadless_vm1_user="user1" >> >> vboxheadless_vm2_name="Ubuntu1" >> vboxheadless_vm2_user="user2" >> vboxheadless_vm2_flags="--vnc --vncport 4711 --vncpass " >> >> >> I could not test it yet but will do that in the evening and commit the >> new script to blueports. > > Done. http://svn.bluelife.at/index.cgi/blueports/revision/?rev=1287 > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk27LRwACgkQQYKEyEkJsIMNQACeLu1Fyj2eIvqoz9OVEqtFEsJZ 9akAnR0LybqddmXx9MO9KbEkTQ6tMdg4 =6ZR+ -----END PGP SIGNATURE----- --------------010206050808040903080705 Content-Type: text/plain; name="vboxheadless.in" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vboxheadless.in" #!/bin/sh # $FreeBSD$ # # PROVIDE: vboxheadless # REQUIRE: LOGIN vboxnet # KEYWORD: shutdown # # Add the following line to /etc/rc.conf[.local] to enable vboxheadless # # vboxheadless_enable (bool): Set to "NO" by default. # Set it to "YES" to enable vboxheadless. # vboxheadless_machines (str): Space separated list of machines # vboxheadless_user (str): Default user account to run with. # (default: %%VBOXUSER%%) # vboxheadless__name (str): Virtualbox machine name or UUID. # vboxheadless__user (str): User account to run with. # vboxheadless__flags (str): Additional flags for VBoxHeadless. . /etc/rc.subr name="vboxheadless" rcvar=`set_rcvar` command="%%PREFIX%%/bin/VBoxHeadless" pidbase="/var/run/${name}" start_cmd="${name}_start" stop_cmd="${name}_stop" status_cmd="${name}_status" vboxheadless_start() { local pid local mpidfile echo "Starting Virtual Machines:" for machine in ${vboxheadless_machines}; do mpidfile="${pidbase}_${machine}.pid" pid=$(check_pidfile $mpidfile $command) eval vmname="\${vboxheadless_${machine}_name:-${machine}}" eval vmuser="\${vboxheadless_${machine}_user:-${vboxheadless_user}}" eval vmflags="\${vboxheadless_${machine}_flags:-}" HOME=$(/usr/sbin/pw usershow -7 -n "${vmuser}" | /usr/bin/cut -d: -f6) /usr/bin/printf "%25s " "${vmname}" %%PREFIX%%/bin/sudo -u ${vmuser} %%PREFIX%%/bin/VBoxManage showvminfo "${vmname}" >/dev/null if [ $? != 0 ]; then echo "Unknown machine" continue fi if [ -n "${pid}" ]; then echo "Already running? (pid=${pid})" continue fi /usr/bin/touch ${mpidfile} /usr/sbin/chown ${vmuser} ${mpidfile} /usr/sbin/daemon -f -p ${mpidfile} -u ${vmuser} ${command} --startvm "${vmname}" ${vmflags} echo "Started" done } vboxheadless_stop() { local pid local mpidfile echo "Saving states for Virtual Machines:" for machine in ${vboxheadless_machines}; do mpidfile="${pidbase}_${machine}.pid" pid=$(check_pidfile $mpidfile $command) eval vmname="\${vboxheadless_${machine}_name:-${machine}}" eval vmuser="\${vboxheadless_${machine}_user:-${vboxheadless_user}}" /usr/bin/printf "%25s " "${vmname}" if [ -n "${pid}" ]; then %%PREFIX%%/bin/sudo -u ${vmuser} %%PREFIX%%/bin/VBoxManage controlvm "${vmname}" savestate >/dev/null wait_for_pids $pid >/dev/null echo "Stopped" else echo "Not running?" fi done } vboxheadless_status() { local pid local mpidfile /usr/bin/printf "%25s %s\n" "Machine" "Status" /usr/bin/printf "%25s %s\n" "-------------------------" "------------" for machine in ${vboxheadless_machines}; do mpidfile="${pidbase}_${machine}.pid" pid=$(check_pidfile $mpidfile $command) eval vmname="\${vboxheadless_${machine}_name:-${machine}}" eval vmuser="\${vboxheadless_${machine}_user:-${vboxheadless_user}}" %%PREFIX%%/bin/sudo -u ${vmuser} %%PREFIX%%/bin/VBoxManage showvminfo "${vmname}" >/dev/null if [ $? != 0 ]; then /usr/bin/printf "%20s %s\n" "${vmname}" "Unknown Machine" elif [ -n "${pid}" ]; then /usr/bin/printf "%25s %s\n" "${vmname}" "Running" else /usr/bin/printf "%25s %s\n" "${vmname}" "Powered Off" fi done } load_rc_config $name : ${vboxheadless_enable="NO"} : ${vboxheadless_machines=""} : ${vboxheadless_user="%%VBOXUSER%%"} cmd_arg="$1" if [ $# -gt 0 ]; then shift fi if [ -n "$*" ]; then vboxheadless_machines="$*" fi run_rc_command "${cmd_arg}" --------------010206050808040903080705--