Crates.io | servicer |
lib.rs | servicer |
version | 0.1.14 |
source | src |
created_at | 2023-08-06 13:43:24.522205 |
updated_at | 2023-11-11 17:55:23.911716 |
description | Simplify Service Management on systemd |
homepage | https://servicer.dev |
repository | https://github.com/servicer-labs/servicer |
max_upload_size | |
id | 937153 |
size | 98,239 |
servicer
is a user-friendly Command Line Interface (CLI) tool designed to simplify service management on systemd
, abstracting away the complexities of the systemd ecosystem. With an easy-to-use API comparable to popular tools like pm2, servicer empowers users to create, control, and manage services effortlessly.
Intuitive CLI: servicer provides a simple and intuitive command-line interface, making it accessible to both beginners and experienced users.
Service Creation: Easily create and define new services by specifying essential details like service name, command, working directory, and environment variables.
Service Control: Start, stop, restart, enable, or disable services seamlessly with straightforward commands.
Process Monitoring: Monitor the status and health of services, ensuring reliable operation and automatic restarts in case of failures.
Service Logs: View real-time service logs directly from the terminal to facilitate troubleshooting and debugging.
Cross-platform Compatibility: servicer is designed to work on various Linux distributions with systemd support. MacOS and Windows support using launchd
and scm
is planned.
Use OS native primitives: Unlike pm2
, servicer
does not fork processes nor run a custom logger. It hooks up your app into systemd and gets out of the way. Logs are handled by journald. You need not worry about your services going down if something wrong happens to servicer
.
Lightweight: Servicer is daemonless, i.e. does not run in the background consuming resources.
Language agnostic: Servicer comes as a binary executable which does not require rust to be installed. There is not bloat from language exclusive features, such as pm2
cluster mode for node.
Currently servicer supports Linux. Systemd must be installed on the system. MacOS (launchd) and Windows (SCM) support is planned.
Download the binary from the release page for run wget https://github.com/servicer-labs/servicer/releases/download/v0.1.2/servicer
. Then setup as
# grant permissions
chmod +rwx ./servicer
# Rename to ser and make it accessable from path
sudo mv ./servicer /usr/bin/ser
# Important- symlink to node. Node must be visible to sudo user
sudo ln -s $(which node) "/usr/local/bin/node"
sudo ln -s $(which npm) "/usr/local/bin/npm"
# This should work now
ser --help
cargo install servicer
# Create a symlink to use the short name `ser`. We can now access servicer in sudo mode
sudo ln -s ~/.cargo/bin/servicer /usr/bin/ser
# Important- symlink to node. Node must be visible to sudo user
sudo ln -s $(which node) "/usr/local/bin/node"
sudo ln -s $(which npm) "/usr/local/bin/npm"
Run --help
to display tooltip. Note that sudo
mode is needed for most commands.
# Create a service for index.js
sudo ser create index.js
# Create service, start and enable on boot
sudo ser create index.js --start --enable
# Create a service for a binary
sudo ser create awesome-binary
# Custom interpreter
sudo ser create hello-typescript.ts --interpreter /home/hp/.config/nvm/versions/node/v20.1.0/bin/ts-node
# Custom name
sudo ser create index.js --name hello-world
# Pass params to index.js by adding them after a `--` followed by space
sudo ser create index.js -- --foo bar
# Pass env variables
sudo ser create index.js --env-vars "FOO=BAR GG=WP"
# Enable auto-restart on exit
sudo ser create index.js --auto-restart
This creates a service file in etc/systemd/system/hello-world.ser.service
. You must follow up with start
and enable
commands to start the service.
Servicer auto-detects the interpreter for node
and python
from $PATH available to the sudo user. You must manually provide the interpeter for other platforms using the interpreter flag, eg. --interpreter conda
. If the interpreter is not found in sudo $PATH, run which conda
and paste the absolute path.
You can write your own service files and manage them with servicer
. Simply rename file to end with .ser.service
instead of .service
.
sudo ser edit hello-world
# Custom editor
sudo ser edit hello-world --editor vi
Opens a .service
file in a text editor. Provides a template if the service doesn't exist.
sudo ser start hello-world
sudo ser stop hello-world
sudo ser enable hello-world
sudo ser disable hello-world
sudo ser delete hello-world
sudo ser rm hello-world
Prints PID, name, active state, enabled state, CPU and memory utilization for every service.
sudo ser status
+-------+-------------+--------+----------------+-------+--------+
| pid | name | active | enable on boot | cpu % | memory |
+-------+-------------+--------+----------------+-------+--------+
| 24294 | index.js | active | false | 0 | 9.5 KB |
+-------+-------------+--------+----------------+-------+--------+
Finds the .service
and unit file path for a service.
sudo ser which hello-world
+--------------+--------------------------------------------------------------+
| name | path |
+--------------+--------------------------------------------------------------+
| Service file | /etc/systemd/system/hello-world.ser.service |
+--------------+--------------------------------------------------------------+
| Unit file | /org/freedesktop/systemd1/unit/hello_2dworld_2eser_2eservice |
+--------------+--------------------------------------------------------------+
ser logs hello-world
# Follow live logs
ser logs hello-world --follow
ser cat hello-world
ser rename index.js hello-world
# Or
ser mv index.js hello-world
node
is unavailable in sudo mode. You must symlink node
to the path available to sudo. Source- https://stackoverflow.com/a/40078875/7721443sudo ln -s $(which node) "/usr/local/bin/node"
sudo ln -s $(which npm) "/usr/local/bin/npm"
servicer
is licensed under the MIT license.
servicer
is distributed "as-is" and without any warranty, expressed or implied. The authors and contributors of servicer
shall not be held liable for any damages or losses resulting from the use or inability to use the software.
Before using servicer
, please review the MIT License and the lack of warranty carefully. By using the software, you are agreeing to the terms of the license and acknowledging the lack of warranty.
We acknowledge all the packages and libraries used in the development of servicer
. Their contributions have been invaluable in making this project possible. Parts of the README and codebase are generated with ChatGPT.
We welcome contributions and feedback from the community. Feel free to open issues, submit pull requests, or share your thoughts on how we can improve servicer further.
Get started with servicer and simplify your service management on systemd. Happy service creation!