X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=serviceman%2FREADME.md;h=e05096829e0640f695af20efd94b8582a80b01ec;hb=b1d3b44f966332434d8ec49b2a0df569e9bf8c16;hp=497bf1f7e166b7154a4382787362f83256c39272;hpb=d32b7bdd4449fb90ab03a7c84b50eb6171d11413;p=webi-installers%2F.git diff --git a/serviceman/README.md b/serviceman/README.md index 497bf1f..e050968 100644 --- a/serviceman/README.md +++ b/serviceman/README.md @@ -3,64 +3,165 @@ title: Serviceman homepage: https://git.rootprojects.org/root/serviceman tagline: | Serviceman: cross-platform service management for Linux, Mac, and Windows. -description: | - Serviceman is a hassle-free wrapper around your system launcher. It works with the default system launcher to make it easy to start _user_- and _system_-level services, such as webservers, backup scripts, network and system tools, etc. - - Supports - - `launchctl` (macOS) - - `systemctl` (Linux) - - The Registry (Windows) --- +To update or switch versions, run `webi serviceman@stable` + +## Cheat Sheet + +> Serviceman is a hassle-free wrapper around your system launcher. It works with +> the default system launcher to make it easy to start _user_- and +> _system_-level services, such as webservers, backup scripts, network and +> system tools, etc. + +Supports + +- `launchctl` (macOS) +- `systemctl` (Linux) +- The Registry (Windows) + Serviceman can run an app in just about any programming language very simply. If you'd like to learn what `serviceman` does without actually making changes, -add the `--dry-run` option. +add the `--dryrun` option. -### Node.js +### Example: Bash + +```bash +sudo env PATH="$PATH" serviceman add bash ./backup.sh /mnt/data +``` + +### Example: Node.js **Development Server** ```bash pushd ./my-node-app/ + sudo env PATH="$PATH" \ - serviceman add --cap-net-bind --system npx nodemon + serviceman add --system --cap-net-bind \ + npx nodemon ./server.js ``` **Production Server** ```bash pushd ./my-node-app/ + sudo env PATH="$PATH" \ - serviceman add --cap-net-bind --system npm start + serviceman add --system --cap-net-bind \ + npm start ``` -### Golang +### Example: Golang ```bash pushd ./my-go-package/ + sudo env PATH="$PATH" \ - serviceman add --system go run -mod=vendor cmd/my-service/*.go --port 3000 + serviceman add --system \ + go run -mod=vendor cmd/my-service/*.go --port 3000 ``` ```bash pushd ./my-go-package/ go build -mod=vendor cmd/my-service + sudo env PATH="$PATH" \ - serviceman add --cap-net-bind --system ./my-service --port 80 + serviceman add --cap-net-bind --system \ + ./my-service --port 80 ``` -### And even bash! +### How to see all services ```bash -sudo env PATH="$PATH" serviceman add bash ./backup.sh /mnt/data +serviceman list --system +serviceman list --user +``` + +```txt +serviceman-managed services: + + example-service +``` + +### How to restart a service + +You can either `add` the service again (which will update any changed options), +or you can `stop` and then `start` any service by its name: + +```bash +sudo env PATH="$PATH" serviceman stop example-service +sudo env PATH="$PATH" serviceman start example-service +``` + +## What a typical systemd .service file looks like + +```txt +[Unit] +Description=example-service +After=network-online.target +Wants=network-online.target systemd-networkd-wait-online.service + +[Service] +Restart=always +StartLimitInterval=10 +StartLimitBurst=3 + +User=root +Group=root + +WorkingDirectory=/srv/example-service +ExecStart=/srv/example-service/bin/example-command start +ExecReload=/bin/kill -USR1 $MAINPID + +# Allow the program to bind on privileged ports, such as 80 and 443 +CapabilityBoundingSet=CAP_NET_BIND_SERVICE +AmbientCapabilities=CAP_NET_BIND_SERVICE +NoNewPrivileges=true + +[Install] +WantedBy=multi-user.target +``` + +## What a typical launchd .plist file looks like + +```txt + + + + + + Label + example-service + ProgramArguments + + /Users/me/example-service/bin/example-command + start + + + RunAtLoad + + KeepAlive + + + WorkingDirectory + /Users/me/example-service + + StandardErrorPath + /Users/me/.local/share/example-service/var/log/example-service.log + StandardOutPath + /Users/me/.local/share/example-service/var/log/example-service.log + + ``` -### Use `--dry-run` to see the generated launcher config: +### Use `--dryrun` to see the generated launcher config: ```bash sudo env PATH="$PATH" \ - serviceman add --dryrun bash ./backup.sh /mnt/data + serviceman add --system --dryrun \ + bash ./backup.sh /mnt/data ``` ### See the (sub)command help