cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

guacd.in (2976B)


      1#!/bin/sh
      2#
      3# Licensed to the Apache Software Foundation (ASF) under one
      4# or more contributor license agreements.  See the NOTICE file
      5# distributed with this work for additional information
      6# regarding copyright ownership.  The ASF licenses this file
      7# to you under the Apache License, Version 2.0 (the
      8# "License"); you may not use this file except in compliance
      9# with the License.  You may obtain a copy of the License at
     10#
     11#   http://www.apache.org/licenses/LICENSE-2.0
     12#
     13# Unless required by applicable law or agreed to in writing,
     14# software distributed under the License is distributed on an
     15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     16# KIND, either express or implied.  See the License for the
     17# specific language governing permissions and limitations
     18# under the License.
     19#
     20
     21# guacd
     22#
     23# chkconfig:   2345 20 80
     24# description: Guacamole proxy daemon
     25
     26### BEGIN INIT INFO
     27# Provides:          guacd
     28# Required-Start:    $network $syslog 
     29# Required-Stop:     $network $syslog
     30# Default-Start:     2 3 4 5
     31# Default-Stop:      0 1 6
     32# Short-Description: Guacamole proxy daemon
     33# Description: The Guacamole proxy daemon, required to translate remote desktop protocols into the text-based Guacamole protocol used by the JavaScript application.
     34### END INIT INFO
     35
     36prog="guacd"
     37exec="@sbindir@/$prog"
     38pidfile="/var/run/$prog.pid"
     39
     40# Returns PID of currently running process, if any
     41getpid() {
     42
     43    if [ -f "$pidfile" ]
     44    then
     45
     46        read PID < "$pidfile"
     47
     48        # If pidfile contains PID and PID is valid
     49        if [ -n "$PID" ] && ps "$PID" > /dev/null 2>&1
     50        then
     51            echo "$PID"
     52            return 0
     53        fi
     54
     55    fi
     56
     57    # pidfile/pid not found, or process is dead
     58    return 1
     59
     60}
     61
     62start() {
     63    [ -x $exec ] || exit 5
     64    echo -n "Starting $prog: "
     65
     66    getpid > /dev/null || $exec -p "$pidfile" 
     67    retval=$?
     68
     69    case "$retval" in
     70        0)
     71            echo "SUCCESS"
     72            ;;
     73        *)
     74            echo "FAIL"
     75            ;;
     76    esac
     77
     78    return $retval
     79}
     80
     81stop() {
     82    echo -n "Stopping $prog: "
     83    
     84    PID=`getpid`
     85    retval=$?
     86
     87    case "$retval" in
     88        0)
     89            if kill $PID > /dev/null 2>&1
     90            then
     91                echo "SUCCESS"
     92                return 0
     93            fi
     94
     95            echo "FAIL"
     96            return 1
     97            ;;
     98        *)
     99            echo "SUCCESS (not running)"
    100            return 0
    101            ;;
    102    esac
    103
    104}
    105
    106restart() {
    107    stop && start
    108}
    109
    110force_reload() {
    111    restart
    112}
    113
    114status() {
    115    
    116    PID=`getpid`
    117    retval=$?
    118
    119    case "$retval" in
    120        0)
    121            echo "$prog is running with PID=$PID."
    122            ;;
    123        *)
    124            echo "$prog is not running."
    125            ;;
    126    esac
    127
    128    return $retval
    129
    130}
    131
    132case "$1" in
    133    start|stop|status|restart|force-reload)
    134        $1
    135        ;;
    136    try-restart)
    137        status && restart
    138        ;;
    139    *)
    140        echo "Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
    141        exit 2
    142esac
    143exit $?
    144