-
Notifications
You must be signed in to change notification settings - Fork 2
/
pianette_initd_script.sh
72 lines (61 loc) · 1.67 KB
/
pianette_initd_script.sh
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
#!/bin/sh
### BEGIN INIT INFO
# Provides: pianette
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: pianette
# Description: pianette firmware
### END INIT INFO
is_running(){
running_processes=`ps axf | grep "python3 /home/pi/pianette/main.py" | wc -l`
if [ "$running_processes" -ge 2 ]; then
echo 1
else
echo 0
fi
}
ok(){
printf "\033[s\033[0A\033[1C\033[1;32mok\033[u\033[0m"
}
case "$1" in
start)
sudo -i PYTHONIOENCODING="utf-8" /home/pi/pianette/main.py --enable-source gpio --enable-source api --select-game 'street-fighter-alpha-3' --select-player 1
;;
stop)
if [ "$(is_running)" -eq "1" ]; then
printf "[..] Stopping Pianette ...\n"
sudo killall python3
ok
else
printf "Pianette is \033[31mstopped\033[0m\n"
fi
;;
force-stop)
printf "[..] Force-stopping Pianette ...\n"
sudo killall python3 > /dev/null 2>&1
ok
;;
status)
if [ "$(is_running)" -eq "1" ]; then
printf "Pianette is \033[32mrunning\033[0m\n"
else
printf "Pianette is \033[31mstopped\033[0m\n"
fi
;;
restart)
$0 stop
if [ "$(is_running)" -eq "1" ]; then
printf "Unable to stop, will not attempt to start\n"
exit 1
fi
$0 start
;;
*)
printf '\033[1mControls the pianette instance.\033[0m\n'
printf 'Usage: sudo service pianette {start|stop|force-stop|restart|status}\n'
exit 1
;;
esac
exit 0