mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-22 07:25:10 +00:00
90 lines
2.2 KiB
Bash
Executable File
90 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# description: Start or stop telegram-bash-bot
|
|
#
|
|
# example service script to run bashbot in background as specified user
|
|
#
|
|
# tested on: ubuntu, opensuse, debian
|
|
#
|
|
#### $$VERSION$$ v1.25-dev-9-g14fa2c7
|
|
# shellcheck disable=SC2009
|
|
# shellcheck disable=SC2181
|
|
|
|
#
|
|
### 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
|
|
|
|
# save default values
|
|
TERM="" # disable bashbot clear and color output
|
|
runcmd="echo Dry run:" # not activated until you edit lines below
|
|
|
|
#######################
|
|
# Configuration Section
|
|
|
|
# edit the next line to fit the user you want to run bashbot, e.g. nobody:
|
|
runas="nobody"
|
|
|
|
# uncomment one of the example lines to fit your system
|
|
# runcmd="su ${runas} -s /bin/bash -c " # runasuser with *su*
|
|
# runcmd="runuser ${runas} -s /bin/bash -c " # runasuser with *runuser*
|
|
|
|
# edit the values of the following lines to fit your config:
|
|
start="cd /usr/local/telegram-bot-bash; /usr/local/telegram-bot-bash/bashbot.sh" # location of your bashbot.sh script
|
|
name='' # your bot name as given to botfather, e.g. mysomething_bot
|
|
|
|
# END Configuration
|
|
#######################
|
|
|
|
[ "${name}" = "" ] && name="${runas}"
|
|
|
|
case "$1" in
|
|
'start')
|
|
# shellcheck disable=SC2250
|
|
$runcmd "$start start" # >/dev/null 2>&1 </dev/null
|
|
RETVAL=$?
|
|
;;
|
|
'stop')
|
|
# shellcheck disable=SC2250
|
|
$runcmd "$start stop"
|
|
RETVAL=$?
|
|
;;
|
|
'status')
|
|
ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot"
|
|
if [ "$?" = "0" ]; then
|
|
printf "bashbot (%s) is runningi\n" "${name}"
|
|
RETVAL=0
|
|
else
|
|
printf "bashbot (%s) is stopped\n" "${name}"
|
|
RETVAL=1
|
|
fi
|
|
;;
|
|
'restart'|'reload')
|
|
$0 stop; $0 start
|
|
RETVAL=$?
|
|
;;
|
|
'restartback')
|
|
$0 suspendback; $0 resumeback
|
|
RETVAL=$?
|
|
;;
|
|
'suspendback'|'resumeback'|'killback')
|
|
# shellcheck disable=SC2250
|
|
$runcmd "$start $1"
|
|
RETVAL=$?
|
|
# kill inotifywait from runuser
|
|
if [ "$1" != "resumeback" ]; then
|
|
# shellcheck disable=SC2046
|
|
kill -9 $(ps -u "${runas}" | grep inotifywait | sed 's/ .*//') >/dev/null 2>&1
|
|
fi
|
|
;;
|
|
*)
|
|
printf "%s\n" "Usage: $0 { start | stop | restart | reload | restartback | suspendback | resumeback | killback }"
|
|
RETVAL=1
|
|
;;
|
|
esac
|
|
exit "${RETVAL}"
|