Merge pull request #60 from gnadelwartz/master

add example startup/init script and crontab
This commit is contained in:
Kay Marquardt 2019-03-25 07:26:44 +01:00 committed by GitHub
commit cd3a5c7845
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 1 deletions

32
bashbot.cron Normal file
View File

@ -0,0 +1,32 @@
#
# this is an exmaple crontab file for telegram-bot-bash
# copy it to /etc/cron.d/bashbot
#
# (c) https://github.com/gnadelwartz
#
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
SHELL=/bin/sh
PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:
MAILTO=root # place your mailadress here
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │ 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * USER command to execute
# * * * * * root echo "run every minute!"
# run as www every day at 0:00
0 0 * * * www /usr/local/telegram-bot-bash/bashbot.sh start # (re)start bot
0 0 * * * www /usr/local/telegram-bot-bash/bashbot.sh resumeback # (re)start background jobs
# run as www on 24 of Dec, 12:00
0 12 24 12 * www /usr/local/telegram-bot-bash/bashbot.sh broadcast "X-Mas shopping is over!" # broadcast qa message

67
bashbot.rc Executable file
View File

@ -0,0 +1,67 @@
#!/bin/sh
# description: Start or stop telegram-bash-bot
#
### 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!
runcmd="echo" # not activated until you edit lines below
# uncomment the next line to run as other user, e.g. www
# runas="www"
# 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
# uncomment and 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
case "$1" in
'start')
$runcmd "$start start" # >/dev/null 2>&1 </dev/null
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
touch $lockfile >/dev/null 2>&1
fi
;;
'stop')
$runcmd "$start kill"
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
rm -f $lockfile
fi
;;
'status')
ps -f -u $runas | grep "$name" | grep -qF "bashbot.sh startbot"
if [ "$?" = "0" ]; then
echo "$name is running"
RETVAL=0
else
echo "$name is stopped"
RETVAL=1
fi
;;
'restart'|'reload')
$stop ; $start
RETVAL=$?
;;
'suspendback'|'resumeback'|'killback')
$runcmd "$start $1"
;;
*)
echo "Usage: $0 { start | stop | restart | reload | suspendback | resumeback | killback }"
RETVAL=1
;;
esac
exit $RETVAL

View File

@ -2,7 +2,7 @@
# bashbot, the Telegram bot written in bash. # bashbot, the Telegram bot written in bash.
# Written by Drew (@topkecleon) and Daniil Gentili (@danogentili). # Written by Drew (@topkecleon) and Daniil Gentili (@danogentili).
# Also contributed: JuanPotato, BigNerd95, TiagoDanin, iicc1. # Also contributed: JuanPotato, BigNerd95, TiagoDanin, iicc1, Gnadelwartz.
# https://github.com/topkecleon/telegram-bot-bash # https://github.com/topkecleon/telegram-bot-bash
# Depends on JSON.sh (http://github.com/dominictarr/JSON.sh) (MIT/Apache), # Depends on JSON.sh (http://github.com/dominictarr/JSON.sh) (MIT/Apache),