From 90cd1450a0eb2b14b8a4f55dcc7b4598fb095c92 Mon Sep 17 00:00:00 2001 From: 0xOzgur <29779769+0xOzgur@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:27:33 +0300 Subject: [PATCH] service fix --- update/update.sh | 73 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/update/update.sh b/update/update.sh index e240c45..7e9257e 100644 --- a/update/update.sh +++ b/update/update.sh @@ -169,20 +169,26 @@ done echo -# Get the current user's home directory +#========================== +# SERVICE UPDATE +#========================== + +#Set variables HOME=$(eval echo ~$HOME_DIR) -# Use the home directory in the path NODE_PATH="$HOME/ceremonyclient/node" -EXEC_START="$NODE_PATH/NODE_BINARY" +EXEC_START="$NODE_PATH/$NODE_BINARY" -# Re-Create Ceremonyclient Service -echo "⏳ Re-Creating Ceremonyclient Service" -sleep 2 # Add a 2-second delay -SERVICE_FILE="/lib/systemd/system/ceremonyclient.service" -if [ ! -f "$SERVICE_FILE" ]; then - echo "📝 Creating new ceremonyclient service file..." - if ! sudo tee "$SERVICE_FILE" > /dev/null < /dev/null <&2 - exit 1 - fi -else - echo "🔍 Checking existing ceremonyclient service file..." - # Check if the required lines exist and if they are different - if ! grep -q "WorkingDirectory=$NODE_PATH" "$SERVICE_FILE" || ! grep -q "ExecStart=$EXEC_START" "$SERVICE_FILE"; then - echo "🔄 Updating existing ceremonyclient service file..." - # Replace the existing lines with new values - sudo sed -i "s|WorkingDirectory=.*|WorkingDirectory=$NODE_PATH|" "$SERVICE_FILE" - sudo sed -i "s|ExecStart=.*|ExecStart=$EXEC_START|" "$SERVICE_FILE" + then + echo "❌ Error: Failed to create ceremonyclient service file." >&2 + exit 1 + fi else - echo "✅ No changes needed." + echo "⏳ Checking existing ceremonyclient service file..." + + # Function to add or update a line in the [Service] section + update_service_section() { + local key="$1" + local value="$2" + if grep -q "^$key=" "$SERVICE_FILE"; then + current_value=$(grep "^$key=" "$SERVICE_FILE" | cut -d'=' -f2-) + if [ "$current_value" != "$value" ]; then + echo "⏳ Updating $key from $current_value to $value in the service file..." + sudo sed -i "s|^$key=.*|$key=$value|" "$SERVICE_FILE" + else + echo "✅ $key=$value already exists and is correct." + fi + else + echo "⏳ Adding $key=$value to the service file..." + sudo sed -i "/^\[Service\]/,/^\[/ { + /^\[Install\]/i $key=$value + }" "$SERVICE_FILE" + fi + } + + # Update all required lines in the [Service] section + update_service_section "WorkingDirectory" "$NODE_PATH" + update_service_section "ExecStart" "$EXEC_START" + update_service_section "KillSignal" "SIGINT" + update_service_section "TimeoutStopSec" "30s" fi fi +echo "✅ Service file update completed." +echo + # Start the ceremonyclient service echo "✅ Starting Ceremonyclient Service" sleep 2 # Add a 2-second delay