[one-users] Re : sunstone-server and oneacctd CentOS init.d scripts

Nicolas AGIUS nicolas.agius at lps-it.fr
Fri May 25 02:21:38 PDT 2012


Hi,

Thanks for this code.
I've done some small improvement and added a script for OCCI.

You can find them here : http://dev.opennebula.org/issues/1289

Cheers,
Nicolas AGIUS

--- En date de : Dim 22.4.12, Francesco Camisa <francesco.camisa at policlinicosanmarco.it> a écrit :

De: Francesco Camisa <francesco.camisa at policlinicosanmarco.it>
Objet: [one-users] sunstone-server and oneacctd CentOS init.d scripts
À: users at lists.opennebula.org
Date: Dimanche 22 avril 2012, 15h58

I find usefull to have sunstone-server and oneacctd to start automatically.

I have created the following scripts. They are rough but do their job in my tests. Any input on improving them is much appreciated.

For oneacctd:

#!/bin/bash
#
#    /etc/rc.d/init.d/oneacctd-d
#
# Starts the oneacctd daemon
#
# chkconfig: 345 66 34
# description: Starts the oneacctd daemon
# processname: oneacctd-d

### BEGIN INIT INFO
# Provides: oneacctd-d
# Required-Start: $local_fs $remote_fs oned
# Required-Stop: $local_fs $remote_fs oned
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop oneacctd-d
# Description: start and stop oneacctd-d
### END INIT INFO

ONEACCTD_BIN=/usr/bin/oneacctd
prog=acctd.rb

# Source function library.
. /etc/rc.d/init.d/functions

lockfile=/var/lock/subsys/$prog
pidfile=/var/run/$prog.pid

RETVAL=0

check() {
    # Check that we're a privileged user
    [ `id -u` = 0 ] || exit 4

    # Check if oneacctd-d is executable
    test -x $ONEACCTD_BIN || exit 5
}

start() {
    check
    echo -n $"Starting oneacctd daemon: "
    daemon --user oneadmin $ONEACCTD_BIN start
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lockfile && echo $(ps -ef|grep su[n]stone-server | awk '{print $2}') > $pidfile
    return $RETVAL
}

stop() {

    check

    echo -n $"Stopping oneacctd daemon: "
    su oneadmin -s /bin/sh -c "$ONEACCTD_BIN stop"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile && rm -f $pidfile
    return $RETVAL
}

restart() {
    stop
    start
}


case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    restart
    ;;
status)
    status $prog
    RETVAL=$?
    ;;
*)
    echo $"Usage: $0 {start|stop|status|restart}"
    RETVAL=2
esac

exit $RETVAL

For sunstone-server:

#!/bin/bash
#
#    /etc/rc.d/init.d/sunstoned
#
# Starts the Sunstone Server daemon
#
# chkconfig: 345 66 34
# description: Starts the Sunstone Server daemon
# processname: sunstoned

### BEGIN INIT INFO
# Provides: sunstoned
# Required-Start: $local_fs $remote_fs oned
# Required-Stop: $local_fs $remote_fs oned
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop sunstoned
# Description: start and stop sunstoned
### END INIT INFO

SUNSTONE_BIN=/usr/bin/sunstone-server
prog=sunstone-server.rb

# Source function library.
. /etc/rc.d/init.d/functions

lockfile=/var/lock/subsys/$prog
pidfile=/var/run/$prog.pid

RETVAL=0

check() {
    # Check that we're a privileged user
    [ `id -u` = 0 ] || exit 4

    # Check if sunstoned is executable
    test -x $SUNSTONE_BIN || exit 5
}

start() {
    check
    echo -n $"Starting Sunstone Server daemon: "
    daemon --user oneadmin $SUNSTONE_BIN start
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch $lockfile && echo $(ps -ef|grep su[n]stone-server | awk '{print $2}') > $pidfile
    return $RETVAL
}

stop() {

    check

    echo -n $"Stopping Sunstone Server daemon: "
    su oneadmin -s /bin/sh -c "$SUNSTONE_BIN stop"
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f $lockfile && rm -f $pidfile
    return $RETVAL
}

restart() {
    stop
    start
}


case "$1" in
start)
    start
    ;;
stop)
    stop
    ;;
restart)
    restart
    ;;
status)
    status $prog
    RETVAL=$?
    ;;
*)
    echo $"Usage: $0 {start|stop|status|restart}"
    RETVAL=2
esac

exit $RETVAL


Francesco Camisa
Vice Direttore Generale
Policlinico San Marco
via Zanotto 40
30173 Mestre-VE
Italy
_______________________________________________
Users mailing list
Users at lists.opennebula.org
http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20120525/d9afd4f0/attachment-0002.htm>


More information about the Users mailing list