1+ #! /bin/bash
2+ #
3+ # Licensed to the Apache Software Foundation (ASF) under one
4+ # or more contributor license agreements. See the NOTICE file
5+ # distributed with this work for additional information
6+ # regarding copyright ownership. The ASF licenses this file
7+ # to you under the Apache License, Version 2.0 (the
8+ # "License"); you may not use this file except in compliance
9+ # with the License. You may obtain a copy of the License at
10+ #
11+ # http://www.apache.org/licenses/LICENSE-2.0
12+ #
13+ # Unless required by applicable law or agreed to in writing,
14+ # software distributed under the License is distributed on an
15+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+ # KIND, either express or implied. See the License for the
17+ # specific language governing permissions and limitations
18+ # under the License.
19+ #
20+ IOTDB_AINODE_SBIN_HOME=" $( cd " ` dirname " $0 " ` " /../../sbin; pwd) "
21+ SYSTEMD_DIR=" /etc/systemd/system"
22+
23+ if [ ! -d " $SYSTEMD_DIR " ]; then
24+ echo " Current system can't support systemd"
25+ exit 1 # Exit with an error status
26+ fi
27+
28+ FILE_NAME=$SYSTEMD_DIR /iotdb-ainode.service
29+
30+ cat > " $FILE_NAME " << EOF
31+ [Unit]
32+ Description=iotdb-ainode
33+ Documentation=https://iotdb.apache.org/
34+ After=network.target
35+
36+ [Service]
37+ StandardOutput=null
38+ StandardError=null
39+ LimitNOFILE=65536
40+ Type=simple
41+ User=root
42+ Group=root
43+ ExecStart=$IOTDB_AINODE_SBIN_HOME /start-ainode.sh
44+ ExecStop=/bin/kill -TERM -\$ MAINPID
45+ Restart=on-failure
46+ SuccessExitStatus=143
47+ RestartSec=5
48+ StartLimitInterval=600s
49+ StartLimitBurst=3
50+ RestartPreventExitStatus=SIGKILL
51+ TimeoutStopSec=60s
52+
53+ [Install]
54+ WantedBy=multi-user.target
55+ EOF
56+
57+ echo " Daemon service of IoTDB AINode has been successfully registered."
58+
59+ systemctl daemon-reload
60+ echo
61+ echo " Do you want to execute 'systemctl start iotdb-ainode'? y/n (default y)"
62+ read -r START_SERVICE
63+ if [[ -z " $START_SERVICE " || " $START_SERVICE " =~ ^[Yy]$ ]]; then
64+ " ${IOTDB_AINODE_SBIN_HOME} " /stop-ainode.sh > /dev/null 2>&1 &
65+ systemctl start iotdb-ainode
66+ echo " Executed successfully."
67+ fi
68+ echo
69+ echo " Do you want to execute 'systemctl enable iotdb-ainode' to start at boot? y/n (default y)"
70+ read -r ADD_STARTUP
71+ if [[ -z " $ADD_STARTUP " || " $ADD_STARTUP " =~ ^[Yy]$ ]]; then
72+ systemctl enable iotdb-ainode > /dev/null 2>&1
73+ echo " Executed successfully."
74+ fi
0 commit comments