Git Product home page Git Product logo

unitscript's Introduction

unitscript

This program can be used as an interpreter for unitscripts, which are yaml based init scripts. Unitscripts could be used as easier alternative to shell scripts as init scripts or to standardise init scripts across many different sysv-rc compatible distributions. This project was created to show how to create something similar to systemd units which could be used to standardise init scripts across distributions but using existing technologies and without imposing a system which has since grown way bayond any reasonable scope on everybody.

This project does only provide some basic functionality to start and stop programs at the moment and may be extendet by additional features in the future. It will, however, never become a daemon in the classical sense and unitscripts will never do anything else than managing services.

Currently supported actions

action description
start Starts the program. The script won't exit until the 'start check' condition is met.
stop Stops the program by sending it a SIGTERM signal. Won't exit until the process whose pid is written in the pid file doesn't exist anymore or an error occurs.
restart shorthand for start and stop actions.
status Returns if the process is running and on which pid or not. Exit code will be either 0 for yes, 1 fo no, or anything else to indicate an error.
check Does nothing, but will still exit with an error message if the unitscript contains an error
zap Removes the pid file

Format

A unitscript consists of the shebang line #!/usr/bin/env unitscript, followed by an LSB Header, followed by the unitscript options. The wholeunit script is a valid yaml file.

The following unitscript options are currently supported:

option type description
user string A valid user name from /etc/passwd
group string A valid group name from /etc/group
start check string Can be either exit, start, or notification.
exit: The process forks itself, wait until it exits and check the return code.
start: The moment the executable is executed is considered a successful start.
notification: The process writes a newline to a file descriptor to indicate the start succeeded. You can specify the file descriptor using the notifyfd property, default is 3.
program string A shell script. The default interpreter is sh -l, but can be overwritten using a shebang line
uid integer A user id of a valid user from /etc/passwd
gid integer A group id of a valid group from /etc/group
notifyfd integer Used if start check is set to notification. Default is 3.
logging string If and how stdout and stdin should be redirected. Can be either: default, syslog, stdio or none.
default: equivalent to syslog if 'start check' is 'start', stdout if 'start check' is 'exit', invalid otherwise.
syslog: redirect stdout and stderr to syslog before executing 'program'.
stdio: keep stdout and stderr unchanged
none: close stdout and stderr before execution.
pidfile string Defaults to /var/run/unitscript/<script name>.pid
manage pidfile boolean Either yes or no. Specifies if the program or the unit script should create the pid file.
Default for 'start check' 'exit' is 'no'.
Default for 'start check' 'start' is 'yes'.
env         map     Environment variables to set before program execution
env scripts list A list of posix shell scripts. The variables those scripts define will be exported as environment variables before executing the program
env files list A list of files similar in syntax to /etc/environment. The variables those scripts define will be exported as environment variables before executing the program
working directory string Sets the working directory. Defaults to the user home directory.
umask integer The umask using which the program is started, defaults to 0022
rlimits    map     All posix rlimits and some system specific ones can be set. The name of the rlimit should be in lower case and shouldn't be prefixed with RLIMIT_. The value for an rlimit can either be an integer, which will set the cur and max rlimit values, or max:cur, where max and cur are integers used to set the max and cur values of the rlimit.

Environment variables

All environment variables will be cleared before execution, but per default a sh login shell is used to start the program, which should source /etc/profile and .profile, which may set some basic environment variables like the PATH variable. In addition to this, all variables specified using the 'env', 'env files' and 'env scripts' option and the following ones will be set:

variable description
SHELL The shell specified for the user in /etc/passwd
HOME The user home directory as specified in /etc/passwd
PIDFILE The location of the pid file
NOTIFICATION_FD The file descriptor number using which the program can indicate that it finished starting up

Build requirements

This project requires my dpaparser project for building. You can find it at https://github.com/Daniel-Abrecht/dpaparser https://gitlab.com/DanielAbrecht/dpaparser Or wherever else I'll put a copy of my projects in addition to that in the future.

You'll also need libbsd and libyaml.

unitscript's People

Contributors

daniel-abrecht avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

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.