Coder Social home page Coder Social logo

Comments (1)

js-ts avatar js-ts commented on May 28, 2024

what do you want the service file to do ?
I wrote these service files for the VMI to run bacalhau serve and restart the service when it fails

[Unit]
Description=Bacalhau Daemon
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Environment="LOG_TYPE=json"
Environment="BACALHAU_DIR=/data"
Environment="BACALHAU_ENVIRONMENT=local"
Restart=always
RestartSec=5s
ExecStart=bacalhau serve ${args}

[Install]
WantedBy=multi-user.target
[Unit]
Description=Startup Script
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
ExecStart=/usr/local/bin/startup-script.sh
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target
#! /bin/bash

echo "Startup script is running as user: $(whoami)"

CONFIG_FILE="/etc/config.yaml"

echo "Fetching node type..."
NODE_TYPE=$(curl -f http://metadata.google.internal/computeMetadata/v1/instance/attributes/node_type -H "Metadata-Flavor: Google")
CURL_STATUS=$?

if [ $CURL_STATUS -ne 0 ]; then
    echo "Error fetching NODE_TYPE. Exiting..."
    exit 1
fi

echo "Node Type: $NODE_TYPE"

if [ "$NODE_TYPE" = "requester" ]; then
    echo "Node type is requester."
    if [ ! -f $CONFIG_FILE ]; then
        sudo cp /etc/requester_config.yaml $CONFIG_FILE
    fi
else
    echo "Node type is not requester. Fetching requester IP..."
    REQUESTER_IP=$(curl -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/attributes/requester_ip")
    echo "Requester IP: $REQUESTER_IP"
    if [ ! -f $CONFIG_FILE ]; then
        sudo cp /etc/compute_config.yaml $CONFIG_FILE
        sed -i "s/\${requester_ip}/$REQUESTER_IP/g" $CONFIG_FILE
    fi
fi

if [ ! -d /data ]; then
    sudo mkdir -p /data
    sudo chmod 0700 /data
    echo "/data directory created."
else
    echo "/data directory already exists. No need to create."
fi
if [ ! -f /data/config.yaml ]; then
    echo "Moving configuration file..."
    sudo mv "$CONFIG_FILE" /data/config.yaml
else
    echo "Configuration file already exists, not moving."
fi

echo "Checking and moving service files..."
if [ ! -f /etc/systemd/system/bacalhau.service ]; then
    sudo mv /etc/bacalhau.service /etc/systemd/system/bacalhau.service
else
    echo "Service file already exists in target location, not moving."
fi

echo "Reloading systemctl daemon..."
systemctl daemon-reload

echo "Handling Docker service..."
systemctl enable docker
systemctl restart docker

echo "Enabling bacalhau service..."
systemctl enable bacalhau.service
systemctl restart bacalhau.service

from bacalhau.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.