forked from nnlgsakib/mind-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-service.sh
47 lines (35 loc) · 1.03 KB
/
setup-service.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Define variables
SERVICE_NAME="mind-node.service"
SERVICE_PATH="/etc/systemd/system/$SERVICE_NAME"
WORKING_DIRECTORY="$PWD"
EXEC_START="/bin/bash -c '$WORKING_DIRECTORY/mind-cli node start-node'"
USER=$(whoami) # Auto-detect the current user
# Create the service file
echo "Creating $SERVICE_NAME service file..."
sudo bash -c "cat > $SERVICE_PATH <<EOL
[Unit]
Description=Mind Node Service
After=network.target
[Service]
Type=simple
User=$USER
WorkingDirectory=$WORKING_DIRECTORY
ExecStart=$EXEC_START
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOL"
# Reload systemd to recognize the new service
echo "Reloading systemd daemon..."
sudo systemctl daemon-reload
# Start the service
echo "Starting $SERVICE_NAME..."
sudo systemctl start $SERVICE_NAME
# Enable the service to start on boot
echo "Enabling $SERVICE_NAME to start on boot..."
sudo systemctl enable $SERVICE_NAME
# Display the service status
echo "Displaying the status of $SERVICE_NAME..."
echo "Setup complete!"
sudo journalctl -u mind-node.service -f