0

I want to set crate boot with the redhat,so I write a systemd service file for crate:

crate version: 1.1.2

following is crate.service:

[Unit]
Description=crate daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/su - hadmin -c '/home/hadmin/aisinofp/crate/bin/crate.sh start'
ExecStop=/usr/bin/su - hadmin -c '/home/hadmin/aisinofp/crate/bin/crate.sh stop'
Restart=always
[Install]
WantedBy=multi-user.target

the crate.sh is:

#!/bin/bash

source /home/hadmin/myproject/conf/env.sh
if [ "$1" = "start" ]
then
$CRATE_HOME/bin/crate -d
elif [ "$1" = "stop" ]
then
pid=$(ps -ef|grep io.crate.bootstrap.CrateDB |grep jar |awk '{print $2}')
echo "KILLING cratedb PROCESS "$pid
kill -9 $pid
fi

the env.sh is:

#!/bin/bash

# set ulimit
#ulimit -n 655360

export JAVA_HOME=/usr/java/default
export JRE_HOME=/usr/java/default
PATH=$JAVA_HOME/bin:$PATH

# environment for all Projects
export TD_BASE=/home/hadmin
export TD_HOME=$TD_BASE/myproject
export TD_DATA=$TD_BASE/data

# zookeeper environment
export ZOO_HOME=$TD_BASE/zookeeper
export ZOO_LOG_DIR=$ZOO_HOME/logs
PATH=$ZOO_HOME/bin:$PATH

# cratedb environment
export CRATE_HEAP_SIZE=4g
export CRATE_HOME=/home/hadmin/crate
PATH=$CRATE_HOME/bin:$PATH

# activemq environment
export activemq_data=/home/hadmin/data/activemq
export activemq_base=/home/hadmin/activemq
export activemq_conf=$activemq_base/conf
PATH=$activemq_base/bin:$PATH

export PATH

when I finish writing these files, I start using "systemctl start crate.service",but I got messages like this in /var/logs/message: enter image description here

I can see that the crate daemon has being restarting all the time, I don't know why it would be killed after started

thanks

Cœur
  • 37,241
  • 25
  • 195
  • 267
MayI
  • 53
  • 1
  • 9
  • Two config to change:1. modify Type=forking to Type=simple; 2. in crate.sh modify $CRATE_HOME/bin/crate, delete option " -d" , because if "-d" the systemctl will think the daemon is not started, and will restart all the time, "-d" means start in background – MayI Jun 08 '17 at 13:34
  • thank u, your answer fix it – MayI Apr 01 '19 at 15:14

1 Answers1

1

Crate already provides an official RPM package for Red Hat Linux that uses systemd. There is no need to write your own service file.

See documentation: https://crate.io/docs/install/local/linux/#red-hat

Christian
  • 279
  • 2
  • 8
  • Thank you so much for your suggestion,I rpm install crate, after I check the crate.service file, I realize what config I miss, I fix it and start it in my own crate config file, here is my crate.service: – MayI Jun 08 '17 at 10:57
  • [Unit] Description=CrateDB daemon After=network.target [Service] Type=simple User=hadmin Group=hadmin ExecStart=/home/hadmin/myproject/crate/bin/crate.sh start ExecStop=/home/hadmin/myproject/crate/bin/crate.sh stop StandardOutput=journal StandardError=journal TimeoutStopSec=20 LimitMEMLOCK=infinity LimitNOFILE=65536 Restart=always [Install] WantedBy=multi-user.target – MayI Jun 08 '17 at 10:58