#!/bin/bash # # Init file for the ARC gridftp server # # chkconfig: 2345 75 25 # description: ARC gridftpd # # config: /etc/sysconfig/nordugrid # config: /etc/sysconfig/gridftpd # config: /cvmfs/dirac.egi.eu/dirac/v8.0.45/Linux-aarch64/etc/arc.conf # config: /etc/arc.conf ### BEGIN INIT INFO # Provides: arc-gridftpd # 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: ARC gridftpd # Description: ARC gridftp server ### END INIT INFO # source function library if [ -f /etc/init.d/functions ]; then . /etc/init.d/functions log_success_msg() { echo -n "$@" success "$@" echo } log_warning_msg() { echo -n "$@" warning "$@" echo } log_failure_msg() { echo -n "$@" failure "$@" echo } elif [ -f /lib/lsb/init-functions ]; then . /lib/lsb/init-functions else echo "Error: Cannot source neither init.d nor lsb functions" exit 1 fi prog=gridftpd # sysconfig files if [ -r /etc/sysconfig/nordugrid ]; then . /etc/sysconfig/nordugrid elif [ -r /etc/default/nordugrid ]; then . /etc/default/nordugrid fi if [ -r /etc/sysconfig/arc-${prog} ]; then . /etc/sysconfig/arc-${prog} elif [ -r /etc/default/arc-${prog} ]; then . /etc/default/arc-${prog} fi # ARC_LOCATION ARC_LOCATION=${ARC_LOCATION:-/cvmfs/dirac.egi.eu/dirac/v8.0.45/Linux-aarch64} if [ ! -d "$ARC_LOCATION" ]; then log_failure_msg "ARC_LOCATION ($ARC_LOCATION) not found" exit 1 fi # PID and lock file PID_FILE=`${ARC_LOCATION}/share/arc/arc-gridftpd-start --getpidfile` if [ $? -ne 0 ]; then # When --getpidfile fails it returns the error on stdout log_failure_msg "$PID_FILE" exit 1 fi if [ `id -u` = 0 ] ; then # Debian does not have /run/lock/subsys if [ -d /run/lock/subsys ]; then LOCKFILE=/run/lock/subsys/$prog else LOCKFILE=/run/lock/$prog fi else LOCKFILE=$HOME/$prog.lock fi start() { echo -n "Starting $prog: " # Check if we are already running if [ -f "$PID_FILE" ]; then read pid < "$PID_FILE" if [ "x$pid" != "x" ]; then ps -p "$pid" -o comm 2>/dev/null | grep "^$prog$" 1>/dev/null 2>/dev/null if [ $? -eq 0 ] ; then log_success_msg "already running (pid $pid)" return 0 fi fi rm -f "$PID_FILE" "$LOCKFILE" fi ${ARC_LOCATION}/share/arc/arc-gridftpd-start RETVAL=$? if [ $RETVAL -eq 0 ]; then touch $LOCKFILE log_success_msg else log_failure_msg fi return $RETVAL } stop() { echo -n "Stopping $prog: " if [ -f "$PID_FILE" ]; then read pid < "$PID_FILE" if [ ! -z "$pid" ] ; then kill "$pid" RETVAL=$? if [ $RETVAL -eq 0 ]; then log_success_msg else log_failure_msg fi sleep 1 kill -9 "$pid" 1>/dev/null 2>&1 rm -f "$PID_FILE" "$LOCKFILE" else RETVAL=1 log_failure_msg "$prog shutdown - pidfile is empty" fi else RETVAL=0 log_success_msg "$prog shutdown - already stopped" fi return $RETVAL } status() { if [ -f "$PID_FILE" ]; then read pid < "$PID_FILE" if [ "$pid" != "" ]; then if ps -p "$pid" > /dev/null; then echo "$1 (pid $pid) is running..." return 0 fi echo "$1 stopped but pid file exists" return 1 fi fi if [ -f $LOCKFILE ]; then echo "$1 stopped but lockfile exists" return 2 fi echo "$1 is stopped" return 3 } restart() { stop start } case "$1" in start) start ;; stop) stop ;; status) status $prog ;; restart | force-reload) restart ;; reload) ;; condrestart | try-restart) [ -f $LOCKFILE ] && restart || : ;; *) echo "Usage: $0 {start|stop|status|restart|force-reload|reload|condrestart|try-restart}" exit 1 ;; esac exit $?