mystic/mrc-server/mrc_server-start.sh

45 lines
1.9 KiB
Bash
Raw Normal View History

2023-01-07 18:31:25 +01:00
#!/bin/bash
#==================================================================================================
# This shell script will launch the 'Multi Relay Chat' python script. It is intended to be called #
# via a forked systemd .service file. The script will check that mrc_server.py is not already #
2023-01-07 18:31:25 +01:00
# running then will launch it. To avoid problems, it should be launched using the same user that #
# owns the mystic install directory. If executing manually, use 'sudo -u username' or ensure you #
# are logged into the terminal as the user that owns the mystic directory. In a systemd .service #
# file, you should use the 'User=' option in the [Service] section. The script will exit with an #
# appropriate error code to indicate whether is was successful or not. This script is indended to #
# work only with Debian, Ubuntu, Raspbian and other debian based distributions. #
#==================================================================================================
# MRC Variables:
MRC_PATH=@MYSTIC_DIR@
MRC_SERVER=0.0.0.0
2023-01-07 18:31:25 +01:00
MRC_PORT=5000
MRC_PID=$(ps auxwww | grep "/usr/bin/python2 ./mrc_server.py" | grep -v grep | awk '{print $2}')
2023-01-07 18:31:25 +01:00
echo "Attempting to start the Multi Relay Chat Server (MRC) python script.."
2023-01-07 18:31:25 +01:00
# Make sure the mrc_server.py script isn't already running:
2023-01-07 18:31:25 +01:00
if [ ! -z "$MRC_PID" ]
then
echo "Error: mrc_server.py script is already running at PID $MRC_PID. Stop it first."
2023-01-07 18:31:25 +01:00
exit 1
fi
# Starting the MRC python script
cd $MRC_PATH >/dev/null
2024-04-20 14:04:22 +02:00
/usr/bin/python2 ./mrc_server.py $MRC_SERVER:$MRC_PORT > data/mrc/mrcserver.log 2>&1 &
2023-01-07 18:31:25 +01:00
cd - >/dev/null
# Wait 3 seconds and check for a PID
sleep 3
MRC_PID=$(ps auxwww | grep "/usr/bin/python2 ./mrc_server.py" | grep -v grep | awk '{print $2}')
2023-01-07 18:31:25 +01:00
# Making sure it started successfully
if [ ! -z "$MRC_PID" ]
then
echo "Success! The mrc_server.py script is now running with PID $MRC_PID"
2023-01-07 18:31:25 +01:00
exit 0
else
echo "Error: mrc_server.py failed to start. Exiting."
2023-01-07 18:31:25 +01:00
exit 1
fi