therootcompany / serviceman Goto Github PK
View Code? Open in Web Editor NEWCross-platform service management for Mac, Linux, and Windows.
Home Page: https://webinstall.dev/serviceman
License: Mozilla Public License 2.0
Cross-platform service management for Mac, Linux, and Windows.
Home Page: https://webinstall.dev/serviceman
License: Mozilla Public License 2.0
Basic
: https://wiki.alpinelinux.org/wiki/Writing_Init_Scripts#Basic_examplecheckpath
: https://manpages.debian.org/testing/openrc/openrc-run.8.en.html--env
: https://manpages.org/supervise-daemon/8curl -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
}
Add darwin_arm64 windows_arm64 release?
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.