mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-28 12:50:44 +00:00
improved kill handling, fix job_control
This commit is contained in:
parent
8669cfb785
commit
5b2d0e1e8f
@ -102,12 +102,12 @@
|
||||
<li>no need to install or learn a new programming language, library or framework</li>
|
||||
<li>no database, not event driven, not OO …</li>
|
||||
</ul>
|
||||
<h4 id="can-i-have-the-single-bashbot.sh-file-back">Can I have the single bashbot.sh file back?</h4>
|
||||
<h3 id="can-i-have-the-single-bashbot.sh-file-back">Can I have the single bashbot.sh file back?</h3>
|
||||
<p>At the beginning bashbot was simply the file <code>bashbot.sh</code> you can copy everywhere and run the bot. Now we have ‘commands.sh’, ‘mycommands.sh’, ’modules/*.sh’ and much more.</p>
|
||||
<p>Hey no Problem, if you are finished with your cool bot run <code>dev/make-standalone.sh</code> to create a stripped down Version of your bot containing only ‘bashbot.sh’ and ‘commands.sh’! For more information see <a href="doc/7_develop.md">Create a stripped down Version of your Bot</a></p>
|
||||
<p><span class="citation">@Gnadelwartz</span></p>
|
||||
<h2 id="thats-it">That’s it!</h2>
|
||||
<p>If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!</p>
|
||||
<h4 id="version-v0.80-pre-8-gf1ebdbb"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.80-pre-8-gf1ebdbb</h4>
|
||||
<h4 id="version-v0.80-pre-11-g8669cfb"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.80-pre-11-g8669cfb</h4>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -96,7 +96,7 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from
|
||||
- no need to install or learn a new programming language, library or framework
|
||||
- no database, not event driven, not OO ...
|
||||
|
||||
#### Can I have the single bashbot.sh file back?
|
||||
### Can I have the single bashbot.sh file back?
|
||||
At the beginning bashbot was simply the file ```bashbot.sh``` you can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more.
|
||||
|
||||
Hey no Problem, if you are finished with your cool bot run ```dev/make-standalone.sh``` to create a stripped down Version of your bot containing only
|
||||
@ -109,4 +109,4 @@ Hey no Problem, if you are finished with your cool bot run ```dev/make-standalon
|
||||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.80-pre-8-gf1ebdbb
|
||||
#### $$VERSION$$ v0.80-pre-11-g8669cfb
|
||||
|
@ -139,7 +139,7 @@ health status
|
||||
- no need to install or learn a new programming language, library or framework
|
||||
- no database, not event driven, not OO ...
|
||||
|
||||
#### Can I have the single bashbot.sh file back?
|
||||
### Can I have the single bashbot.sh file back?
|
||||
At the beginning bashbot was simply the file ```bashbot.sh``` you can copy
|
||||
everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh',
|
||||
'modules/*.sh' and much more.
|
||||
@ -158,4 +158,4 @@ down Version of your Bot](doc/7_develop.md)
|
||||
If you feel that there's something missing or if you found a bug, feel free to
|
||||
submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.80-pre-8-gf1ebdbb
|
||||
#### $$VERSION$$ v0.80-pre-11-g8669cfb
|
||||
|
21
bashbot.sh
21
bashbot.sh
@ -11,7 +11,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.80-pre-9-g8dfdf2e
|
||||
#### $$VERSION$$ v0.80-pre-11-g8669cfb
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -147,12 +147,27 @@ procname(){
|
||||
printf '%s\n' "$2${ME}_$1"
|
||||
}
|
||||
|
||||
# $1 proc name
|
||||
# $1 sting to search for proramm incl. parameters
|
||||
# retruns a list of PIDs of all current bot proceeses matching $1
|
||||
proclist() {
|
||||
# shellcheck disable=SC2009
|
||||
ps -fu "${UID}" | grep -v grep| grep "$1" | sed 's/\s\+/\t/g' | cut -f 2
|
||||
ps -fu "${UID}" | grep -F "$1" | grep -v ' grep'| grep -F "${ME}" | sed 's/\s\+/\t/g' | cut -f 2
|
||||
}
|
||||
|
||||
# $1 sting to search for proramm to kill
|
||||
killallproc() {
|
||||
local procid; procid="$(proclist "$1")"
|
||||
if [ "${procid}" != "" ] ; then
|
||||
# shellcheck disable=SC2046
|
||||
kill $(proclist "$1")
|
||||
sleep 1
|
||||
procid="$(proclist "$1")"
|
||||
# shellcheck disable=SC2046
|
||||
[ "${procid}" != "" ] && kill $(proclist -9 "$1")
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# returns true if command exist
|
||||
_exists()
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
# file: make-distribution.sh
|
||||
# creates files and arcchives to dirtribute bashbot
|
||||
#
|
||||
#### $$VERSION$$ v0.80-pre-0-gdd7c66d
|
||||
#### $$VERSION$$ v0.80-pre-11-g8669cfb
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
@ -38,7 +38,7 @@ cd "${DISTDIR}" || exit 1
|
||||
|
||||
# additional stuff
|
||||
mv "bashbot.rc" "bashbot.rc.dist"
|
||||
mv "commands.sh" "commands.sh.dist"
|
||||
# mv "commands.sh" "commands.sh.dist" # will be overwritten from v0.80 on
|
||||
mv "mycommands.sh" "mycommands.sh.dist"
|
||||
|
||||
JSONSHFILE="JSON.sh/JSON.sh"
|
||||
|
@ -589,11 +589,49 @@ Returns PrefixBotname_Postfix
|
||||
|
||||
*usage:* procname postfix prefix
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
# returns botname, if already set
|
||||
procname
|
||||
# returns unique identifier for everthing related to chat
|
||||
procname "${CHAT[ID]}"
|
||||
# returns unique identifier for job, regardless of chat
|
||||
procname "" "back-jobname-"
|
||||
# returns unique identifier for a job related to a chat
|
||||
# e.g. fifo, cmd and logfile name
|
||||
procname "${CHAT[ID]}" "back-jobname-"
|
||||
```
|
||||
|
||||
##### proclist
|
||||
Returns process IDs from ps -ef containing procname
|
||||
Returns process IDs of current bot processes containing string 'pattern' in name or argument.
|
||||
|
||||
*usage:* proclist procname
|
||||
*usage:* proclist pattern
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
# list PIDs of all background processes
|
||||
proclist "back-"
|
||||
# list PIDs of all processes of a job
|
||||
proclist "back-jobname-"
|
||||
# list PIDs of all processes for a chat
|
||||
proclist "_${CHAT[ID]}"
|
||||
# list PIDs of all bot processes
|
||||
proclist
|
||||
```
|
||||
##### killallproc
|
||||
kill all current bot processes containing string 'pattern' in name or argument
|
||||
|
||||
*usage:* killallproc pattern
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
# kill all background processes
|
||||
killallproc "back-"
|
||||
# kill all processes for a chat
|
||||
killallproc "_${CHAT[ID]}"
|
||||
# kill all bot processes, including YOURSELF!
|
||||
killallproc
|
||||
```
|
||||
##### get_file
|
||||
*usage:* url="$(get_file "${CHAT[ID]}" "message")"
|
||||
|
||||
@ -643,5 +681,5 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca
|
||||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.80-pre-5-ge5f7b2d
|
||||
#### $$VERSION$$ v0.80-pre-11-g8669cfb
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.80-pre-10-gfd7ca77
|
||||
#### $$VERSION$$ v0.80-pre-11-g8669cfb
|
||||
|
||||
# source from commands.sh if you want ro use interactive or background jobs
|
||||
|
||||
@ -110,7 +110,7 @@ inproc() {
|
||||
# suspendb*
|
||||
# resumeb*
|
||||
job_control() {
|
||||
local content proc CHAT job fifo
|
||||
local content proc CHAT job fifo killall=""
|
||||
for FILE in "${TMPDIR:-.}/"*-back.cmd; do
|
||||
[ "${FILE}" = "${TMPDIR:-.}/*-back.cmd" ] && echo -e "${RED}No background processes.${NC}" && break
|
||||
content="$(< "${FILE}")"
|
||||
@ -126,13 +126,17 @@ job_control() {
|
||||
;;
|
||||
"suspendb"*)
|
||||
echo "Suspend Job: ${proc} ${fifo}"
|
||||
kill_proc "${CHAT}" "${proc}" "${job}"
|
||||
kill_proc "${CHAT}" "${job}"
|
||||
killall="y"
|
||||
;;
|
||||
"killb"*)
|
||||
echo "Kill Job: ${proc} ${fifo}"
|
||||
kill_proc "${CHAT}" "${proc}" "${job}"
|
||||
kill_proc "${CHAT}" "${job}"
|
||||
rm -f "${FILE}" # remove job
|
||||
killall="y"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
# kill all requestet. kill ALL background jobs, even not listed in data-bot-bash
|
||||
[ "${killall}" = "y" ] && killallproc "back-"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user