From 373f00b6e020b465bc6bd39c65cc52e8cc7c8221 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 22 Nov 2010 13:14:37 +0100 Subject: [PATCH 1/4] bug #394: added init scripts created by Dan Yocum and Damien Raude-Morvan --- share/etc/init.d/one.debian | 95 ++++++++++++++++ share/etc/init.d/one.ubuntu | 95 ++++++++++++++++ share/etc/init.d/oned.centos | 195 +++++++++++++++++++++++++++++++++ share/etc/init.d/oned.opensuse | 195 +++++++++++++++++++++++++++++++++ 4 files changed, 580 insertions(+) create mode 100755 share/etc/init.d/one.debian create mode 100755 share/etc/init.d/one.ubuntu create mode 100755 share/etc/init.d/oned.centos create mode 100755 share/etc/init.d/oned.opensuse diff --git a/share/etc/init.d/one.debian b/share/etc/init.d/one.debian new file mode 100755 index 0000000000..fe34910279 --- /dev/null +++ b/share/etc/init.d/one.debian @@ -0,0 +1,95 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: opennebula +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: OpenNebula init script +# Description: OpenNebula cloud initialisation script +### END INIT INFO + +# Author: Soren Hansen + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="OpenNebula cloud" +NAME=one +DAEMON=/usr/bin/$NAME +DAEMON_ARGS="" +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + mkdir -p /var/run/one /var/lock/one + chown oneadmin /var/run/one /var/lock/one + su oneadmin -s /bin/sh -c 'one start' +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + su oneadmin -s /bin/sh -c 'one stop' +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/share/etc/init.d/one.ubuntu b/share/etc/init.d/one.ubuntu new file mode 100755 index 0000000000..fe34910279 --- /dev/null +++ b/share/etc/init.d/one.ubuntu @@ -0,0 +1,95 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: opennebula +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: OpenNebula init script +# Description: OpenNebula cloud initialisation script +### END INIT INFO + +# Author: Soren Hansen + +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="OpenNebula cloud" +NAME=one +DAEMON=/usr/bin/$NAME +DAEMON_ARGS="" +PIDFILE=/var/run/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + mkdir -p /var/run/one /var/lock/one + chown oneadmin /var/run/one /var/lock/one + su oneadmin -s /bin/sh -c 'one start' +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + su oneadmin -s /bin/sh -c 'one stop' +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/share/etc/init.d/oned.centos b/share/etc/init.d/oned.centos new file mode 100755 index 0000000000..883d29ac83 --- /dev/null +++ b/share/etc/init.d/oned.centos @@ -0,0 +1,195 @@ +#!/bin/bash +# +# oned This shell script takes care of starting and stopping +# the Opennebula subsystem (oned). +# +# chkconfig: - 65 35 +# description: oned cloud server. +# processname: oned +# config: /etc/one/oned.conf +# pidfile: /var/run/one/oned.pid + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Set the ONE_LOCATION +# ONE_LOCATION="/srv/cloud/one" +ONE_LOCATION="" + +prog="oned" + +if [ -z "$ONE_LOCATION" ]; then + ONE_PID=/var/run/one/oned.pid + ONE_SCHEDPID=/var/run/one/sched.pid + ONE_CONF=/etc/one/oned.conf + ONE_DB=/var/lib/one/one.db + + ONED=/usr/bin/oned + ONE_SCHEDULER=/usr/bin/mm_sched + + LOCK_FILE=/var/lock/one/one +else + ONE_PID=$ONE_LOCATION/var/oned.pid + ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid + ONE_CONF=$ONE_LOCATION/etc/oned.conf + ONE_DB=$ONE_LOCATION/var/one.db + + ONED=$ONE_LOCATION/bin/oned + ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched + + LOCK_FILE=$ONE_LOCATION/var/.lock +fi + +setup() +{ + PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` + + if [ $? -ne 0 ]; then + echo "Can not find PORT in $ONE_CONF." + exit 1 + fi + + if [ -f $LOCK_FILE ]; then + if [ -f $ONE_PID ]; then + ONEPID=`cat $ONE_PID` + ps $ONEPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + if [ -f $ONE_SCHEDPID ]; then + ONESCHEDPID=`cat $ONE_SCHEDPID` + ps $ONESCHEDPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + echo "Stale .lock detected. Erasing it." + rm $LOCK_FILE + fi +} + +start() +{ + if [ ! -x "$ONED" ]; then + echo "Can not find $ONED." + exit 1 + fi + + if [ ! -x "$ONE_SCHEDULER" ]; then + echo "Can not find $ONE_SCHEDULER." + exit 1 + fi + + if [ ! -f "$ONE_DB" ]; then + if [ -f "$HOME/.one/one_auth" ]; then + . $HOME/.one/one_auth + elif [ -z "$ONE_AUTH" ]; then + echo "You should have ONE_AUTH set the first time you start" + echo "OpenNebula as it is used to set the credentials for" + echo "the adminitrator user." + exit 1 + fi + fi + + # Start the one daemon + daemon --user=oneadmin $ONED -f 2>&1 & + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONED" + exit 1 + else + echo $LASTPID > $ONE_PID + fi + + sleep 1 + ps $LASTPID > /dev/null 2>&1 + + if [ $? -ne 0 ]; then + echo "Error executing $ONED." + exit 1 + fi + + # Start the scheduler + # The following command line arguments are supported by mm_shed: + # [-p port] to connect to oned - default: 2633 + # [-t timer] seconds between two scheduling actions - default: 30 + # [-m machines limit] max number of VMs managed in each scheduling action + # - default: 300 + # [-d dispatch limit] max number of VMs dispatched in each scheduling action + # - default: 30 + # [-h host dispatch] max number of VMs dispatched to a given host in each + # scheduling action - default: 1 + + daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONE_SCHEDULER" + exit 1 + else + echo $LASTPID > $ONE_SCHEDPID + fi + + echo "oned and scheduler started" +} + +# +# Function that stops the daemon/service +# +stop() +{ + if [ ! -f $ONE_PID ]; then + echo "Couldn't find oned process pid." + exit 1 + fi + + if [ ! -f $ONE_SCHEDPID ]; then + echo "Couldn't find scheduler process pid." + exit 1 + fi + + # Kill the one daemon + + killproc oned + + # Kill the scheduler + + killproc mm_sched + + # Remove pid files + + rm -f $ONE_PID > /dev/null 2>&1 + rm -f $ONE_SCHEDPID > /dev/null 2>&1 + + echo "oned and scheduler stopped" +} + + +case "$1" in + start) + setup + start + ;; + stop) + stop + ;; + status) + status oned + status mm_sched + ;; + *) + echo "Usage: one {start|stop|status}" >&2 + exit 3 + ;; +esac diff --git a/share/etc/init.d/oned.opensuse b/share/etc/init.d/oned.opensuse new file mode 100755 index 0000000000..883d29ac83 --- /dev/null +++ b/share/etc/init.d/oned.opensuse @@ -0,0 +1,195 @@ +#!/bin/bash +# +# oned This shell script takes care of starting and stopping +# the Opennebula subsystem (oned). +# +# chkconfig: - 65 35 +# description: oned cloud server. +# processname: oned +# config: /etc/one/oned.conf +# pidfile: /var/run/one/oned.pid + +# Source function library. +. /etc/rc.d/init.d/functions + +# Source networking configuration. +. /etc/sysconfig/network + +# Set the ONE_LOCATION +# ONE_LOCATION="/srv/cloud/one" +ONE_LOCATION="" + +prog="oned" + +if [ -z "$ONE_LOCATION" ]; then + ONE_PID=/var/run/one/oned.pid + ONE_SCHEDPID=/var/run/one/sched.pid + ONE_CONF=/etc/one/oned.conf + ONE_DB=/var/lib/one/one.db + + ONED=/usr/bin/oned + ONE_SCHEDULER=/usr/bin/mm_sched + + LOCK_FILE=/var/lock/one/one +else + ONE_PID=$ONE_LOCATION/var/oned.pid + ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid + ONE_CONF=$ONE_LOCATION/etc/oned.conf + ONE_DB=$ONE_LOCATION/var/one.db + + ONED=$ONE_LOCATION/bin/oned + ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched + + LOCK_FILE=$ONE_LOCATION/var/.lock +fi + +setup() +{ + PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` + + if [ $? -ne 0 ]; then + echo "Can not find PORT in $ONE_CONF." + exit 1 + fi + + if [ -f $LOCK_FILE ]; then + if [ -f $ONE_PID ]; then + ONEPID=`cat $ONE_PID` + ps $ONEPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + if [ -f $ONE_SCHEDPID ]; then + ONESCHEDPID=`cat $ONE_SCHEDPID` + ps $ONESCHEDPID > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." + exit 1 + fi + fi + echo "Stale .lock detected. Erasing it." + rm $LOCK_FILE + fi +} + +start() +{ + if [ ! -x "$ONED" ]; then + echo "Can not find $ONED." + exit 1 + fi + + if [ ! -x "$ONE_SCHEDULER" ]; then + echo "Can not find $ONE_SCHEDULER." + exit 1 + fi + + if [ ! -f "$ONE_DB" ]; then + if [ -f "$HOME/.one/one_auth" ]; then + . $HOME/.one/one_auth + elif [ -z "$ONE_AUTH" ]; then + echo "You should have ONE_AUTH set the first time you start" + echo "OpenNebula as it is used to set the credentials for" + echo "the adminitrator user." + exit 1 + fi + fi + + # Start the one daemon + daemon --user=oneadmin $ONED -f 2>&1 & + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONED" + exit 1 + else + echo $LASTPID > $ONE_PID + fi + + sleep 1 + ps $LASTPID > /dev/null 2>&1 + + if [ $? -ne 0 ]; then + echo "Error executing $ONED." + exit 1 + fi + + # Start the scheduler + # The following command line arguments are supported by mm_shed: + # [-p port] to connect to oned - default: 2633 + # [-t timer] seconds between two scheduling actions - default: 30 + # [-m machines limit] max number of VMs managed in each scheduling action + # - default: 300 + # [-d dispatch limit] max number of VMs dispatched in each scheduling action + # - default: 30 + # [-h host dispatch] max number of VMs dispatched to a given host in each + # scheduling action - default: 1 + + daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& + + LASTRC=$? + LASTPID=$! + + if [ $LASTRC -ne 0 ]; then + echo "Error executing $ONE_SCHEDULER" + exit 1 + else + echo $LASTPID > $ONE_SCHEDPID + fi + + echo "oned and scheduler started" +} + +# +# Function that stops the daemon/service +# +stop() +{ + if [ ! -f $ONE_PID ]; then + echo "Couldn't find oned process pid." + exit 1 + fi + + if [ ! -f $ONE_SCHEDPID ]; then + echo "Couldn't find scheduler process pid." + exit 1 + fi + + # Kill the one daemon + + killproc oned + + # Kill the scheduler + + killproc mm_sched + + # Remove pid files + + rm -f $ONE_PID > /dev/null 2>&1 + rm -f $ONE_SCHEDPID > /dev/null 2>&1 + + echo "oned and scheduler stopped" +} + + +case "$1" in + start) + setup + start + ;; + stop) + stop + ;; + status) + status oned + status mm_sched + ;; + *) + echo "Usage: one {start|stop|status}" >&2 + exit 3 + ;; +esac From 010a26d5cb5ebc9bc3b5f5c461b8248c83d80e62 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 22 Nov 2010 16:24:30 +0100 Subject: [PATCH 2/4] bug #394: changed chkconfig levels --- share/etc/init.d/oned.centos | 2 +- share/etc/init.d/oned.opensuse | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/share/etc/init.d/oned.centos b/share/etc/init.d/oned.centos index 883d29ac83..fa66e4a13b 100755 --- a/share/etc/init.d/oned.centos +++ b/share/etc/init.d/oned.centos @@ -3,7 +3,7 @@ # oned This shell script takes care of starting and stopping # the Opennebula subsystem (oned). # -# chkconfig: - 65 35 +# chkconfig: 2345 65 35 # description: oned cloud server. # processname: oned # config: /etc/one/oned.conf diff --git a/share/etc/init.d/oned.opensuse b/share/etc/init.d/oned.opensuse index 883d29ac83..fa66e4a13b 100755 --- a/share/etc/init.d/oned.opensuse +++ b/share/etc/init.d/oned.opensuse @@ -3,7 +3,7 @@ # oned This shell script takes care of starting and stopping # the Opennebula subsystem (oned). # -# chkconfig: - 65 35 +# chkconfig: 2345 65 35 # description: oned cloud server. # processname: oned # config: /etc/one/oned.conf From 6b6390667e4d8fbd7169ba1f70d6f768e3160e72 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Mon, 22 Nov 2010 18:01:50 +0100 Subject: [PATCH 3/4] bug #394: created opensuse init script from opensuse's skeleton --- share/etc/init.d/oned.opensuse | 268 +++++++++++---------------------- 1 file changed, 85 insertions(+), 183 deletions(-) diff --git a/share/etc/init.d/oned.opensuse b/share/etc/init.d/oned.opensuse index fa66e4a13b..1553b6a540 100755 --- a/share/etc/init.d/oned.opensuse +++ b/share/etc/init.d/oned.opensuse @@ -1,195 +1,97 @@ -#!/bin/bash -# -# oned This shell script takes care of starting and stopping -# the Opennebula subsystem (oned). -# -# chkconfig: 2345 65 35 -# description: oned cloud server. -# processname: oned -# config: /etc/one/oned.conf -# pidfile: /var/run/one/oned.pid +#!/bin/sh -# Source function library. -. /etc/rc.d/init.d/functions +# -------------------------------------------------------------------------- # +# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # -# Source networking configuration. -. /etc/sysconfig/network +### BEGIN INIT INFO +# Provides: ONE +# Required-Start: $remote_fs +# Required-Stop: $remote_fs +# Default-Start: 3 5 +# Default-Stop: 0 1 2 6 +# Short-Description: OpenNebula Init Script +# Description: OpenNebula Init Script +### END INIT INFO -# Set the ONE_LOCATION -# ONE_LOCATION="/srv/cloud/one" -ONE_LOCATION="" +ONE_BIN=/usr/bin/one -prog="oned" - -if [ -z "$ONE_LOCATION" ]; then - ONE_PID=/var/run/one/oned.pid - ONE_SCHEDPID=/var/run/one/sched.pid - ONE_CONF=/etc/one/oned.conf - ONE_DB=/var/lib/one/one.db - - ONED=/usr/bin/oned - ONE_SCHEDULER=/usr/bin/mm_sched - - LOCK_FILE=/var/lock/one/one -else - ONE_PID=$ONE_LOCATION/var/oned.pid - ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid - ONE_CONF=$ONE_LOCATION/etc/oned.conf - ONE_DB=$ONE_LOCATION/var/one.db - - ONED=$ONE_LOCATION/bin/oned - ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched - - LOCK_FILE=$ONE_LOCATION/var/.lock -fi - -setup() -{ - PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` - - if [ $? -ne 0 ]; then - echo "Can not find PORT in $ONE_CONF." - exit 1 - fi - - if [ -f $LOCK_FILE ]; then - if [ -f $ONE_PID ]; then - ONEPID=`cat $ONE_PID` - ps $ONEPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - if [ -f $ONE_SCHEDPID ]; then - ONESCHEDPID=`cat $ONE_SCHEDPID` - ps $ONESCHEDPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - echo "Stale .lock detected. Erasing it." - rm $LOCK_FILE - fi -} - -start() -{ - if [ ! -x "$ONED" ]; then - echo "Can not find $ONED." - exit 1 - fi - - if [ ! -x "$ONE_SCHEDULER" ]; then - echo "Can not find $ONE_SCHEDULER." - exit 1 - fi - - if [ ! -f "$ONE_DB" ]; then - if [ -f "$HOME/.one/one_auth" ]; then - . $HOME/.one/one_auth - elif [ -z "$ONE_AUTH" ]; then - echo "You should have ONE_AUTH set the first time you start" - echo "OpenNebula as it is used to set the credentials for" - echo "the adminitrator user." - exit 1 - fi - fi - - # Start the one daemon - daemon --user=oneadmin $ONED -f 2>&1 & - - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONED" - exit 1 - else - echo $LASTPID > $ONE_PID - fi - - sleep 1 - ps $LASTPID > /dev/null 2>&1 - - if [ $? -ne 0 ]; then - echo "Error executing $ONED." - exit 1 - fi - - # Start the scheduler - # The following command line arguments are supported by mm_shed: - # [-p port] to connect to oned - default: 2633 - # [-t timer] seconds between two scheduling actions - default: 30 - # [-m machines limit] max number of VMs managed in each scheduling action - # - default: 300 - # [-d dispatch limit] max number of VMs dispatched in each scheduling action - # - default: 30 - # [-h host dispatch] max number of VMs dispatched to a given host in each - # scheduling action - default: 1 - - daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& - - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONE_SCHEDULER" - exit 1 - else - echo $LASTPID > $ONE_SCHEDPID - fi - - echo "oned and scheduler started" -} - -# -# Function that stops the daemon/service -# -stop() -{ - if [ ! -f $ONE_PID ]; then - echo "Couldn't find oned process pid." - exit 1 - fi - - if [ ! -f $ONE_SCHEDPID ]; then - echo "Couldn't find scheduler process pid." - exit 1 - fi - - # Kill the one daemon - - killproc oned - - # Kill the scheduler - - killproc mm_sched - - # Remove pid files - - rm -f $ONE_PID > /dev/null 2>&1 - rm -f $ONE_SCHEDPID > /dev/null 2>&1 - - echo "oned and scheduler stopped" -} +. /etc/rc.status +rc_reset case "$1" in - start) - setup - start + start) + echo -n "Starting ONE " + /sbin/startproc -u oneadmin $ONE_BIN start + rc_status -v ;; - stop) - stop + stop) + echo -n "Shutting down ONE " + /sbin/startproc -u oneadmin $ONE_BIN stop + rc_status -v ;; - status) - status oned - status mm_sched + try-restart|condrestart) + if test "$1" = "condrestart"; then + echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}" + fi + $0 status + if test $? = 0; then + $0 restart + else + rc_reset # Not running is not a failure. + fi + # Remember status and be quiet + rc_status ;; - *) - echo "Usage: one {start|stop|status}" >&2 - exit 3 + restart) + $0 stop + $0 start + + rc_status + ;; + force-reload) + $0 try-restart + rc_status + ;; + reload) + rc_failed 3 + rc_status -v + ;; + status) + echo -n "Checking for service ONE " + ## Check status with checkproc(8), if process is running + ## checkproc will return with exit status 0. + + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + + # NOTE: checkproc returns LSB compliant status values. + /sbin/checkproc $ONE_BIN + # NOTE: rc_status knows that we called this init script with + # "status" option and adapts its messages accordingly. + rc_status -v + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}" + exit 1 ;; esac +rc_exit From 5fb6679242b22869d395d69c99f43f2cbfa69192 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 24 Nov 2010 12:58:45 +0100 Subject: [PATCH 4/4] bug #394: changed CentOS init script to rely on /usr/bin/one instead of starting oned and scheduler separately --- share/etc/init.d/oned.centos | 220 +++++++++-------------------------- 1 file changed, 54 insertions(+), 166 deletions(-) diff --git a/share/etc/init.d/oned.centos b/share/etc/init.d/oned.centos index fa66e4a13b..d556915e89 100755 --- a/share/etc/init.d/oned.centos +++ b/share/etc/init.d/oned.centos @@ -1,195 +1,83 @@ #!/bin/bash # -# oned This shell script takes care of starting and stopping -# the Opennebula subsystem (oned). +# /etc/rc.d/init.d/oned # -# chkconfig: 2345 65 35 -# description: oned cloud server. +# Starts the OpenNebula daemon +# +# chkconfig: 345 26 74 +# description: Starts the OpenNebula daemon # processname: oned -# config: /etc/one/oned.conf -# pidfile: /var/run/one/oned.pid + +### BEGIN INIT INFO +# Provides: oned +# Required-Start: $local_fs $remote_fs +# Required-Stop: $local_fs $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: start and stop oned +# Description: start and stop oned +### END INIT INFO + +ONE_BIN=/usr/bin/one # Source function library. . /etc/rc.d/init.d/functions -# Source networking configuration. -. /etc/sysconfig/network +RETVAL=0 -# Set the ONE_LOCATION -# ONE_LOCATION="/srv/cloud/one" -ONE_LOCATION="" - -prog="oned" - -if [ -z "$ONE_LOCATION" ]; then - ONE_PID=/var/run/one/oned.pid - ONE_SCHEDPID=/var/run/one/sched.pid - ONE_CONF=/etc/one/oned.conf - ONE_DB=/var/lib/one/one.db - - ONED=/usr/bin/oned - ONE_SCHEDULER=/usr/bin/mm_sched - - LOCK_FILE=/var/lock/one/one -else - ONE_PID=$ONE_LOCATION/var/oned.pid - ONE_SCHEDPID=$ONE_LOCATION/var/sched.pid - ONE_CONF=$ONE_LOCATION/etc/oned.conf - ONE_DB=$ONE_LOCATION/var/one.db - - ONED=$ONE_LOCATION/bin/oned - ONE_SCHEDULER=$ONE_LOCATION/bin/mm_sched - - LOCK_FILE=$ONE_LOCATION/var/.lock -fi - -setup() -{ - PORT=`cat $ONE_CONF | grep ^PORT= | cut -d= -f2` - - if [ $? -ne 0 ]; then - echo "Can not find PORT in $ONE_CONF." - exit 1 - fi +check() { + # Check that we're a privileged user + [ `id -u` = 0 ] || exit 4 - if [ -f $LOCK_FILE ]; then - if [ -f $ONE_PID ]; then - ONEPID=`cat $ONE_PID` - ps $ONEPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "ONE is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - if [ -f $ONE_SCHEDPID ]; then - ONESCHEDPID=`cat $ONE_SCHEDPID` - ps $ONESCHEDPID > /dev/null 2>&1 - if [ $? -eq 0 ]; then - echo "The scheduler is still running (PID:$ONEPID). Please try 'one stop' first." - exit 1 - fi - fi - echo "Stale .lock detected. Erasing it." - rm $LOCK_FILE - fi + # Check if oned is executable + test -x $ONE_BIN || exit 5 } -start() -{ - if [ ! -x "$ONED" ]; then - echo "Can not find $ONED." - exit 1 - fi +start() { - if [ ! -x "$ONE_SCHEDULER" ]; then - echo "Can not find $ONE_SCHEDULER." - exit 1 - fi - - if [ ! -f "$ONE_DB" ]; then - if [ -f "$HOME/.one/one_auth" ]; then - . $HOME/.one/one_auth - elif [ -z "$ONE_AUTH" ]; then - echo "You should have ONE_AUTH set the first time you start" - echo "OpenNebula as it is used to set the credentials for" - echo "the adminitrator user." - exit 1 - fi - fi - - # Start the one daemon - daemon --user=oneadmin $ONED -f 2>&1 & + check - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONED" - exit 1 - else - echo $LASTPID > $ONE_PID - fi - - sleep 1 - ps $LASTPID > /dev/null 2>&1 - - if [ $? -ne 0 ]; then - echo "Error executing $ONED." - exit 1 - fi - - # Start the scheduler - # The following command line arguments are supported by mm_shed: - # [-p port] to connect to oned - default: 2633 - # [-t timer] seconds between two scheduling actions - default: 30 - # [-m machines limit] max number of VMs managed in each scheduling action - # - default: 300 - # [-d dispatch limit] max number of VMs dispatched in each scheduling action - # - default: 30 - # [-h host dispatch] max number of VMs dispatched to a given host in each - # scheduling action - default: 1 - - daemon --user=oneadmin $ONE_SCHEDULER -p $PORT -t 30 -m 300 -d 30 -h 1& - - LASTRC=$? - LASTPID=$! - - if [ $LASTRC -ne 0 ]; then - echo "Error executing $ONE_SCHEDULER" - exit 1 - else - echo $LASTPID > $ONE_SCHEDPID - fi - - echo "oned and scheduler started" + echo -n $"Starting OpenNebula daemon: " + daemon --user oneadmin $ONE_BIN start + RETVAL=$? + echo + return $RETVAL } -# -# Function that stops the daemon/service -# -stop() -{ - if [ ! -f $ONE_PID ]; then - echo "Couldn't find oned process pid." - exit 1 - fi +stop() { - if [ ! -f $ONE_SCHEDPID ]; then - echo "Couldn't find scheduler process pid." - exit 1 - fi - - # Kill the one daemon - - killproc oned - - # Kill the scheduler + check - killproc mm_sched - - # Remove pid files - - rm -f $ONE_PID > /dev/null 2>&1 - rm -f $ONE_SCHEDPID > /dev/null 2>&1 - - echo "oned and scheduler stopped" + echo -n $"Stopping OpenNebula daemon: " + su oneadmin -s /bin/sh -c "$ONE_BIN stop" + RETVAL=$? + echo + return $RETVAL } +restart() { + stop + start +} + case "$1" in - start) - setup +start) start ;; - stop) +stop) stop ;; - status) +restart) + restart + ;; +status) status oned - status mm_sched - ;; - *) - echo "Usage: one {start|stop|status}" >&2 - exit 3 + RETVAL=$? ;; +*) + echo $"Usage: $0 {start|stop|status|restart}" + RETVAL=2 esac + +exit $RETVAL