painless per-user daemon manager
Nocrux is an easily configurable daemon manager that can be used by any user
on the system. It uses double-forks to transfer cleanup responsibility of
daemons to the init process.
usage: nocrux [-h] [-e] [-l] [-f] [--sudo] [--as AS_] [--stderr] [--version]
[daemon] [command]
Nocrux is a daemon process manager that is easy to configure and can
operate on the user- or root-level. The nocrux configuration syntax is
similar to Nginx. All users configuration file is in ~/.nocrux/conf,
except for the root user, which is in /etc/nocrux/conf.
This will start your $EDITOR to open the configuration file:
$ nocrux -e
The main namespace has the options and default values below:
root ~/.nocrux/run;
kill_timeout 10;
You can also include other files like this (relative paths are considered
relative to the configuration file):
include ~/more-nocrux-config.txt;
To configure a new daemon, you start a `daemon` section, specify the name
and then the daemon's options in the news scope.
daemon jupyter {
cwd ~;
run jupyter notebook;
}
You can now start the daemon with:
$ nocrux jupyter start
[nocrux]: (jupyter) starting "jupyter notebook"
[nocrux]: (jupyter) started (pid: 10117)
The following commands are available for all daemons:
- start
- stop
- restart
- status
- pid
- cat
- tail
You can specify additional commands like this:
daemon jupyter {
cwd ~;
run jupyter notebook;
command uptime echo $(($(date +%s) - $(date +%s -r $DAEMON_PIDFILE))) seconds;
}
Now to run this command:
$ nocrux jupyter uptime;
3424 seconds;
Here's a daemon configuration with all available options and the
respective default or example values:
daemon test {
# Example values:
export PATH=/usr/sbin:$PATH;
export DEBUG=1;
run ~/Desktop/mytestdaemon.sh arg1 "arg 2";
cwd ~;
command uptime echo $(($(date +%s) - $(date +%s -r $DAEMON_PIDFILE))) seconds;
requires daemon1 daemon2;
# Options with their respective defaults:
user me;
group me;
stdin /dev/null;
stdout $root/$name.out;
stderr $stdout;
pidfile $root/$name.pid;
signal term TERM;
signal kill KILL;
}
positional arguments:
daemon The name of the daemon.
command A command to execute on the specified daemon.
optional arguments:
-h, --help show this help message and exit
-e, --edit Edit the nocrux configuration file.
-l, --list List up all daemons and their status.
-f, --follow Pass -f to the tail command.
--sudo Re-invoke the same command with sudo.
--as AS_ Run the command as the specified user. Overrides --sudo.
--stderr Choose stderr instead of stdout for the cat/tail command.
--version Print the nocrux version and exit.
$ pip3 install --user nocrux # or
$ nodepy-pm install git+https://github.com/NiklasRosenstein/nocrux.git@v2.0.3 --global
Nocrux can only send SIGTERM or SIGKILL to the main process that it
originally started. If that process spawns any child precesses, it must take
care of forwarding the signal! The thread Forward SIGTERM to child in Bash
contains some information on doing that for Bash scripts. For very simple scripts
that just set up an environment, I recommend the exec
approach as described
in the link.
Example:
daemon gogs {
user gogs;
cwd /home/gogs/gogs;
run ./gogs web;
}
If you’re trying to manage a daemon that will be started by nocrux under a
different user, you need the permissions to do so. For example, the superuser
is allowed to do so and using nocrux as root should work immediately.
However, if you are not already the root user, nocrux will by default try to
re-run itself as the user specified in the daemon, eg. in this case:
sudo gogs NOCRUX_CONFIG=/home/niklas/.nocrux/conf /home/niklas/.local/bin/nocrux gogs start
This will only work if
gogs
user can read the path of the nocrux executable and thegogs
user can read your nocrux configuration fileOtherwise, you may be greeted with one of the following error messages:
v2.0.3
--sudo
command-line option--as <user>
command-line optiondaemon { export; }
field$DAEMON_PID
, $DAEMON_PIDFILE
, $DAEMON_STDOUT
,$DAEMON_STDERR
(see issue #22)daemon{ root; }
field which will change the parent directory#
comments in the configuration filedaemon { user; }
option, now serves as a default value--as
optiondaemon { run; }
may now be preceeded by any other option)-e, --edit
now opens the editor always for the user’s filev2.0.2
nocrux version
commandnocrux edit
commandall
is now sorted alphabeticallyv2.0.1
fn:out
, fn:err
and fn:pid
commands (actually already removed in 2.0.0)root
config value will now be /var/run/nocrux
if the/etc/nocrux/conf
nr.parse.strex
modulenocrux <daemon> tail
ifv2.0.0
nocrux <daemon> <command>
(switched)<daemon>
argument can be a list of~/.nocrux/conf
or/etc/nocrux/conf
v1.1.3
README.md
(corrected example and command-line interface)-e, --stderr
argumentsetup.py
(use py_modules
instead of the invalid modules
parameter)nocrux.py
directly without prior installationpid
, tail
, tail:out
and tail:err
subcommandsv1.1.2
setup.py
installation script, remove nocrux
scriptREADME.md
and renamed from README.markdown
v1.1.1
v1.1.0
nocrux
v1.0.1
krugs tail <daemon> [-e/-stderr]
commandall
krugs restart
command