aboutsummaryrefslogtreecommitdiffstats
path: root/library/ajaxchat/chat/socket/server
blob: 806b5ef74a72364c0ba3e873398b171777a31974 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash

# Simple bash script to start and stop a service
# Works without access to /var/run/ or ps and pidof commands
#
# Date:: Wed, 09 Jan 2008
# Author:: Sebastian Tschan, https://blueimp.net
# License:: GNU Affero General Public License


SERVICE_TITLE=Service
SERVICE_BASENAME=${0##*/}
SERVICE_DIR=${0%/$SERVICE_BASENAME}
SERVICE_COMMAND=$SERVICE_DIR/$SERVICE_BASENAME.rb
SERVICE_CONFIG=$SERVICE_DIR/$SERVICE_BASENAME.conf
SERVICE_LOG=$SERVICE_DIR/$SERVICE_BASENAME.log
SERVICE_PIDFILE=$SERVICE_DIR/$SERVICE_BASENAME.pid


function start
{
	if [ -f $SERVICE_PIDFILE ]
	then
		echo "PID file $SERVICE_PIDFILE found - $SERVICE_TITLE already running?"
	else
		$SERVICE_COMMAND $SERVICE_CONFIG >> $SERVICE_LOG & echo "Started $SERVICE_TITLE..."
		PID=$!
		echo $PID > $SERVICE_PIDFILE
	fi
	exit 0
}

function stop
{
	if [ -f $SERVICE_PIDFILE ]
	then
		PID=`cat $SERVICE_PIDFILE`
		kill -TERM $PID
		rm -f $SERVICE_PIDFILE
		echo "Stopped $SERVICE_TITLE."
	else
		echo "PID file $SERVICE_PIDFILE not found - $SERVICE_TITLE not running?"
	fi
	exit 0
}

function main 
{ 
	for arg in $@
	do
		if [ $arg == "start" ]
		then
			start
		elif [ $arg == "stop" ]
		then
			stop
		else
			echo "Unknown argument:" $arg
			echo "Usage: $0 [start|stop]"
			exit 0
		fi
	done

	echo "Missing argument."
	echo "Usage: $0 [start|stop]"
	exit 0
} 


# Script execution: 
main $@