Changeset 982


Ignore:
Timestamp:
Feb 19, 2008, 12:16:09 PM (10 years ago)
Author:
jrollins
Message:

cleanup up more for transition to update-service

Location:
trunk/cereal/fs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/cereal/fs/etc/cereal/cereal-admin.conf

    r978 r982  
    11# /etc/cereal/cereal-admin.conf
    22
    3 # If set to 'yes', create sessions with world accessbile supervise
    4 # directory.  This lets all users test the running state of registered
    5 # sessions.  However, this may be a security vulnerability on systems
    6 # that do not respect FIFO file permissions.
     3# If set to 'yes', session supervise directories will be made world
     4# accessbile when the session is started. This lets all users test the
     5# running state of registered sessions.  However, this may be a
     6# security vulnerability on systems that do not respect FIFO file
     7# permissions.
    78SUPERVISE_WORLD_ACCESSIBLE=yes
  • trunk/cereal/fs/usr/sbin/cereal-admin

    r978 r982  
    6060
    6161    is_session "$SESSION" && failure "A session named '$SESSION' already exists."
    62     check_is_tty "$TTY"
    63     check_is_session_tty "$TTY"
     62    check_tty "$TTY"
     63    check_session_tty "$TTY"
    6464    check_user "$SUSER"
    6565    check_group "$SGROUP"
     
    9696    ln -s "$SHAREDIR/logrun" "$SESSIONDIR/$SESSION/log/run"
    9797
    98     # make supervise directory world accessible if requested
    99     if [ "$SUPERVISE_WORLD_ACCESSIBLE" = 'yes' ] ; then
    100         mkdir -p -m 0755 "$SESSIONDIR/$SESSION/supervise"
    101     fi
    102 
    10398    echo "Created session '$SESSION':"
    10499    display_session "$SESSION"
     
    107102# start_check
    108103start_check() {
    109     check_tty_rw "$USER" "$GROUP" "$TTY"
     104    is_tty_rw "$USER" "$GROUP" "$TTY"
    110105}
    111106export -f start_check
     
    114109start_session() {
    115110    local SESSION="$1"
    116     update-service --add "$SESSIONDIR/$SESSION" "cereal.$SESSION"
    117     log_write "$SESSION" "session '$SESSION' started."
     111
     112    if chpst -e "$SESSIONDIR/$SESSION/env/" bash -c start_check ; then
     113        log_write "$SESSION" "starting session '$SESSION'..."
     114        update-service --add "$SESSIONDIR/$SESSION" "cereal.$SESSION"
     115       
     116        # make supervise directory world accessible if requested
     117        if [ "$SUPERVISE_WORLD_ACCESSIBLE" = 'yes' ] ; then
     118            chmod 0755 "$SESSIONDIR/$SESSION/supervise"
     119            chmod 0755 "$SESSIONDIR/$SESSION/log/supervise"
     120        fi
     121    else
     122        return 1
     123    fi
    118124}
    119125export -f start_session
     
    134140            error "Session '$SESSION' not found." 1
    135141        elif update-service --check "cereal.$SESSION" ; then
    136             error "Session '$SESSION' is already registered." 1
    137         elif ! chpst -e "$SESSIONDIR/$SESSION/env/" bash -c start_check ; then
    138             error "Session '$SESSION' not properly configured." 2
     142            echo "Session '$SESSION' is already running."
     143        elif start_session "$SESSION" ; then
     144            echo "Session '$SESSION' started."
    139145        else
     146            error "Session '$SESSION' could not be started." 2
     147        fi
     148    done
     149}
     150
     151# restart_session SESSION
     152restart_session(){
     153    local SESSION="$1"
     154    if sv restart "cereal.$SESSION" ; then
     155        log_write "$SESSION" "session '$SESSION' restarted."
     156    fi
     157}
     158export -f restart_session
     159
     160# restart session
     161restart() {
     162    if [ -z "$1" ] ; then
     163        failure "Not enough input arguments.
     164Type '$CMD help' for more info."
     165    elif [ "$1" = '--all' -o "$1" = '-a' ] ; then
     166        SESSIONS=$(list -n) || failure "There are no sessions." 1
     167    elif [ "$1" = '--running' -o "$1" = '-r' ] ; then
     168        SESSIONS=$(list | grep '^+' | cut -d ' ' -f 2)
     169        [ "$SESSIONS" ] || failure "There are no running sessions." 0
     170    else
     171        SESSIONS="$@"
     172    fi
     173   
     174    for SESSION in $SESSIONS ; do
     175        if ! is_session "$SESSION" ; then
     176            error "Session '$SESSION' not found." 1
     177        elif ! update-service --check "cereal.$SESSION" ; then
    140178            if start_session "$SESSION" ; then
    141                 echo "Started session '$SESSION'."
     179                echo "Session '$SESSION' started."
    142180            else
    143181                error "Session '$SESSION' could not be started." 2
    144182            fi
     183        elif restart_session "$SESSION" ; then
     184            echo "Session '$SESSION' restarted."
     185        else
     186            error "Session could not be restart." 2
    145187        fi
    146188    done
     
    150192stop_session() {
    151193    local SESSION="$1"
    152     log_write "$SESSION" "stopping session '$SESSION'..."
    153     update-service --remove "$SESSIONDIR/$SESSION" "cereal.$SESSION"
     194    if sv exit "cereal.$SESSION" ; then
     195        log_write "$SESSION" "stopping session '$SESSION'..."
     196        update-service --remove "$SESSIONDIR/$SESSION" "cereal.$SESSION"
     197    else
     198        return 1
     199    fi
    154200}
    155201export -f stop_session
     
    171217        elif ! update-service --check "cereal.$SESSION" ; then
    172218            error "Session '$SESSION' not registered." 1
    173         elif ! is_controllable "$SESSION" ; then
    174             error "You do not have permission to stop session '$SESSION'." 2
     219        elif stop_session "$SESSION" ; then
     220            echo "Session '$SESSION' stopped."
    175221        else
    176             if stop_session "$SESSION" ; then
    177                 echo "Stopped session '$SESSION'."
    178             else
    179                 error "Session '$SESSION' could not be stopped." 2
    180             fi
     222            error "Session '$SESSION' could not be stopped." 2
    181223        fi
    182224    done
    183225}
    184226
    185 # restart_session SESSION
    186 restart_session() {
     227# destroy_session SESSION
     228destroy_session() {
    187229    local SESSION="$1"
    188     log_write "$SESSION" "restarting session '$SESSION'..."
    189     sv restart "cereal.$SESSION"
    190 }
    191 export -f restart_session
    192 
    193 # restart session
    194 restart() {
     230    rm -rf "$SESSIONDIR/$SESSION"
     231}
     232export -f destroy_session
     233
     234# destroy session
     235destroy() {
    195236    if [ -z "$1" ] ; then
    196237        failure "Not enough input arguments.
     
    198239    elif [ "$1" = '--all' -o "$1" = '-a' ] ; then
    199240        SESSIONS=$(list -n) || failure "There are no sessions." 1
    200     elif [ "$1" = '--running' -o "$1" = '-r' ] ; then
    201         SESSIONS=$(list | grep '^+' | cut -d ' ' -f 2)
    202         [ "$SESSIONS" ] || failure "There are no running sessions." 0
    203241    else
    204242        SESSIONS="$@"
    205243    fi
    206    
     244
    207245    for SESSION in $SESSIONS ; do
    208246        if ! is_session "$SESSION" ; then
    209247            error "Session '$SESSION' not found." 1
    210         elif ! update-service --check "cereal.$SESSION" ; then
    211             start "$SESSION"
    212         elif ! is_controllable "$SESSION" ; then
    213             error "You do not have permission to restart session '$SESSION'." 2
    214         else
    215             if restart_session "$SESSION" ; then
    216                 echo "Restarted session '$SESSION'."
    217             else
    218                 error "Session '$SESSION' could not be restarted." 2
    219             fi
    220         fi
    221     done
    222 }
    223 
    224 # destroy_session SESSION
    225 destroy_session() {
    226     rm -rf "$SESSIONDIR/$1"
    227 }
    228 export -f destroy_session
    229 
    230 # destroy session
    231 destroy() {
    232     if [ -z "$1" ] ; then
    233         failure "Not enough input arguments.
    234 Type '$CMD help' for more info."
    235     elif [ "$1" = '--all' -o "$1" = '-a' ] ; then
    236         SESSIONS=$(list -n) || failure "There are no sessions." 1
    237     else
    238         SESSIONS="$@"
    239     fi
    240 
    241     for SESSION in $SESSIONS ; do
    242         if ! is_session "$SESSION" ; then
    243             error "Session '$SESSION' not found." 1
    244         elif [ ! -w "$SESSIONDIR/$SESSION" ] ; then
    245             error "You do not have permission to destroy session '$SESSION'." 2
     248        elif [ ! -w "$SESSIONDIR/$SESSION" ] ; then
     249            error "You do not have permission to destroy session '$SESSION'." 2
    246250        elif update-service --check "cereal.$SESSION" ; then
    247251            echo "Session '$SESSION' is currently registered."
     
    250254                if stop_session "$SESSION" ; then
    251255                    if destroy_session "$SESSION" ; then
    252                         echo "Stopped and destroyed session '$SESSION'."
     256                        echo "Session '$SESSION' stopped and destroyed."
    253257                    else
    254258                        error "Session '$SESSION' could not be destroyed." 2
     
    264268            if [ "${OK/y/Y}" = 'Y' ] ; then
    265269                if destroy_session "$SESSION" ; then
    266                     echo "Destroyed session '$SESSION'."
     270                    echo "Session '$SESSION' destroyed."
    267271                else
    268272                    error "Session '$SESSION' could not be destroyed." 2
  • trunk/cereal/fs/usr/share/cereal/common

    r978 r982  
    3030# check if TTY is valid tty
    3131# check_is_tty TTY
    32 check_is_tty() {
     32check_tty() {
    3333    [ -c "$1" ] || failure "'$1' is not a valid tty."
    3434}
    35 export -f check_is_tty
     35export -f check_tty
    3636
    3737# check is tty is already being used in another session
    3838# check_is_session_tty TTY
    39 check_is_session_tty() {
    40     TTY="$1"
     39check_session_tty() {
    4140    local SESSION
     41    local TTY="$1"
     42
    4243    for SESSION in $(ls "$SESSIONDIR") ; do
    4344        if grep -q "^$TTY$" "$SESSIONDIR/$SESSION/env/TTY" ; then
     
    4647    done
    4748}       
    48 export -f check_is_session_tty
     49export -f check_session_tty
    4950
    5051# check if USER is valid
     
    6364
    6465# check if the user can read/write to a TTY
     66is_tty_rw() {
     67    chpst -u "$1:$2" bash -c "test -r $3 && test -w $3"
     68}
     69export -f is_tty_rw
     70
    6571# check_tty_rw USER GROUP TTY
    6672check_tty_rw() {
    67     chpst -u "$1:$2" bash -c "test -r $3 && test -w $3" || failure "User '$1' does not have read/write access to tty '$3', tty is not g+rw, or you do not have permission to change user."
     73    is_tty_rw "$@" || failure "User '$1' does not have read/write access to tty '$3', tty is not g+rw, or you do not have permission to change user."
    6874}
    6975export -f check_tty_rw
     
    133139#log_write SESSION STATEMENT
    134140log_write() {
    135     echo -e "\ncereal: $2" >> "$SERVICE.$1/socket"
     141    echo -e "\ncereal: $2" >> "$SESSIONDIR/$1/socket"
    136142}
    137143export -f log_write
  • trunk/cereal/fs/usr/share/cereal/mainrun

    r551 r982  
    1818
    1919mainrun() {
    20     check_is_tty "$TTY"
     20    check_tty "$TTY"
    2121    check_user "$USER"
    2222    check_group "$GROUP"
Note: See TracChangeset for help on using the changeset viewer.