From b5c2e7709dfdf8a082f6caafe9a016a8ccaabaf8 Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Fri, 24 Mar 2023 13:28:43 -0400 Subject: [PATCH] init --- README.md | 35 +++++++++++++++ src/bin/esv | 111 +++++++++++++++++++++++++++++++++++++++++++++++ src/etc/esv.conf | 13 ++++++ src/man/esv.1 | 30 +++++++++++++ 4 files changed, 189 insertions(+) create mode 100644 README.md create mode 100755 src/bin/esv create mode 100755 src/etc/esv.conf create mode 100644 src/man/esv.1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..92d746d --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +## esv + +esv is a simple service manager, compatible with sysv init scripts. It is intended to interface well wtith +busybox init, however it also works well with sysvinit. + +## Get started + +esv requires the following packages: + +- Bash (esv runtime) + +To install esv, clone the everest-tools repository: +``` +git clone https://git.everestlinux.org/EverestLinux/everest-tools +``` +Inside `src/esv/esv3`, edit install.conf.dist and ensure all options are adequate, and save as install.conf: +``` +EDITOR=your_editor_here +$EDITOR install.conf.dist +``` +Run `build.sh` as root: +``` +doas ./build.sh install +# OR +sudo ./build.sh install +# OR +su -c ./build.sh install +``` + +## Usage +``` +esv {start,stop,restart} SERVICE_NAME # start a service +esv {-h,--help} # show a help message +esv {-v,--version} # show the version +``` diff --git a/src/bin/esv b/src/bin/esv new file mode 100755 index 0000000..6d698ac --- /dev/null +++ b/src/bin/esv @@ -0,0 +1,111 @@ +#!/bin/sh +# esv - Everest Service Manager + +if [ ! -f "/etc/esv.conf" ]; then + printf "error: unable to parse /etc/esv.conf, does it exist?\n" + exit 1 +fi + +source /etc/esv.conf + +helpmsg_big() { + printf "${0} - Everest Service Manager\n" + printf "usage: ${0} [start] [stop] [restart] [-h] [-v] SERVICE NAME\n" + printf "\n" + printf "${0} {start} start a service\n" + printf "${0} {stop} stop a service\n" + printf "${0} {restart} restart a running service\n" + printf "${0} {-h/--help} print this message and exit\n" + printf "${0} {-v/--version} print the version and exit\n" + printf "\n" + printf "This program is free software.\n" + printf "See the GNU GPL version 3 for details.\n" +} + +helpmsg_small() { + printf "usage: ${0} [start] [stop] [restart] [-h] [-v] SERVICE NAME\n" +} + +check_if_exists() { + SV="${@}" + for SRV in ${SV[@]}; do + if [ ! -f "${SRV_DIR}/${SRV}" ]; then + printf "${red}service ${SRV} does not exist${reset}\n" + exit 1 + fi + done +} + +startsv() { + SV="${@}" + if [ "$SV" = "" ]; then + printf "${red}you must specify a service name${reset}\n" + exit 1 + fi + + printf "${blue}starting: $SV...${reset}\n" + for SRV in ${SV[@]}; do + source ${SRV_DIR}/${SRV} + run + done +} + +stopsv() { + SV="${@}" + if [ "$SV" = "" ]; then + printf "${red}you must specify a service name${reset}\n" + exit 1 + fi + + printf "${blue}stopping: $SV...${reset}\n" + for SRV in ${SV[@]}; do + source ${SRV_DIR}/${SRV} + stop + done +} + +restartsv() { + SV="${@}" + if [ "$V" = "" ]; then + printf "${red}you must specify a service name${reset}\n" + exit 1 + fi + + printf "${blue} restarting: $SV...${reset}\n" + for SRV in ${SV[@]}; do + source ${SRV_DIR}/${SRV} + restart + done +} + +printver() { + printf "${blue}esv v3.0.0${reset}\n" +} + +case $1 in + -h|--help) + helpmsg_big + exit 0 + ;; + -v|--version) + printver + exit 0 + ;; + start) + shift + check_if_exists "$@" + startsv "$@" + ;; + stop) + shift + check_if_exists "$@" + stopsv "$@" + ;; + restart) + shift + check_if_exists "$@" + restartsv "$@" + ;; + *) + helpmsg_small "$@" +esac diff --git a/src/etc/esv.conf b/src/etc/esv.conf new file mode 100755 index 0000000..f8f095f --- /dev/null +++ b/src/etc/esv.conf @@ -0,0 +1,13 @@ +# /etc/esv.conf + +# Where services are stored. +# On Everest, this is /etc/init.d +export SRV_DIR="/etc/init.d" + +# Colors +export red="\033[1;31m" +export green="\033[1;32m" +export blue="\033[1;34m" +export reset="\033[m" + +# end /etc/esv.conf diff --git a/src/man/esv.1 b/src/man/esv.1 new file mode 100644 index 0000000..779da39 --- /dev/null +++ b/src/man/esv.1 @@ -0,0 +1,30 @@ +.\" Manpage for esv. +.TH man 1 "24 March 2023" "3.0" "Everest Linux Manual" +.SH NAME +esv \- start, stop, and restart services from sysv-style init scripts +.SH SYNPOSIS +esv [start] [stop] [restart] [-h] [-v] +.SH DESCRIPTION +esv is a service manager for Everest Linux which interfaces with already-existing sysv-style init scripts. It is written in POSIX sh, and as such interfaces well with these scripts. +.SH OPTIONS +.TP +.BR start +starts a daemon +.TP +.BR stop +stops a daemon +.TP +.BR restart +restarts a daemon +.TP +.BR \-h +shows a help message +.TP +.BR \-v +shows the version +.SH SEE ALSO +ecrypt(1) gpkg(8) +.SH BUGS +Report all bugs on the issues page at https://git.everestlinux.org/EverestLinux/esv +.SH AUTHOR +Liam Waldron (liamwaldron@everestlinux.org)