Add some basic PID management and polish docs
This commit is contained in:
parent
60420623cc
commit
77ece8b2ef
24
README.md
24
README.md
@ -10,7 +10,7 @@ Execute `firestarter` in your `.xinitrc`, ideally by `exec`ing it after performi
|
||||
|
||||
Additionally, you will need to configure Firestarter. See the section below on how to do that.
|
||||
|
||||
Lastly, make sure you're not executing a bunch of stuff from your WM's config. Firestarter will handle the startup of bars, Pulse, etc. by itself. Double-executing will just cause more problems.
|
||||
Lastly, make sure you're not executing a bunch of stuff from your WM's config. That's Firestarter's job; let it do it.
|
||||
|
||||
## Configuration
|
||||
|
||||
@ -24,11 +24,25 @@ command -v openbox
|
||||
openbox
|
||||
```
|
||||
|
||||
Every first uncommented line is a "check" command that must succeed in order for the following "target" line to be executed. Once a target command is selected, parsing stops and the target is executed. When Firestarter is invoked with no arguments, any file with a first line of `#.fsdefaults` is parsed this way.
|
||||
Every first uncommented line is a "check" command that must succeed in order for the following "target" line to be executed. Once a target command is selected, parsing stops and the target is executed. When Firestarter is invoked with no arguments, any file with a first line of `#.fsdefaults` is parsed this way. This allows for quick and easy conditional execution (i.e. to fall back to your second-favorite compositor, or only start an application after it's been configured for the first time).
|
||||
|
||||
Any file that does *not* have the initial "crunchdot" is executed normally. You can keep shell scripts or symlinks in here and they will be executed without issue.
|
||||
|
||||
After all these programs have been started, firestarter executes `~/.firestarterrc` if it exists and then starts XDG autostart applications.
|
||||
After all these programs have been started, Firestarter executes `~/.firestarterrc` if it exists and then starts XDG autostart applications.
|
||||
|
||||
## Usage
|
||||
|
||||
If `firestarter` is invoked without any arguments, it will attempt to start a session. However, there are a series of subcommands you can use to manage your session and configuration:
|
||||
|
||||
* `init`: Starts a new Firestarter session. Firestarter defaults to this action if none is specified.
|
||||
|
||||
* `list`, `ls`: List all configuration files and, if they are fsdefaults files, resolve them. Useful for debugging.
|
||||
|
||||
* `start`: Start a configuration file, redirecting output to the proper logs and dropping its PID in `/run` for existing Firestarter instances to use.
|
||||
|
||||
* `status`, `st`, `stat`: Prints information about the running Firestarter session, including PID, display, and the state of all services.
|
||||
|
||||
* `stop`: Kill Firestarter, if it's running.
|
||||
|
||||
## Logging
|
||||
|
||||
@ -74,11 +88,11 @@ Firestarter, in addition to spawning the programs in the default configs, also i
|
||||
|
||||
* The `wm` config file is special; if it exists and a target can be found for it, firestarter will watch the `_NET_WM_NAME` atom on the root window, waiting for it to initialize before starting XDG autostarts. This prevents applications from being started before the WM is ready to manage them. You can disable this by setting `FS_NOWAITWM`.
|
||||
|
||||
* In addition to this, setting the `FS_DIEONWM` variable makes firestarter automatically end the session if the WM were to die for any reason. This requires that the target not contain any environment variable declarations; `TERMINAL=urxvt i3` would not work. Arguments are okay.
|
||||
* In addition to this, setting the `FS_DIEONWM` variable makes firestarter automatically end the session if the WM were to die for any reason. This requires that the target not contain any environment variable declarations; `TERMINAL=urxvt i3` would not work. Arguments are okay (i.e. `ksmserver -w i3`).
|
||||
|
||||
## Contribution
|
||||
|
||||
Firestarter by no means contains an exhaustive list of all possible programs. If you know of or have created a program that should be added, *please* open an issue about it. The script should be light but its choices massive.
|
||||
There's a very good chance Firestarter doesn't cover all the bases it can. If there's a common session component that you find yourself sourcing in before Firestarter, it might be worth rolling in. File an issue if that's the case.
|
||||
|
||||
Bug reports are also more than welcome.
|
||||
|
||||
|
23
firestarter
23
firestarter
@ -14,7 +14,7 @@ declare -r _sessionid="$(< /proc/self/sessionid)"
|
||||
# Options
|
||||
declare _optconfigdir="${XDG_CONFIG_HOME:-$HOME/.config}/$_name"
|
||||
declare _optdatadir="${XDG_DATA_HOME:-$HOME/.local/share}/$_name"
|
||||
declare _optrundir="${XDG_RUNTIME_DIR:-/run/user/$UID}/$_name"
|
||||
declare _optrundir="${XDG_RUNTIME_DIR:-/run/user/$UID}/$_name/$DISPLAY"
|
||||
declare _optlogdir="$_optdatadir/logs"
|
||||
declare _optdryrun
|
||||
declare -i _opthelp
|
||||
@ -110,6 +110,7 @@ gettarget() {
|
||||
fsexec() {
|
||||
# Execute an fsdefaults file
|
||||
[ -z "$1" ] && return 1
|
||||
local pid
|
||||
local file="$1"
|
||||
local filename="$(basename -- "$file")"
|
||||
local logfile="$_optlogdir/$filename.log"
|
||||
@ -125,15 +126,21 @@ fsexec() {
|
||||
mv "$logfile" "$logfile.old"
|
||||
fi
|
||||
bash -c "$target" > "$logfile" 2>&1 &
|
||||
pid="$!"
|
||||
elif [ $? = 50 ] && [ -x "$file" ]; then
|
||||
# It's a shell script or executable symlink
|
||||
log "File is an executable" 2
|
||||
log "Executing file: \"$filename\""
|
||||
[ -n "$_optdryrun" ] && return
|
||||
"$file" > "$logfile" 2>&1 &
|
||||
pid="$!"
|
||||
else
|
||||
warn "Could not execute target: \"$filename\""
|
||||
fi
|
||||
if [ -n "$pid" ]; then
|
||||
[ -d "$_optrundir" ] || error "Run directory does not exist: $_optrundir"
|
||||
printf "$pid" > "$_optrundir/$filename.pid"
|
||||
fi
|
||||
}
|
||||
fslist() {
|
||||
# List all valid services and what they point to
|
||||
@ -396,7 +403,10 @@ step_wait() {
|
||||
}
|
||||
step_logout() {
|
||||
log "Logging out"
|
||||
if has loginctl; then
|
||||
if [ -n "$_optrundir" ] && [ -d "$_optrundir" ]; then
|
||||
rm -rf "$_optrundir"
|
||||
fi
|
||||
if has loginctl && [ -z "$FS_NOLOGINCTL" ]; then
|
||||
# Use loginctl if possible
|
||||
if [ -n "$_sessionid" ]; then
|
||||
loginctl terminate-session "$_sessionid"
|
||||
@ -429,6 +439,7 @@ provided
|
||||
Environment Variables:
|
||||
|
||||
FS_DIEONWM If nonempty, end the session when the WM dies.
|
||||
FS_NOLOGINCTL Don't invoke loginctl to end the session. Good for testing.
|
||||
FS_NOWAITWM If nonempty, skip waiting for the WM to initialize
|
||||
|
||||
Copyright (c) 2019 rehashedsalt@cock.li
|
||||
@ -458,6 +469,14 @@ firestart() {
|
||||
st|stat|status)
|
||||
fsstatus
|
||||
;;
|
||||
stop)
|
||||
if [ -n "$FIRESTARTER" ] && [ -d "/proc/$FIRESTARTER" ] && [ "$FIRESTARTER" -gt 0 ] 2> /dev/null; then
|
||||
log "Killing PID $FIRESTARTER"
|
||||
kill $FIRESTARTER
|
||||
else
|
||||
error "\$FIRESTARTER is unset or references a dead process" 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
error "Unknown action: $action" 51
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user