Skip to content

Instantly share code, notes, and snippets.

@hyunto
Last active February 12, 2018 05:44
Show Gist options
  • Save hyunto/2b4390fcc21cfacd8f32b87b8bbd9caf to your computer and use it in GitHub Desktop.
Save hyunto/2b4390fcc21cfacd8f32b87b8bbd9caf to your computer and use it in GitHub Desktop.
This is the systemd script that start or stop a minio server.
#! /bin/sh
### BEGIN INIT INFO
# Provides: minio
# Required-Start: $network $named $remote_fs $syslog
# Required-Stop: $network $named $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: minio server
# Description: Minio is an open source object storage server
# with Amazon S3 compatible API.
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="minio server"
PIDPATH="/var/run/minio"
PIDFILE="$PIDPATH/minio.pid"
ADDRESS=":62222"
DATA_PATH="/data"
CONFIG_PATH="/etc/minio"
NAME="server"
DAEMON=/usr/local/bin/minio
DAEMON_OPTS="--config-dir $CONFIG_PATH --address $ADDRESS $DATA_PATH"
LOGFILE="/var/log/minio.log"
MINIO_ACCESS_KEY="minio"
MINIO_SECRET_KEY="miniostorage"
MINIO_REGION="us-east-1"
MINIO_BROWSER="on"
. /lib/lsb/init-functions
start_minio() {
export MINIO_ACCESS_KEY="$MINIO_ACCESS_KEY"
export MINIO_SECRET_KEY="$MINIO_SECRET_KEY"
export MINIO_REGION="$MINIO_REGION"
export MINIO_BROWSER="$MINIO_BROWSER"
if [ ! -d $DATA_PATH ]; then
echo "$(tput setaf 1)[Error] Directory for storing data does not exist : $DATA_PATH $(tput sgr 0)"
exit 1
fi
if [ ! -d $CONFIG_PATH ]; then
mkdir $CONFIG_PATH
fi
if [ ! -d $PIDPATH ]; then
mkdir $PIDPATH
fi
start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE \
--no-close \
--startas $DAEMON -- $NAME $DAEMON_OPTS >> $LOGFILE 2>&1
echo "minio started : `date`" >> $LOGFILE 2>&1
}
stop_minio() {
start-stop-daemon --stop --quiet --signal HUP --pidfile $PIDFILE
rm -rf $PIDFILE
echo "minio stoped : `date`" >> $LOGFILE 2>&1
}
status_minio() {
status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}"
}
case "$1" in
start)
log_begin_msg "Starting $DESC"
start_minio
log_end_msg $?
;;
stop)
log_begin_msg "Stopping $DESC"
stop_minio
log_end_msg $?
;;
status)
status_minio
;;
restart|force-reload)
log_begin_msg "Restarting $DESC"
stop_minio
start_minio
log_end_msg $?
;;
*)
echo "Usage: $0 {start|stop|status|restart}" >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment