Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matterbridge as a linux systemd service #176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions init.d/README.md
@@ -0,0 +1,24 @@
Matterbridge as a Service in Linux
==================================

To install Matterbridge as a service in Linux, place matterbridge and the config file in the `/opt/matterbridge` directory, like so:

```
sudo mkdir -p /opt/matterbridge
sudo cp matterbridge-linux64 /opt/matterbridge
sudo cp matterbridge.toml /opt/matterbridge
```

Then, install the [matterbridge deamon script](matterbridge) service into `/etc/init.d/` like so (description for Debian like installations):

```
sudo cp matterbridge /etc/init.d/
sudo chmod +x /etc/init.d/matterbridge
sudo systemctl daemon-reload
sudo systemctl enable matterbridge
sudo systemctl start matterbridge
```

The Matterbridge will now be running, and will restart after a reboot (it will wait for mattermost to start first).

Output and logging can be found in `/var/log/matterbridge.log`
99 changes: 99 additions & 0 deletions init.d/matterbridge
@@ -0,0 +1,99 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: matterbridge
# Required-Start: $mattermost
# Required-Stop: $mattermost
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: Matterbridge as daemon
# Description: init.d script to run the matterbridge as a daemon
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

DESC="Matterbridge, see https://github.com/42wim/matterbridge"
NAME=matterbridge
SCRIPTNAME=/etc/init.d/$NAME
#DAEMON=

EXECUTABLE=matterbridge-linux64
INSTALLDIR=/opt/matterbridge
LOGFILE=/var/log/matterbridge.log

do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started

pidof "$EXECUTABLE" >/dev/null
if [[ $? = 0 ]] ; then
echo "Matterbridge is still running, please stop it first." >&2
return 1
fi

cd "$INSTALLDIR"
echo "$(date) Starting matterbridge" >> "$LOGFILE"
nohup ./"$EXECUTABLE" >> "$LOGFILE" 2>&1 &
cd -
echo "$NAME Started."
return 0
}

do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred

pidof "$EXECUTABLE" >/dev/null
if [[ $? -ne 0 ]] ; then
echo "$NAME was not running." >&2
return 1
fi

echo "$(date) Stopping matterbridge" >> "$LOGFILE"
sudo killall -e "$INSTALLDIR/$EXECUTABLE" >> "$LOGFILE"
echo "$NAME Stopped."
return 0
}

do_status()
{
pidof "$EXECUTABLE" >/dev/null
case "$?" in
0)
echo "$NAME is running."
return 0
;;
*)
echo "$NAME stopped."
return 1
;;
esac
}

case "$1" in
start)
do_start
exit "$?"
;;
stop)
do_stop
exit "$?"
;;
status)
do_status
exit "$?"
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac

exit 0