diff --git a/README.md b/README.md index cccef83..7756bf4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,13 @@ Various runit service files for per-user services. May need to be modified to wo Helper scripts: - `log`: symlink as the `run` script in your service's log directory to enable logging to `~/.local/log/` - `setup-supervise.zsh`: run to create symlinks for `supervise` directories, so they are created in $XDG_RUNTIME_DIR -- `new-service`: create a new service, executing the given command line. Optionally pass `-l` before any other arguments to also create a logging entry. Example: +- `new-service`: create a new service, executing the given command line. + Accepted options before service name: + + - `-l`, `--log`: create a log directory and symlink `log` script + - `-i PROC`, `--import-env PROC`: include import-env script and import environment from process `PROC` + + Example + ``` + ./new-service -l my-daemon --foreground -a -b -c ``` - ./new-service -l my-daemon --foreground -a -b -c - ``` diff --git a/new-service b/new-service index 32a7fa1..1795fe4 100755 --- a/new-service +++ b/new-service @@ -1,11 +1,17 @@ #!/bin/zsh -zparseopts -D l=logs -log=logs -enable-log=logs +zparseopts -D l=logs -log=logs -enable-log=logs i:=importenv -import-env:=importenv mkdir $1 ln -s ${XDG_RUNTIME_DIR:-/run/user/$UID}/supervise.$1 $1/supervise -echo '#!/bin/zsh' > $1/run -echo "exec $*" >> $1/run +{ + echo '#!/bin/zsh' + if [[ $importenv ]]; then + echo 'source ${0:a:h:h}/import-env.zsh' + echo "import-env ${importenv[2]}" + fi + echo "exec $*" +} > $1/run chmod +x $1/run if [[ $logs ]]; then