Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dist: add a sample systemd service #356

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

Davidson-Souza
Copy link
Collaborator

@Davidson-Souza Davidson-Souza commented Jan 27, 2025

What is this PR for?

This PR adds a sample systemd service that may be used by package managers.

What is the purpose of this pull request?

  • Bug fix;
  • New feature;
  • Docs update;
  • Test;
  • Other: .

Which aspect of floresta its being addresed?

  • Blockchain;
  • Nodes communication;
  • User consumption;
  • Utreexo accumulator;
  • Other: Build/distribution.

Checklists

  • I've signed all my commits;
  • I ran just lint;
  • I ran cargo test;
  • I checked the integration tests;
  • I'm linking the issue being fixed by this PR (if any).

Description

This PR adds a new floresta.service file that contains a fully functional systemd service to run floresta as a system-wide service. It is meant for package managers and automated scripts that installs floresta and makes the environment for it to run.

Notes to the reviewers

For this service to work you need a user and group called florestad with a home at /var/lib/florestad and the following directories:

d /var/lib/florestad 0710 florestad florestad - -
d /etc/florestad     0710 florestad florestad - -

@jaoleal
Copy link
Contributor

jaoleal commented Jan 27, 2025

Concept ACK.
IMO this pr could be complemented with a check_setup_for_service.sh

Something like this

#!/bin/bash

# This script is intended to serve as a demonstration of which setup floresta.service needs to run properly.

# Check if the group 'florestad' exists
if getent group florestad > /dev/null 2>&1; then
    echo "Group 'florestad' exists."
else
    echo "Group 'florestad' does not exist."
    return 1
fi

# Check if the user 'florestad' exists
if id -u florestad > /dev/null 2>&1; then
    echo "User 'florestad' exists."
else
    echo "User 'florestad' does not exist."
    return 11
fi

# Check if the directory /var/lib/florestad exists and has proper permissions
if [ -d "/var/lib/florestad" ]; then
    echo "Directory '/var/lib/florestad' exists."
    if [ "$(stat -c '%U' /var/lib/florestad)" == "florestad" ] && [ "$(stat -c '%G' /var/lib/florestad)" == "florestad" ]; then
        echo "Directory '/var/lib/florestad' is owned by user 'florestad' and group 'florestad'."
    else
        echo "Directory '/var/lib/florestad' is not owned by user 'florestad' and group 'florestad'."
        return 1
        fi
else
    echo "Directory '/var/lib/florestad' does not exist."
    return 1
fi

# Check if the directory /etc/florestad exists and has proper permissions
if [ -d "/etc/florestad" ]; then
    echo "Directory '/etc/florestad' exists."
    if [ "$(stat -c '%U' /etc/florestad)" == "florestad" ] && [ "$(stat -c '%G' /etc/florestad)" == "florestad" ]; then
        echo "Directory '/etc/florestad' is owned by user 'florestad' and group 'florestad'."
    else
        echo "Directory '/etc/florestad' is not owned by user 'florestad' and group 'florestad'."
        return 1
        fi
else

    echo "Directory '/etc/florestad' does not exist."
    return 1
fi

contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
@Davidson-Souza
Copy link
Collaborator Author

Concept ACK. IMO this pr could be complemented with a check_setup_for_service.sh

Something like this

#!/bin/bash

# This script is intended to serve as a demonstration of which setup floresta.service needs to run properly.

# Check if the group 'florestad' exists
if getent group florestad > /dev/null 2>&1; then
    echo "Group 'florestad' exists."
else
    echo "Group 'florestad' does not exist."
    return 1
fi

# Check if the user 'florestad' exists
if id -u florestad > /dev/null 2>&1; then
    echo "User 'florestad' exists."
else
    echo "User 'florestad' does not exist."
    return 11
fi

# Check if the directory /var/lib/florestad exists and has proper permissions
if [ -d "/var/lib/florestad" ]; then
    echo "Directory '/var/lib/florestad' exists."
    if [ "$(stat -c '%U' /var/lib/florestad)" == "florestad" ] && [ "$(stat -c '%G' /var/lib/florestad)" == "florestad" ]; then
        echo "Directory '/var/lib/florestad' is owned by user 'florestad' and group 'florestad'."
    else
        echo "Directory '/var/lib/florestad' is not owned by user 'florestad' and group 'florestad'."
        return 1
        fi
else
    echo "Directory '/var/lib/florestad' does not exist."
    return 1
fi

# Check if the directory /etc/florestad exists and has proper permissions
if [ -d "/etc/florestad" ]; then
    echo "Directory '/etc/florestad' exists."
    if [ "$(stat -c '%U' /etc/florestad)" == "florestad" ] && [ "$(stat -c '%G' /etc/florestad)" == "florestad" ]; then
        echo "Directory '/etc/florestad' is owned by user 'florestad' and group 'florestad'."
    else
        echo "Directory '/etc/florestad' is not owned by user 'florestad' and group 'florestad'."
        return 1
        fi
else

    echo "Directory '/etc/florestad' does not exist."
    return 1
fi

Those configurations should come from your package manager. And any decent PM would check those anyway.

@Davidson-Souza
Copy link
Collaborator Author

@luisschwab done!

contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Show resolved Hide resolved
contrib/init/floresta.service Show resolved Hide resolved
@luisschwab
Copy link
Contributor

luisschwab commented Jan 28, 2025

Found a few more issues, but this should be it.

@Davidson-Souza
Copy link
Collaborator Author

Fixed. I'm intentionally making it only group-readable, so I've updated the PR description with mode 0710 instead of 0770

@luisschwab
Copy link
Contributor

Found a few more issues, but this should be it.

Found a few more. Third time's the charm!

contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
contrib/init/floresta.service Outdated Show resolved Hide resolved
@Davidson-Souza
Copy link
Collaborator Author

Davidson-Souza commented Jan 28, 2025

Jeez, now I think I got all of them

@luisschwab
Copy link
Contributor

ACK 66afab5

@Davidson-Souza Davidson-Souza merged commit 7e456c2 into vinteumorg:master Jan 29, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants