summaryrefslogtreecommitdiff
path: root/network/museek+/rc.museekd
blob: 8c74eb95abbb760be651d04ff1f975a9e392832d (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/sh
#
# This shell script takes care of starting and stopping museekd.

MUSEEKD=/usr/bin/museekd
MUSETUP=/usr/bin/musetup
MUSCAN=/usr/bin/muscan
MUSOCKET=/tmp/museekd.root
PIDFILE=/var/run/museekd.pid
DBDIR=/var/museek
CONFIG=$DBDIR/museekd.xml
CHOWNSOCKET=YES

case "$1" in
  start)
	if [ ! -d $DBDIR ]; then 
		mkdir $DBDIR
	fi	
	if [ ! -f $CONFIG ]; then
		echo -n "Starting Museek Setup"
		echo
		if [ ! -d $DBDIR ]; then 
			mkdir $DBDIR
		fi
		$MUSETUP $CONFIG
		echo
	fi
	if [ -f $PIDFILE ]; then
		echo -n "Museek Daemon already running (or zombie pid file in /var/run/)"
		echo
		exit
	fi
	echo -n "Starting Museek Daemon"
	$MUSEEKD -c $CONFIG &>/dev/null &
	PID="$!"
	sleep 2
	if kill -0 $PID # pid check
	then 
 		if [ $CHOWNSOCKET = YES  ];
 		then 
			if [ -e $MUSOCKET ]; then chmod 666 $MUSOCKET
			# access the museekd socket from other users, may be a security risk on multiuser systems
			fi
		fi
		echo $PID > $PIDFILE
		echo
	else
		echo -n "Museekd isn't starting up properly. Check your Config file, \nor run 'museekd -c /var/museek/museekd.xml' for verbose messages."
		echo
	fi
	;;
  stop)
	echo -n "Stopping Museek Daemon"
	echo
	if [ -f $PIDFILE ]; then
		kill -15 $(cat $PIDFILE)  &>/dev/null
		rm $PIDFILE
	else
		echo -n "Museek Daemon not running"
		echo
		exit
	fi
	;;
  reconnect)
	if [ -f $PIDFILE ]; then
		echo -n "Attempting to reconnect Museekd to the Server" 
		kill -ALRM $(cat $PIDFILE)  &>/dev/null
		echo
	fi
  	;;
  restart)
	$0 stop
	sleep 3
	$0 start
	;;
  rescan)
	echo -n "Starting Muscan, rescanning shared files" 
	echo
	$MUSCAN -c $CONFIG -r -v
	echo
	$0 reload
	;;
  setup)
	echo -n "Starting Museek Setup"
	echo
	if [ ! -d $DBDIR ]; then 
		mkdir $DBDIR
	fi
	$MUSETUP $CONFIG
	echo
	;;
  reload)
	if [ -f $PIDFILE ]; then
		echo -n "Reloading Museek Daemon to update Shares" 
		kill -HUP $(cat $PIDFILE)
		echo
	else
		echo -n "Museek Daemon not running, can't reload shares"
		echo
	fi
	;;
  *)
    echo "usage: $0 {start|stop|restart|rescan|reconnect|setup|reload}"  
    echo -n
esac