Project

General

Profile

Revision 296

Added by Red Robot almost 14 years ago

added hack for running screen as a daemon, still need to handle logging and get rid of multi-user screen

View differences:

trunk/swipe/install.sh
1
#!/bin/bash
2

  
3
# This script installs tooltron
4

  
5
if [[ $EUID -ne 0 ]]; then
6
    echo "You must be root" 2>&1
7
    exit 1
8
else
9

  
10
    cp tooltron.daemon /etc/init.d/tooltron
11
    chmod u+x /etc/init.d/tooltron
12

  
13
    update-rc.d tooltron defaults
14

  
15
    cp runtron.sh /usr/sbin/
16
    chmod +x /usr/sbin/runtron.sh
17
fi
0 18

  
trunk/swipe/runtron.sh
1
#!/bin/sh
2

  
3
#TODO: better way to know the path
4
cd /home/rc99/officers/tooltron/trunk/swipe
5

  
6
while /bin/true
7
do
8
./tooltron.py `ls /dev/ttyUSB*`
9

  
10
echo "tooltron exited, waiting for log to catch up"
11
sleep 2
12
if [ $? ] ; then
13
  cat /home/tooltron/screenlog.? > screenlog
14
  tail -n 100 screenlog > body.txt
15
  uuencode screenlog screenlog > attach.txt
16
  cat body.txt attach.txt > combined.txt
17
  mail -s "tooltron ERROR" rc-tooltron@lists.andrew.cmu.edu < combined.txt
18
  rm body.txt
19
  rm attach.txt
20
  rm combined.txt
21
  rm screenlog
22
fi
23
echo "exited, restarting"
24
   
25
done
26

  
27
echo "tooltron script exiting"
trunk/swipe/tooltron.daemon
10 10
### END INIT INFO
11 11

  
12 12
# Author: Brad Neuman <bradneuman@gmail.com>
13
# This is a decently big hack that runs a screen to run the tooltron script
13 14

  
14 15
# Do NOT "set -e"
15 16

  
......
17 18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
18 19
DESC="Tooltron Server"
19 20
NAME=tooltron
20
DAEMON=/usr/sbin/$NAME
21
#DAEMON_ARGS="--options args"
21
DAEMON=/usr/bin/screen
22
#/usr/sbin/$NAME
23
DAEMON_ARGS="-dmS tooltron /usr/sbin/runtron.sh"
22 24
PIDFILE=/var/run/$NAME.pid
23 25
SCRIPTNAME=/etc/init.d/$NAME
26
USER=tooltron
24 27

  
25 28
# Exit if the package is not installed
26 29
[ -x "$DAEMON" ] || exit 0
......
44 47
	#   0 if daemon has been started
45 48
	#   1 if daemon was already running
46 49
	#   2 if daemon could not be started
47
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
50
	start-stop-daemon --start --quiet -c $USER --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
48 51
		|| return 1
49
	start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
52
	start-stop-daemon --start --quiet -c $USER --pidfile $PIDFILE --exec $DAEMON -- \
50 53
		$DAEMON_ARGS \
51 54
		|| return 2
52 55
	# Add code here, if necessary, that waits for the process to be ready
......
64 67
	#   1 if daemon was already stopped
65 68
	#   2 if daemon could not be stopped
66 69
	#   other if a failure occurred
67
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
70
	start-stop-daemon --stop --quiet -u $USER
68 71
	RETVAL="$?"
69
	[ "$RETVAL" = 2 ] && return 2
70
	# Wait for children to finish too if this is a daemon that forks
71
	# and if the daemon is only ever run from this initscript.
72
	# If the above conditions are not satisfied then add some other code
73
	# that waits for the process to drop all resources that could be
74
	# needed by services started subsequently.  A last resort is to
75
	# sleep for some time.
76
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
77
	[ "$?" = 2 ] && return 2
78
	# Many daemons don't delete their pidfiles when they exit.
72
	# [ "$RETVAL" = 2 ] && return 2
73
	# # Wait for children to finish too if this is a daemon that forks
74
	# # and if the daemon is only ever run from this initscript.
75
	# # If the above conditions are not satisfied then add some other code
76
	# # that waits for the process to drop all resources that could be
77
	# # needed by services started subsequently.  A last resort is to
78
	# # sleep for some time.
79
	# start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
80
	# [ "$?" = 2 ] && return 2
81
	# # Many daemons don't delete their pidfiles when they exit.
79 82
	rm -f $PIDFILE
80 83
	return "$RETVAL"
81 84
}
trunk/swipe/tooltron.sh
4 4
echo "starting tooltron..."
5 5
echo ""
6 6

  
7
/usr/sbin/runtron.sh &
7
screen -S tooltron /usr/sbin/runtron.sh &
8 8

  
9
echo "started tooltron server script"
9
echo "started tooltron screen"
10 10

  

Also available in: Unified diff