Giter VIP home page Giter VIP logo

serviceman's Issues

Feature request: command to remove or edit a service

Hey AJ! Nice to run into your work on the internet again. I used serviceman to set up syncthing, but now I want to edit the command, and it seems I'm going to have to reach under syncthing to edit the systemd service directly. Not a huge deal, but would be nice to also have the commands to remove or overwrite a service built-in.

-- Lauren

add openrc support

Notes

Proof of Concept

curl -L https://github.com/therootcompany/serviceman/files/15244697/serviceman.tar.gz \
  -o ./serviceman.tar.gz

mkdir -p ~/bin/
tar xvzf ./serviceman.tar.gz -C ~/bin/

serviceman-add:

#!/bin/sh
set -e
set -u

g_sudo=''
if command -v sudo > /dev/null; then
    g_sudo='sudo'
fi

main() { (
    a_name="${1:-}"
    a_dashes="${2:-}"
    a_cmd="${3:-}"
    shift || true
    shift || true
    shift || true
    a_cmdargs="$*"

    if test "--" != "${a_dashes}"; then
        echo >&2 ""
        echo >&2 "USAGE"
        echo >&2 "    serviceman-add <service-name> -- <command> [args...]"
        echo >&2 ""
        echo >&2 "EXAMPLE"
        echo >&2 "    serviceman-add foo-api -- node ./server.js"
        echo >&2 ""
        return 1
    fi

    b_workdir="$(pwd)"
    b_cmdname="${a_name}"
    b_name="${a_name} service"
    b_desc="Accepts authorized API reqs to sets Title, Desc, etc"
    b_cmdpath="$(realpath "$(command -v "${a_cmd}")")"
    b_user="$(id -u -n)"
    b_group="$(id -g -n)"
    # b_stdout="/var/log/${b_cmdname}.log"
    # b_stderr="/var/log/${b_cmdname}.err"

    b_dir="$(dirname "${0}")"
    # shellcheck disable=SC2002
    cat "${b_dir}/_serviceman-openrc-tmpl" |
        sed "s;name=.*;name='${b_name}';" |
        sed "s;description=.*;description='${b_desc}';" |
        sed "s;command=.*;command='${b_cmdpath}';" |
        sed "s;command_args=.*;command_args='${a_cmdargs}';" |
        sed "s;command_user=.*;command_user='${b_user}:${b_group}';" |
        sed "s;supervise_daemon_args=.*;supervise_daemon_args='--chdir ${b_workdir} --env PATH=${PATH}';" |
        sed "s;root:;${b_user}:;" |
        sed "s;:www-data;:${b_group};" |
        sed "s;exampled;${b_cmdname};" > "${b_cmdname}"

    $g_sudo mv "${b_cmdname}" "/etc/init.d/${b_cmdname}"
    $g_sudo chown root "/etc/init.d/${b_cmdname}"
    $g_sudo chmod 0755 "/etc/init.d/${b_cmdname}"

    $g_sudo mkdir -p "/var/log/${b_cmdname}/"
    $g_sudo chmod 0750 "/var/log/${b_cmdname}"

    $g_sudo rc-service "${b_cmdname}" restart &&
        $g_sudo rc-update add "${b_cmdname}"
); }

main "${@:-}"

_serviceman-add-openrc-tmpl:

#!/sbin/openrc-run
supervisor=supervise-daemon

name="Example System Daemon"
description="runs exampled and captures stdout and stderr to log files"

command=/opt/exampled/bin/exampled
command_args="run --port 1337"
command_user=root:www-data
supervise_daemon_args="--chdir /tmp --env PATH='/bin'"
output_log=/var/log/exampled.log
error_log=/var/log/exampled.err

start_pre() {
    checkpath --dir --owner root:www-data --mode 0750 \
        /var/log/exampled

    checkpath --file --owner root:www-data --mode 0640 \
        /var/log/exampled/stdout.log \
        /var/log/exampled/stderr.err
}

depend() {
    need net
}

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.