-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage
60 lines (50 loc) · 1.35 KB
/
manage
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
# if not register for service, please load in your .bashrc or .zshrc:
# source ~/picsy-bot/manage
VARDIR="/var/run/picsy-bot"
PIDFILE="$VARDIR/.pid"
RUNLOG="$VARDIR/.run.log"
WORKDIR="/opt/picsy-bot"
BINDIR="$WORKDIR/bin"
export PICSY_ALTERNATE_DATA_DIRECTORY="$WORKDIR/data"
function picsy-bot-install() {
echo creating service user...
sudo useradd -c "picsy-bot service user" -d $WORKDIR -m -s /usr/sbin/nologin picsy-bot
echo creating log directory...
if [ ! -d $VARDIR ]; then
sudo mkdir -p $VARDIR
sudo chown picsy-bot $VARDIR
fi
echo installing binaries...
sudo cp -a --verbose . $BINDIR
sudo chown -R picsy-bot $BINDIR
echo registering service...
sudo cp ./picsy-bot.service /etc/systemd/system/picsy-bot.service
echo enabling service...
sudo systemctl enable picsy-bot
}
function picsy-bot-up() {
if [ -f $PIDFILE ]; then
echo "picsy-bot is already running"
return
fi
if [ -f RUNLOG ]; then
local LOGNAME=${RUNLOG%.*}
mv $RUNLOG $LOGNAME.`date +%Y%m%d%H%M%S`.log
fi
local CURRENT_PATH=`pwd`
cd $BINDIR
nohup npm run bot > $RUNLOG 2>&1 &
echo $! > $PIDFILE
cd $CURRENT_PATH
}
function picsy-bot-down() {
if [ ! -f $PIDFILE ]; then
echo "picsy-bot is not running"
return
fi
kill -SIGINT `cat $PIDFILE`
rm $PIDFILE
}
function picsy-bot-restart() {
picsy-bot-down && picsy-bot-up;
}