Quantcast
Channel: Mattermost Discussion Forums - Latest posts
Viewing all articles
Browse latest Browse all 25778

CentOS 6.8 init script!

$
0
0

Was unsure on where to post it, but since I found no init-script for CentOS I made my own based on the debian one.

create a file at /etc/init.d/ named mattermost

nano /etc/init.d/mattermost

Copy the script at the bottom inside of it, then make the file executable with:

chmod +x /etc/init.d/mattermost

Add it to the services list:

chkconfig --add mattermost

The script(Make sure you change the paths and user/groups where needed):

#! /bin/sh
### BEGIN INIT INFO
# Provides:          mattermost
# Required-Start:    $network $syslog
# Required-Stop:     $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Mattermost Group Chat
# Description:       Mattermost: An open-source Slack
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Mattermost"
NAME=mattermost
MATTERMOST_ROOT=/home/mattermost
MATTERMOST_GROUP=mattermost
MATTERMOST_USER=mattermost
DAEMON="$MATTERMOST_ROOT/bin/platform"
PIDFILE=/var/run/$NAME.pid
PIDDIR=`dirname $PIDFILE`
SCRIPTNAME=/etc/init.d/$NAME
CONFIGFILE="$MATTERMOST_ROOT/config/config.json"

cd $MATTERMOST_ROOT/bin
. /etc/rc.d/init.d/functions

start()
{
        echo -n $"Starting $NAME: "
        if [ -f "$PIDFILE" ];
        then
                echo $"$NAME is already running..."
                RETVAL=1
        else
                nohup $DAEMON --config $CONFIGFILE >/dev/null 2>&1 &
                RETVAL=$?
                PID=$!
                if [ $RETVAL -eq 0 ];
                then
                        touch /var/lock/subsys/$NAME && success || failure
                        echo
                        echo $PID > $PIDFILE
                fi
        fi
}

stop()
{
        echo -n $"Stopping mattermost: "
        if [ -f "$PIDFILE" ];
        then
                killproc -p "$PIDFILE" -d 300 $DAEMON
                RETVAL=$?
                echo
                if [ $RETVAL -eq 0 ];
                then
                        rm -f /var/lock/subsys/$NAME
                        rm -f $PIDFILE
                fi
        else
                echo $"$NAME is not running..."
                RETVAL=1
        fi
}

restart ()
{
        if [ -f "$PIDFILE" ];
        then
                stop
                sleep 3
                start
        else
                start
        fi
}

status ()
{
        if [ -f "$PIDFILE" ];
        then
                echo "$NAME is running..."
        else
                echo "$NAME is not running..."
        fi
}

RETVAL=0

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|force-reload)
    restart
    ;;
  condrestart)
    [ -f /var/lock/subsys/$NAME ] && restart || :
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|force-reload|condrestart}"
    RETVAL=1
esac

exit $RETVAL

I am no expert in CentOS, so I am sure the above script can be improved, but at the very least it works as intended.


Viewing all articles
Browse latest Browse all 25778

Trending Articles