#!/bin/bash ### BEGIN INIT INFO # Provides: ARK manager deamon # Required-Start: networking # Required-Stop: networking # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: ARK manager deamon # Description: ARK manager daemon used to start the server and keep it updated # ### END INIT INFO # Using the lsb functions to perform the operations. . /lib/lsb/init-functions # Global variables source /etc/arkmanager/arkmanager.cfg NAME="ShooterGameServer" LOGFILE="${logdir}/${NAME}.log" DAEMON="/usr/bin/arkmanager" SVCNAME="${0##*/}" INSTANCE="${SVCNAME#*.}" if [ "$INSTANCE" == "$SVCNAME" ]; then INSTANCE="$2" fi set -e # If the daemon is not there, then exit. test -x $DAEMON || exit 5 function start_instance(){ local INSTANCE="$1" PID="$(<"/var/run/arkmanager.${INSTANCE}.pid")" if [ -n "$PID" ] && kill -0 "$PID" >/dev/null 2>&1; then if grep " ${PID} .* ${DAEMON}" <(ps -ef) >/dev/null 2>&1; then echo "$NAME @${INSTANCE} is already running" return 0 fi fi log_daemon_msg "Starting" "$NAME @${INSTANCE}" ulimit -n 100000 "${DAEMON}" run "@${INSTANCE}" & PID="$!" sleep 5 if kill -0 "$PID" >/dev/null 2>&1; then echo "$PID" >"/var/run/arkmanager.${INSTANCE}.pid" log_end_msg 0 return 0 else log_end_msg 1 return 1 fi } function start_all_instances(){ local nosuccess=0 local anyfailure=0 for instance in $("${DAEMON}" list-instances --brief); do if start_instance "$instance"; then nosuccess=0 else anyfailure=1 fi done return $nosuccess } function stop_instance(){ local INSTANCE="$1" log_daemon_msg "Stopping $NAME @${INSTANCE}: " "${DAEMON}" stop "@${INSTANCE}" & rm -f "/var/run/arkmanager.${INSTANCE}.pid" log_end_msg 0 return 0 } case "$1" in start) if [ -n "$INSTANCE" ]; then start_instance "$INSTANCE" exit $? else if start_all_instances; then exit 0 else exit 1 fi fi ;; stop) if [ -n "$INSTANCE" ]; then stop_instance "$INSTANCE" exit $? else for instance in $("${DAEMON}" list-instances --brief); do stop_instance "$instance" done exit $? fi ;; restart) "$0" stop "$0" start ;; status) "$DAEMON" status "@${INSTANCE:-all}" ;; *) # For invalid arguments, print the usage message. echo "Usage: $0 {start|stop|restart|status}" exit 2 ;; esac exit 0