mirror of
https://github.com/FactoKit/FactoCord.git
synced 2024-11-16 10:08:21 +02:00
Added support for running FactoCord as service.
This commit is contained in:
parent
9cb5ace77f
commit
25432fa8c9
57
README.md
57
README.md
@ -1,5 +1,5 @@
|
||||
<p align="center"><img src="http://i.imgur.com/QrhAeBe.png"></p>
|
||||
<p align="center">FactoCord -- a Factorio to Discord bridge bot</p>
|
||||
<p align="center">FactoCord -- a Factorio to Discord bridge bot for Linux</p>
|
||||
<p align="center">
|
||||
<a href="https://goreportcard.com/report/github.com/FactoKit/FactoCord"><img src="https://goreportcard.com/badge/github.com/FactoKit/FactoCord" alt="Go Report Card"></a>
|
||||
</p>
|
||||
@ -7,22 +7,61 @@
|
||||
# Running
|
||||
*Make sure you have your .env file in the same directory as the executable/binary, you can use .envexample the template*
|
||||
|
||||
For Linux:
|
||||
`./FactoCord`
|
||||
There are two ways of starting FactoCord
|
||||
|
||||
1. Using the start.sh bash script (bash start.sh or ./start.sh) (make sure you chmod +x the script first)
|
||||
2. Manually running the binary (./FactoCord)
|
||||
|
||||
# Installing as a service
|
||||
|
||||
To install FactoCord as a service so that it can run on startup, you can use the provided service.sh
|
||||
|
||||
*Note you must run service.sh as root/sudo to install it as a service*
|
||||
|
||||
Example of running service.sh:
|
||||
`./service.sh factorio /home/facotrio/factocord/`
|
||||
|
||||
|
||||
# Compiling
|
||||
|
||||
This application uses several packages that'll need to be installed for you to compile
|
||||
`Requires go 1.8 or above`
|
||||
|
||||
FactoCord uses the following packages:
|
||||
|
||||
- [DiscordGo](https://github.com/bwmarrin/discordgo)
|
||||
- [godotenv](https://github.com/joho/godotenv/)
|
||||
- [tails](https://github.com/hpcloud/tail)
|
||||
|
||||
To compile just do `go build`
|
||||
|
||||
Thanks to Brett and MajesticFudgie for making the logo!
|
||||
|
||||
<hr>
|
||||
<h3>Screenshots</h3>
|
||||
<p><img src="http://i.imgur.com/QjS1D01.png"</p>
|
||||
<p><img src="http://i.imgur.com/TC8H8Hk.png"></p>
|
||||
# Error reporting
|
||||
|
||||
When FactoCord encounters an error will log to error.log within the same directory as itself.
|
||||
|
||||
If you are having an issue make sure to check the error.log to see what the problem is.
|
||||
|
||||
If you are unable to solve the issue yourself, please post an issue containing the error.log and I will review and attempt to solve what the problem is.
|
||||
|
||||
|
||||
# Windows Support?
|
||||
|
||||
Currently I haven't had any luck getting FactoCord to run correctly on Windows, [see this](https://github.com/FactoKit/FactoCord/issues/3) for information
|
||||
|
||||
If a way is found to fix this problem, then Windows support will be added.
|
||||
|
||||
|
||||
# Screenshots
|
||||
|
||||
<p><img src="http://i.imgur.com/JsLOVst.png" alt="restart command"></p>
|
||||
<p><img src="http://i.imgur.com/1cxq54P.png" alt="mod list command"></p>
|
||||
<p><img src="http://i.imgur.com/qN3NsO6.png" alt="stop command"></p>
|
||||
<p><img src="http://i.imgur.com/cxjvFG8.png" alt="save command"></p>
|
||||
<p><img src="http://i.imgur.com/dztOTrk.png" alt="in-game chat being sent to discord, notice how you can mention discord members"></p>
|
||||
<p><img src="http://i.imgur.com/Npl0vBb.png" alt="discord chat being sent to in-game"></p>
|
||||
|
||||
|
||||
# Special Thanks
|
||||
|
||||
- Brett and MajesticFudgie for making the logo!
|
||||
- [UclCommander](https://github.com/UclCommander) for finding me the tails library which made this a lot easier to build.
|
||||
|
86
linux/service.sh
Normal file
86
linux/service.sh
Normal file
@ -0,0 +1,86 @@
|
||||
# !/bin/bash
|
||||
# Installs FactoCord as a systemd service
|
||||
# Script by Allen Lydiard (FM1337)
|
||||
|
||||
|
||||
# First let's check if the user is running this script as root.
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "Sorry to install this service, you need to run this script as root"
|
||||
echo "To run it as root do sudo bash service.sh (or sudo ./service.sh)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# We then check for the amount of arguments.
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "You didn't supply any arguments!"
|
||||
echo "You must supply the following arguments"
|
||||
echo "1. The user to run the service as: e.g factorio"
|
||||
echo "2. The working directory: e.g /home/factorio/factocord"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Followed by checking if the user to run the service as exists.
|
||||
if ! id "$1" >/dev/null 2>&1; then
|
||||
echo "Sorry the user you want to run the service as does not exist!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# We also need to check if the working directory exists.
|
||||
if [ ! -d "$2" ]; then
|
||||
echo "Sorry the working directory you supplied does not exist."
|
||||
echo "Example of working directory: /home/factorio/factocord/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Moving on we need to check if the start.sh script exists in the working directory.
|
||||
if [ ! -f "$2/start.sh" ]; then
|
||||
echo "Sorry the start.sh script isn't in the working directory."
|
||||
echo "You can fetch a copy of it from here https://github.com/FactoKit/FactoCord/tree/master/linux"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# After we verified start.sh exist, we need to check if the FactoCord binary exists.
|
||||
if [ ! -f "$2/FactoCord" ]; then
|
||||
echo "Sorry the FactoCord binary is missing from your working directory"
|
||||
echo "You can get a copy of it from here https://github.com/FactoKit/FactoCord/releases"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Last but not least, we check if the factocord service is already installed and ask if it should be
|
||||
# reinstalled.
|
||||
if [ -f "/etc/systemd/system/factocord.service" ]; then
|
||||
while true; do
|
||||
echo "It looks like Factocord is already installed a service"
|
||||
read -p "Would you like to reinstall it? " yn
|
||||
case $yn in
|
||||
[Yy]* ) systemctl disable factocord.service; break;;
|
||||
[Nn]* ) exit 0;;
|
||||
* ) echo "Please enter yes or no.";;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
ServiceVar="[Unit]
|
||||
Description=FactoCord Bot
|
||||
Wants=network-online.target
|
||||
After=network.target network-online.target
|
||||
|
||||
[Service]
|
||||
User=$1
|
||||
WorkingDirectory=$2
|
||||
PIDFile=$2/factocord.pid
|
||||
ExecStart=/bin/bash start.sh
|
||||
Restart=on-failure
|
||||
StartLimitInterval=600
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target"
|
||||
|
||||
echo "$ServiceVar" > /etc/systemd/system/factocord.service
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable factocord.service
|
||||
systemctl start factocord.service
|
12
linux/start.sh
Normal file
12
linux/start.sh
Normal file
@ -0,0 +1,12 @@
|
||||
# !/bin/bash
|
||||
# FactoCord start script
|
||||
# By Allen Lydiard (FM1337)
|
||||
|
||||
screen -dmS FactoCord ./FactoCord
|
||||
echo "Hey if you're running this manually and not as a service, you can go ahead and just ctrl+c this script and the server will continue to run!"
|
||||
while screen -list | grep -q FactoCord
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
ExitCode=`cat .exit`
|
||||
exit $ExitCode
|
Loading…
Reference in New Issue
Block a user