2019-03-24 18:31:54 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# description: Start or stop telegram-bash-bot
|
|
|
|
#
|
2019-04-01 17:13:13 +00:00
|
|
|
#### $$VERSION$$ v0.6-dev-3-g614eae8
|
2019-04-01 16:24:05 +00:00
|
|
|
# shellcheck disable=SC2009
|
|
|
|
# shellcheck disable=SC2181
|
|
|
|
|
2019-03-28 15:51:33 +00:00
|
|
|
#
|
2019-03-24 18:31:54 +00:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: bashbot
|
|
|
|
# Required-Start: $network $syslog
|
|
|
|
# Required-Stop: $network
|
|
|
|
# Default-Start: 2 3 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Description: Start or stop telegram-bot-bash server
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
runas="root" # not recommended!
|
2019-04-01 10:52:25 +00:00
|
|
|
runcmd="echo Dry run:" # not actived until you edit lines below
|
2019-03-24 18:31:54 +00:00
|
|
|
|
|
|
|
# uncomment the next line to run as other user, e.g. www
|
2019-03-28 19:59:52 +00:00
|
|
|
# runas="nobody"
|
2019-03-24 18:31:54 +00:00
|
|
|
|
|
|
|
# uncomment one of the following lines
|
|
|
|
# runcmd="su $runas -s /bin/bash -c " # runasuser with su
|
|
|
|
# runcmd="runuser $runas -s /bin/bash -c " # runasuser with runuser
|
|
|
|
|
2019-03-25 10:11:22 +00:00
|
|
|
# adjust the the values of the following lines
|
|
|
|
start="/usr/local/telegram-bot-bash/bashbot.sh"
|
|
|
|
lockfile=/usr/local/telegram-bot-bash/lockfile
|
|
|
|
name='new-session' # telegram name of your bot
|
2019-03-24 18:31:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
'start')
|
|
|
|
$runcmd "$start start" # >/dev/null 2>&1 </dev/null
|
|
|
|
RETVAL=$?
|
|
|
|
if [ "$RETVAL" = "0" ]; then
|
2019-03-29 16:52:00 +00:00
|
|
|
touch "$lockfile" >/dev/null 2>&1
|
2019-03-24 18:31:54 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
'stop')
|
|
|
|
$runcmd "$start kill"
|
|
|
|
RETVAL=$?
|
|
|
|
if [ "$RETVAL" = "0" ]; then
|
2019-03-29 16:52:00 +00:00
|
|
|
rm -f "$lockfile"
|
2019-03-24 18:31:54 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
'status')
|
2019-03-29 16:52:00 +00:00
|
|
|
ps -f -u "$runas" | grep "$name" | grep -qF "bashbot.sh startbot"
|
2019-03-24 18:31:54 +00:00
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
echo "$name is running"
|
|
|
|
RETVAL=0
|
|
|
|
else
|
|
|
|
echo "$name is stopped"
|
|
|
|
RETVAL=1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
'restart'|'reload')
|
2019-03-25 10:11:22 +00:00
|
|
|
$0 stop; $0 start
|
2019-03-24 18:31:54 +00:00
|
|
|
RETVAL=$?
|
|
|
|
;;
|
|
|
|
'suspendback'|'resumeback'|'killback')
|
|
|
|
$runcmd "$start $1"
|
2019-03-25 10:11:22 +00:00
|
|
|
RETVAL=$?
|
2019-03-24 18:31:54 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 { start | stop | restart | reload | suspendback | resumeback | killback }"
|
|
|
|
RETVAL=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
exit $RETVAL
|
|
|
|
|