Skip to content

Commit 83addf9

Browse files
authored
Set both JAVA_HOME and PATH environment for daemon-services (#17370)
1 parent d1ae3ce commit 83addf9

2 files changed

Lines changed: 64 additions & 4 deletions

File tree

scripts/tools/ops/daemon-confignode.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ if [ ! -d "$SYSTEMD_DIR" ]; then
2525
exit 1 # Exit with an error status
2626
fi
2727

28-
if [ -z "$JAVA_HOME" ]; then
29-
echo "JAVA_HOME is not set. Please set the JAVA_HOME environment variable."
28+
if ! java --version >/dev/null 2>&1; then
29+
echo "java command is not available. Please install Java or ensure it is in PATH."
3030
exit 1
3131
fi
3232

3333
FILE_NAME=$SYSTEMD_DIR/iotdb-confignode.service
3434

35+
if [ -z "$JAVA_HOME" ]; then
3536
cat > "$FILE_NAME" <<EOF
3637
[Unit]
3738
Description=iotdb-confignode
@@ -46,6 +47,34 @@ Type=simple
4647
User=root
4748
Group=root
4849
Environment=JAVA_HOME=$JAVA_HOME
50+
Environment=PATH=$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
51+
ExecStart=$IOTDB_SBIN_HOME/start-confignode.sh
52+
ExecStop=$IOTDB_SBIN_HOME/stop-confignode.sh
53+
Restart=on-failure
54+
SuccessExitStatus=143
55+
RestartSec=5
56+
StartLimitInterval=600s
57+
StartLimitBurst=3
58+
RestartPreventExitStatus=SIGKILL
59+
60+
[Install]
61+
WantedBy=multi-user.target
62+
EOF
63+
else
64+
cat > "$FILE_NAME" <<EOF
65+
[Unit]
66+
Description=iotdb-confignode
67+
Documentation=https://iotdb.apache.org/
68+
After=network.target
69+
70+
[Service]
71+
StandardOutput=null
72+
StandardError=null
73+
LimitNOFILE=65536
74+
Type=simple
75+
User=root
76+
Group=root
77+
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
4978
ExecStart=$IOTDB_SBIN_HOME/start-confignode.sh
5079
ExecStop=$IOTDB_SBIN_HOME/stop-confignode.sh
5180
Restart=on-failure
@@ -58,6 +87,7 @@ RestartPreventExitStatus=SIGKILL
5887
[Install]
5988
WantedBy=multi-user.target
6089
EOF
90+
fi
6191

6292
echo "Daemon service of IoTDB ConfigNode has been successfully registered."
6393

scripts/tools/ops/daemon-datanode.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ if [ ! -d "$SYSTEMD_DIR" ]; then
2525
exit 1 # Exit with an error status
2626
fi
2727

28-
if [ -z "$JAVA_HOME" ]; then
29-
echo "JAVA_HOME is not set. Please set the JAVA_HOME environment variable."
28+
if ! java --version >/dev/null 2>&1; then
29+
echo "java command is not available. Please install Java or ensure it is in PATH."
3030
exit 1
3131
fi
3232

3333
FILE_NAME=$SYSTEMD_DIR/iotdb-datanode.service
3434

35+
if [ -z "$JAVA_HOME" ]; then
3536
cat > "$FILE_NAME" <<EOF
3637
[Unit]
3738
Description=iotdb-datanode
@@ -46,6 +47,34 @@ Type=simple
4647
User=root
4748
Group=root
4849
Environment=JAVA_HOME=$JAVA_HOME
50+
Environment=PATH=$JAVA_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
51+
ExecStart=$IOTDB_SBIN_HOME/start-datanode.sh
52+
ExecStop=$IOTDB_SBIN_HOME/stop-datanode.sh
53+
Restart=on-failure
54+
SuccessExitStatus=143
55+
RestartSec=5
56+
StartLimitInterval=600s
57+
StartLimitBurst=3
58+
RestartPreventExitStatus=SIGKILL
59+
60+
[Install]
61+
WantedBy=multi-user.target
62+
EOF
63+
else
64+
cat > "$FILE_NAME" <<EOF
65+
[Unit]
66+
Description=iotdb-datanode
67+
Documentation=https://iotdb.apache.org/
68+
After=network.target
69+
70+
[Service]
71+
StandardOutput=null
72+
StandardError=null
73+
LimitNOFILE=65536
74+
Type=simple
75+
User=root
76+
Group=root
77+
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
4978
ExecStart=$IOTDB_SBIN_HOME/start-datanode.sh
5079
ExecStop=$IOTDB_SBIN_HOME/stop-datanode.sh
5180
Restart=on-failure
@@ -58,6 +87,7 @@ RestartPreventExitStatus=SIGKILL
5887
[Install]
5988
WantedBy=multi-user.target
6089
EOF
90+
fi
6191

6292
echo "Daemon service of IoTDB DataNode has been successfully registered."
6393

0 commit comments

Comments
 (0)