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

Francesco Camisa francesco.camisa at policlinicosanmarco.it
Sun Apr 22 06:58:54 PDT 2012


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


More information about the Users mailing list