| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #!/bin/bash
- #
- # Copyright (c) 2019 Clementine Computing LLC.
- #
- # This file is part of PopuFare.
- #
- # PopuFare is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # PopuFare is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
- #
- org_daemon_base_dir="/home/bus/bin/server_daemon"
- org_deamon_pid_dir="/tmp"
- org_daemon_log_dir="/home/bus/log"
- daemon=( avls_server billing_server buspass_server hello_daemon version_server )
- start_org_server() {
- path=$1
- lockfile=$2
- logfile=$3
- if [ -e "$lockfile" ]; then
- if ps -p `cat $lockfile` > /dev/null 2>&1; then
- echo $path is already running - skipping start
- return 0
- else
- echo Lockfile $lockfile is junk. Deleting...
- rm -f $lockfile
- #start_buspass_server
- fi
- fi
- if [ -z "$logfile" ]
- then
- logfile="/dev/null"
- fi
- #else
- echo Starting $path
- $path > $logfile 2>&1 &
- echo $! > $lockfile
- #fi
- }
- stop_org_server() {
- path=$1
- lockfile=$2
- if [ -e $lockfile ]; then
- echo Stopping $path
- kill `cat $lockfile`
- rm -f $lockfile
- else
- echo $path is not running
- fi
- }
- echo
- case $1 in
- start )
- for d in ${daemon[@]}
- do
- start_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid $org_daemon_logfile_dir/$d.log
- done
- ;;
- stop )
- for d in ${daemon[@]}
- do
- stop_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid
- done
- ;;
- restart )
- $0 stop
- $0 start
- ;;
- * )
- for d in ${daemon[@]}
- do
- if [ "$d" == $1 ]
- then
- case "$2" in
- start )
- start_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid $org_daemon_logfile_dir/$d.log
- break
- ;;
- stop )
- stop_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid
- break
- ;;
- restart )
- stop_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid
- start_server $org_deamon_base_dir/$d.pl $org_daemon_lockfile_dir/$d.pid $org_daemon_logfile_dir/$d.log
- break
- ;;
- * )
- break
- ;;
- esac
- return 0
- fi
- done
-
- echo "Usage:"
- echo " $0 start"
- echo " $0 stop"
- echo " $0 restart"
- ;;
- esac
|