Skip to content

Commit

Permalink
feat(native): add support for system services for systemd
Browse files Browse the repository at this point in the history
Allow installing Veraison services into the system services manager
under systemd using -s option (the default is to use the user service
manager).

Signed-off-by: Sergei Trofimov <[email protected]>
  • Loading branch information
setrofim committed Sep 17, 2024
1 parent 5f785b5 commit 5bda697
Showing 1 changed file with 65 additions and 29 deletions.
94 changes: 65 additions & 29 deletions deployments/native/bin/veraison
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ function help() {
-C disable color output
-f force overwriting of existing files
-i save intermediate artifacts
-s install service units into the system, rather than user, service manager.
(on Linux only; on MacOSX, services will always be installed for the user.)
Some options only apply to certain commands; if an option is applicable to a
command, it will be listed for that command alongside its name and arguments.
Expand Down Expand Up @@ -557,37 +559,39 @@ function help() {
SYSTEMD/LAUNCHD EXECUTION COMMANDS:
(note: these commands will only work on OS's that use systemd or launchd for
service management. Currently only user services, i.e. via systemctl --user and
non-root invocations of launchd, are supported.)
service management. By default, user services, i.e. via systemctl --user and
non-root invocations of launchd, will be created. For systemd (on Linux distros),
-s option may be used to create system services instead. Only user services are
currently supported for launchd (MacOSX).)
enable-services
[-s] enable-services
Enable the systemd/launchd units for veraison services for the current
use. This merely adds veraison services to the (current user's) systemd
services; this does not start them.
use. This merely adds veraison services to the (current user's, or with -s,
system's) systemd services; this does not start them.
disable-services
[-s] disable-services
Disable the previously-enabled systemd/launchd units for Veraison services.
start [SERVICE]
Start Veraison service specified by SERVICE via (user) systemd/launchd. If
SERVICE is not specified, start all Veraison services. This also enables
Veraison services (as with enable-services command above) if they have not
already been enabled.
[-s] start [SERVICE]
Start Veraison service specified by SERVICE via systemd/launchd. If SERVICE
is not specified, start all Veraison services. This also enables Veraison
services (as with enable-services command above) if they have not already been
enabled.
stop [SERVICE]
Stop Veraison service specified by SERVICE via (user) systemd/launchd. If
SERVICE is not specified, stop all Veraison services.
[-s] stop [SERVICE]
Stop Veraison service specified by SERVICE via systemd/launchd. If SERVICE is
not specified, stop all Veraison services.
status [SERVICE]
[-s] status [SERVICE]
Show the status of the systemd/launchd unit specified by SERVICE (similar
to running "systemctl --user status" or "launchctl print
<service-target>"). If SERVICE is not specified, show summary one line
status for each services' units (systemd), or the details for each service
(launchd).
follow SERVICE
Follow STDOUT of the specified (user) systemd SERVICE (similar to running
"journalctl --user --follow").
[-s] follow SERVICE
Follow STDOUT of the specified systemd SERVICE (similar to running
"journalctl [--user] --follow").
Note: As all execution methods utilize the deployment's config (such as ports), only
one method can be use used to run the services at a time (i.e. its not possible
Expand Down Expand Up @@ -780,6 +784,7 @@ function _get_terminal() {
_force=false
_color=true
_save_intermediate=false
_system=false

_purp=''
_red=''
Expand Down Expand Up @@ -817,12 +822,13 @@ function _reset_colors() {

OPTIND=1

while getopts "hCif" opt; do
while getopts "hCifs" opt; do
case "$opt" in
h) help; exit 0;;
C) _color=false;;
i) _save_intermediate=true;;
f) _force=true;;
s) _system=true;;
*) break;;
esac
done
Expand Down Expand Up @@ -869,20 +875,35 @@ case $command in
kill_tmux_session "$1"
;;
enable-services)
_mode=user
if [[ $_system == true ]]; then
_mode=system
fi

case $_os in
Darwin) enable_launchd_services;;
Linux) enable_systemd_services user;;
Linux) enable_systemd_services $_mode;;
esac
;;
disable-services)
_mode=user
if [[ $_system == true ]]; then
_mode=system
fi

case $_os in
Darwin) disable_launchd_services;;
Linux) disable_systemd_services user;;
Linux) disable_systemd_services $_mode;;
esac
;;
start-services | start)
_what=$1

_mode=user
if [[ $_system == true ]]; then
_mode=system
fi

case $_os in
Darwin)
enable_launchd_services
Expand All @@ -894,19 +915,24 @@ case $command in
fi
;;
Linux)
enable_systemd_services user
enable_systemd_services $_mode

if [[ $_what == "" ]]; then
start_systemd_services user
start_systemd_services $_mode
else
control_systemd_service user start $_what
control_systemd_service $_mode start $_what
fi
;;
esac
;;
stop-services | stop)
_what=$1

_mode=user
if [[ $_system == true ]]; then
_mode=system
fi

case $_os in
Darwin)
if [[ $_what == "" ]]; then
Expand All @@ -917,35 +943,45 @@ case $command in
;;
Linux)
if [[ $_what == "" ]]; then
stop_systemd_services user
stop_systemd_services $_mode
else
control_systemd_service user stop $_what
control_systemd_service $_mode stop $_what
fi
;;
esac
;;
status)
_what=$1

_mode=user
if [[ $_system == true ]]; then
_mode=system
fi

case $_os in
Darwin)
show_launchd_service_status $_what
;;
Linux)
if [[ $_what == "" ]]; then
show_systemd_service_status user
show_systemd_service_status $_mode
else
control_systemd_service user status $_what
control_systemd_service $_mode status $_what
fi
;;
esac
;;
follow)
_what=$1

_mode=user
if [[ $_system == true ]]; then
_mode=system
fi

case $_os in
Darwin) follow_launchd_service $_what;;
Linux) follow_systemd_service user $_what;;
Linux) follow_systemd_service $_mode $_what;;
esac
;;
stores | show-stores | check-stores)
Expand Down

0 comments on commit 5bda697

Please sign in to comment.