Enhance systemd service creation by cleaning up existing services and ensuring a fresh start
This commit is contained in:
parent
3d504efcea
commit
abcfca230d
@ -581,12 +581,29 @@ configure_firewall() {
|
|||||||
create_systemd_service() {
|
create_systemd_service() {
|
||||||
local service_file="/etc/systemd/system/debros-$NODE_TYPE.service"
|
local service_file="/etc/systemd/system/debros-$NODE_TYPE.service"
|
||||||
|
|
||||||
if [ -f "$service_file" ]; then
|
# Always clean up any existing service files to ensure fresh start
|
||||||
log "Systemd service already exists, updating..."
|
for service in debros-bootstrap debros-node; do
|
||||||
# Stop the service before updating
|
if [ -f "/etc/systemd/system/$service.service" ]; then
|
||||||
sudo systemctl stop debros-$NODE_TYPE.service 2>/dev/null || true
|
log "Cleaning up existing $service service..."
|
||||||
|
sudo systemctl stop $service.service 2>/dev/null || true
|
||||||
|
sudo systemctl disable $service.service 2>/dev/null || true
|
||||||
|
sudo rm -f /etc/systemd/system/$service.service
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
log "Creating new systemd service..."
|
||||||
|
|
||||||
|
# Determine the correct ExecStart command based on node type
|
||||||
|
local exec_start=""
|
||||||
|
if [ "$NODE_TYPE" = "bootstrap" ]; then
|
||||||
|
exec_start="$INSTALL_DIR/bin/bootstrap -data $INSTALL_DIR/data/bootstrap -port $BOOTSTRAP_PORT"
|
||||||
else
|
else
|
||||||
log "Creating systemd service..."
|
# For regular nodes, we need to specify the bootstrap peer
|
||||||
|
# This should be configured based on the bootstrap node's address
|
||||||
|
exec_start="$INSTALL_DIR/bin/node -data $INSTALL_DIR/data/node -port $NODE_PORT"
|
||||||
|
# Note: Bootstrap peer address would need to be configured separately
|
||||||
|
# exec_start="$INSTALL_DIR/bin/node -data $INSTALL_DIR/data/node -port $NODE_PORT -bootstrap /ip4/BOOTSTRAP_IP/tcp/$BOOTSTRAP_PORT/p2p/BOOTSTRAP_PEER_ID"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat > /tmp/debros-$NODE_TYPE.service << EOF
|
cat > /tmp/debros-$NODE_TYPE.service << EOF
|
||||||
@ -600,7 +617,7 @@ Type=simple
|
|||||||
User=debros
|
User=debros
|
||||||
Group=debros
|
Group=debros
|
||||||
WorkingDirectory=$INSTALL_DIR
|
WorkingDirectory=$INSTALL_DIR
|
||||||
ExecStart=$INSTALL_DIR/bin/$NODE_TYPE -config $INSTALL_DIR/configs/$NODE_TYPE.yaml
|
ExecStart=$exec_start
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
StandardOutput=journal
|
StandardOutput=journal
|
||||||
|
Loading…
x
Reference in New Issue
Block a user