fix runit install

This commit is contained in:
Yann Autissier
2022-06-22 10:02:09 +02:00
parent 14a4f86524
commit a75d5b4645
33 changed files with 200 additions and 71 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
# target ansible: Fire docker-build-ansible, Call ansible ANSIBLE_ARGS ARGS or ansible-run target
.PHONY: ansible
ansible: $(if $(DOCKER_RUN),docker-build-ansible,install-ansible)
ansible: $(if $(ANSIBLE_DOCKER_RUN),docker-build-ansible,install-ansible)
$(call ansible,$(ANSIBLE_ARGS) $(ARGS))
# target ansible-playbook: Call ansible-playbook ANSIBLE_ARGS ARGS
.PHONY: ansible-playbook
ansible-playbook: $(if $(DOCKER_RUN),docker-build-ansible,install-ansible)
ansible-playbook: $(if $(ANSIBLE_DOCKER_RUN),docker-build-ansible,install-ansible)
$(call ansible-playbook,$(ANSIBLE_ARGS) $(ARGS))
# target ansible-pull: Call ansible-pull ANSIBLE_GIT_REPOSITORY ANSIBLE_PLAYBOOK
@@ -24,7 +24,7 @@ ansible-run: ansible-run-localhost
# target ansible-run-%: Fire docker-build-ansible, Call ansible-playbook ANSIBLE_PLAYBOOK
.PHONY: ansible-run-%
ansible-run-%: $(if $(DOCKER_RUN),docker-build-ansible,install-ansible)
ansible-run-%: $(if $(ANSIBLE_DOCKER_RUN),docker-build-ansible,install-ansible)
$(call ansible-playbook,$(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) $(if $(ANSIBLE_EXTRA_VARS),--extra-vars '$(patsubst target=localhost,target=$*,$(ANSIBLE_EXTRA_VARS))') $(if $(findstring true,$(DRYRUN)),--check) $(if $(ANSIBLE_INVENTORY),--inventory $(ANSIBLE_INVENTORY)) $(ANSIBLE_PLAYBOOK))
# target ansible-tests: Fire ssh-add ansible-tests-localhost
+11 -7
View File
@@ -1,3 +1,4 @@
ANSIBLE_APP_NAME ?= myos
ANSIBLE_APP_TYPE ?= myos
ANSIBLE_ARGS ?= $(if $(filter-out 0,$(UID)),$(if $(shell sudo -l 2>/dev/null |grep 'NOPASSWD: ALL'),,--ask-become-pass))$(if $(DOCKER_RUN),$(if $(shell ssh-add -l >/dev/null 2>&1 || echo false), --ask-pass))
ANSIBLE_AWS_ACCESS_KEY_ID ?= $(AWS_ACCESS_KEY_ID)
@@ -8,6 +9,10 @@ ANSIBLE_CONFIG ?= ansible/ansible.cfg
ANSIBLE_DISKS_NFS_DISK ?= $(NFS_DISK)
ANSIBLE_DISKS_NFS_OPTIONS ?= $(NFS_OPTIONS)
ANSIBLE_DISKS_NFS_PATH ?= $(NFS_PATH)
# running ansible in docker requires sshd running on localhost,
# to allow ansible to escape docker and apply changes to localhost
ANSIBLE_DOCKER ?= false
ANSIBLE_DOCKER_RUN ?= $(if $(filter-out false False FALSE,$(ANSIBLE_DOCKER)),$(ANSIBLE_DOCKER))
ANSIBLE_DOCKER_IMAGE_TAG ?= $(DOCKER_IMAGE_TAG)
ANSIBLE_DOCKER_REGISTRY ?= $(DOCKER_REGISTRY)
ANSIBLE_EXTRA_VARS ?= target=localhost
@@ -29,28 +34,27 @@ ANSIBLE_SERVER_NAME ?= $(SERVER_NAME)
ANSIBLE_USERNAME ?= $(USER)
ANSIBLE_VERBOSE ?= $(if $(DEBUG),-vvvv,$(if $(VERBOSE),-v))
CMDS += ansible ansible-playbook
DOCKER_RUN_OPTIONS += $(if $(DOCKER_INTERNAL_DOCKER_HOST),--add-host=host.docker.internal:$(DOCKER_INTERNAL_DOCKER_HOST))
ENV_VARS += ANSIBLE_APP_TYPE ANSIBLE_AWS_ACCESS_KEY_ID ANSIBLE_AWS_DEFAULT_OUTPUT ANSIBLE_AWS_DEFAULT_REGION ANSIBLE_AWS_SECRET_ACCESS_KEY ANSIBLE_CONFIG ANSIBLE_DISKS_NFS_DISK ANSIBLE_DISKS_NFS_OPTIONS ANSIBLE_DISKS_NFS_PATH ANSIBLE_DOCKER_IMAGE_TAG ANSIBLE_DOCKER_REGISTRY ANSIBLE_EXTRA_VARS ANSIBLE_GIT_DIRECTORY ANSIBLE_GIT_KEY_FILE ANSIBLE_GIT_REPOSITORY ANSIBLE_GIT_VERSION ANSIBLE_INVENTORY ANSIBLE_MYOS ANSIBLE_PLAYBOOK ANSIBLE_SSH_AUTHORIZED_KEYS ANSIBLE_SSH_BASTION_HOSTNAME ANSIBLE_SSH_BASTION_USERNAME ANSIBLE_SSH_PRIVATE_IP_RANGE ANSIBLE_SSH_PRIVATE_KEYS ANSIBLE_SSH_PUBLIC_HOSTS ANSIBLE_SSH_USERNAME ANSIBLE_USERNAME ANSIBLE_VERBOSE
DOCKER_RUN_OPTIONS_ANSIBLE ?= -it $(if $(DOCKER_INTERNAL_DOCKER_HOST),--add-host=host.docker.internal:$(DOCKER_INTERNAL_DOCKER_HOST))
ENV_VARS += ANSIBLE_APP_NAME ANSIBLE_APP_TYPE ANSIBLE_AWS_ACCESS_KEY_ID ANSIBLE_AWS_DEFAULT_OUTPUT ANSIBLE_AWS_DEFAULT_REGION ANSIBLE_AWS_SECRET_ACCESS_KEY ANSIBLE_CONFIG ANSIBLE_DISKS_NFS_DISK ANSIBLE_DISKS_NFS_OPTIONS ANSIBLE_DISKS_NFS_PATH ANSIBLE_DOCKER_IMAGE_TAG ANSIBLE_DOCKER_REGISTRY ANSIBLE_EXTRA_VARS ANSIBLE_GIT_DIRECTORY ANSIBLE_GIT_KEY_FILE ANSIBLE_GIT_REPOSITORY ANSIBLE_GIT_VERSION ANSIBLE_INVENTORY ANSIBLE_MYOS ANSIBLE_PLAYBOOK ANSIBLE_SSH_AUTHORIZED_KEYS ANSIBLE_SSH_BASTION_HOSTNAME ANSIBLE_SSH_BASTION_USERNAME ANSIBLE_SSH_PRIVATE_IP_RANGE ANSIBLE_SSH_PRIVATE_KEYS ANSIBLE_SSH_PUBLIC_HOSTS ANSIBLE_SSH_USERNAME ANSIBLE_USERNAME ANSIBLE_VERBOSE
# function ansible: Call run ansible ANSIBLE_ARGS with arg 1
define ansible
$(call INFO,ansible,$(1))
$(RUN) $(call run,ansible $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),$(DOCKER_REPOSITORY)/)
$(RUN) $(call $(if $(ANSIBLE_DOCKER_RUN),run,env-run),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(ANSIBLE_DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),$(DOCKER_RUN_OPTIONS_ANSIBLE) $(DOCKER_REPOSITORY)/)
endef
# function ansible-playbook: Call run ansible-playbook ANSIBLE_ARGS with arg 1
define ansible-playbook
$(call INFO,ansible-playbook,$(1))
$(RUN) $(call run,ansible$(if $(DOCKER_RUN),,-playbook) $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),--entrypoint=ansible-playbook $(DOCKER_REPOSITORY)/)
$(RUN) $(call $(if $(ANSIBLE_DOCKER_RUN),run,env-run),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible$(if $(ANSIBLE_DOCKER_RUN),,-playbook) $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(ANSIBLE_DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),$(DOCKER_RUN_OPTIONS_ANSIBLE) --entrypoint=ansible-playbook $(DOCKER_REPOSITORY)/)
endef
# function ansible-pull: Call run ansible-pull ANSIBLE_ARGS with arg 1
## TODO: run ansible in docker and target localhost outside docker when DOCKER=true
define ansible-pull
$(call INFO,ansible-pull,$(1))
$(call env-run,$(RUN) ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1))
$(call $(if $(ANSIBLE_DOCKER_RUN),run,env-run),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1))
endef
# function ansible-user-add-groups: Call ansible to add user 1 in groups 2
define ansible-user-add-groups
$(call INFO,ansible-user-add-groups,$(1)$(comma) $(2))
$(if $(DOCKER_RUN),$(call make,docker-build-ansible),$(call make,install-ansible))
$(if $(ANSIBLE_DOCKER_RUN),$(call make,docker-build-ansible),$(call make,install-ansible))
$(call ansible,-b -m user -a 'name=$(1) groups=$(2) append=yes' localhost)
endef
+5
View File
@@ -27,5 +27,10 @@
name: "{{item.name}}"
state: "{{item.state}}"
enabled: "{{item.enabled}}"
runlevels:
- 2
- 3
- 4
- 5
become: yes
+8 -2
View File
@@ -24,10 +24,16 @@ docker_daemon_config_directory: '/etc/docker'
docker_daemon_config_file: "{{docker_daemon_config_directory}}/daemon.json"
```
* `docker_daemon_config_file` - Docker daemon configuration file
* `docker_daemon_config_data_root` - Docker daemon data root directory
``` yaml
docker_daemon_config_storage: 'overlay2'
docker_daemon_config_data_root: '/var/lib/docker'
```
* `docker_daemon_config_storage_driver` - Docker daemon storage driver
``` yaml
docker_daemon_config_storage_driver: 'overlay2'
```
* `docker_daemon_config` - docker daemon yaml config
+7 -4
View File
@@ -5,16 +5,19 @@
docker_check_kernel: '3.10'
# location of configuration files of docker daemon
docker_daemon_config_directory: "/etc/docker"
# docker_daemon_config_directory: "/etc/docker"
# configuration files of docker daemon
docker_daemon_config_file: "{{docker_daemon_config_directory}}/daemon.json"
# docker_daemon_config_file: "{{docker_daemon_config_directory}}/daemon.json"
# configure docker daemon data root directory
# docker_daemon_config_data_root: "/var/lib/docker"
# configure docker daemon storage driver
docker_daemon_config_storage: "overlay2"
# docker_daemon_config_storage: "overlay2"
# docker daemon configuration
docker_daemon_config: {}
# docker_daemon_config: {}
# docker package name
docker_package: docker
+19 -19
View File
@@ -1,27 +1,27 @@
---
# file: tasks/config.yml
- name: config - add docker storage setup
when: docker_package|length > 0 and ansible_service_mgr == "systemd" and ansible_os_family|lower == "redhat"
lineinfile: dest="{{docker_init_config_directory}}/{{docker_package}}-storage-setup" state="present" line="STORAGE_DRIVER=\"\""
become: yes
notify: restart docker
# - name: config - add docker storage setup
# when: docker_package|length > 0 and ansible_service_mgr == "systemd" and ansible_os_family|lower == "redhat"
# lineinfile: dest="{{docker_init_config_directory}}/{{docker_package}}-storage-setup" state="present" line="STORAGE_DRIVER=\"\""
# become: yes
# notify: restart docker
- name: config - register docker_daemon_config
set_fact:
docker_daemon_config: "{{ lookup('file',docker_daemon_config_file)|default('{}')|from_json}}"
ignore_errors: true
# - name: config - register docker_daemon_config
# set_fact:
# docker_daemon_config: "{{ lookup('file',docker_daemon_config_file)|default('{}')|from_json}}"
# ignore_errors: true
- name: config - add docker daemon storage configuration
when: docker_package|length > 0
template:
src: daemon.json.j2
dest: "{{docker_daemon_config_file}}"
owner: root
group: docker
mode: "0640"
become: yes
notify: restart docker
# - name: config - add docker daemon storage configuration
# when: docker_package|length > 0
# template:
# src: daemon.json.j2
# dest: "{{docker_daemon_config_file}}"
# owner: root
# group: docker
# mode: "0640"
# become: yes
# notify: restart docker
# - name: config - disable docker iptables setup
# when: docker_package|length > 0 and ansible_service_mgr == "systemd"
+5
View File
@@ -33,6 +33,11 @@
name: "{{item.name}}"
state: "{{item.state}}"
enabled: "{{item.enabled}}"
runlevels:
- 2
- 3
- 4
- 5
become: yes
- name: services - force service restart - openrc
+1
View File
@@ -105,6 +105,7 @@ hosts_packages_distro: []
# services to enable/disable
hosts_services:
- { "name": "ansible", "state": "stopped", "enabled": "no" }
- { "name": "myos", "state": "stopped", "enabled": "no" }
- { "name": "zram", "state": "stopped", "enabled": "no" }
# list of urls to get public keys to add to ~/.ssh/authorized_keys
+2 -2
View File
@@ -1,8 +1,6 @@
# shellcheck shell=bash source=/dev/null
# ~/.bash_profile: executed by the command interpreter for bash login shell.
[ -f ~/.sh_profile ] && . ~/.sh_profile
# bash-completion
if ! shopt -oq posix && [ -z "${BASH_COMPLETION_VERSINFO-}" ]; then
if [ "${BASH_VERSINFO[0]}" -gt 4 ] \
@@ -17,3 +15,5 @@ if ! shopt -oq posix && [ -z "${BASH_COMPLETION_VERSINFO-}" ]; then
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
fi
fi
[ -f ~/.sh_profile ] && . ~/.sh_profile
+2 -1
View File
@@ -1,6 +1,5 @@
# shellcheck shell=sh source=/dev/null
# ~/.sh_profile: executed by the command interpreter for login shells.
# set -x
# source ~/.*aliases and ~/.*functions files
for source in aliases functions; do
@@ -36,3 +35,5 @@ for path in /*/local/sbin /*/local/bin /*/local/*/bin "${HOME}"/.*/bin; do
*) export PATH="${path}:$PATH" ;;
esac
done
[ -f ~/.profile ] && . ~/.profile
+42 -2
View File
@@ -9,11 +9,51 @@
# Description: MYOS system calls
### END INIT INFO
NAME="$(basename "$0")"
# check system config
[ -r /etc/default/myos ] && . /etc/default/myos 2>/dev/null
type make >/dev/null 2>&1 && [ -d "${MYOS}" ] || exit 1
type make >/dev/null 2>&1 && [ -d "${MYOS}" ] && cd "${MYOS}" || exit 1
case "$1" in
force-stop)
HOOK="stop stack-node-stop"
shift
;;
force-reload)
HOOK="recreate stack-node-recreate"
shift
;;
force-restart)
HOOK="restart stack-node-restart"
shift
;;
force-shutdown)
HOOK="down stack-node-down"
shift
;;
reload)
HOOK="recreate"
shift
;;
shutdown)
HOOK="down"
shift
;;
start)
echo "Starting $NAME..."
HOOK="up"
shift
;;
status)
HOOK="ps"
shift
;;
stop)
echo "Stopping $NAME..."
;;
*)
IFS=$'\n'; cd "${MYOS}"; exec env $(cat /etc/default/myos ~/.myos 2>/dev/null) make "$@"
;;
esac
IFS=$'\n'; exec env $(cat /etc/default/myos ~/.myos 2>/dev/null) make ${HOOK:-} "${@}"
@@ -10,7 +10,7 @@ start() {
}
status() {
/etc/init.d/myos ps
/etc/init.d/myos status
}
stop() {
@@ -9,10 +9,10 @@ start() {
/etc/init.d/zram start
}
stop() {
/etc/init.d/zram stop
}
status() {
/etc/init.d/zram status
}
stop() {
/etc/init.d/zram stop
}
@@ -2,7 +2,7 @@
# file rc_functions.sh: Define shell functions
## author: Yann "aya" Autissier
## license: GPL
## version: 20210714
## version: 20220620
# function force: Run a command sine die
force() {
@@ -135,8 +135,8 @@ ps1_set() {
fi
)"
PS1_GIT="${COLOR_CYAN}${PS1_GIT}${COLOR_RESET}"
PS1_HOSTNAME_COLOR="\`case \"\${ENV}\" in
[Pp][Rr][0Oo][Dd]*)
PS1_HOSTNAME_COLOR="\`case \"\${ENV}${HOSTNAME%%.*}\" in
*[Pp][Rr][0Oo][Dd]*|*[Pp][Rr][Dd]*)
printf \"${COLOR_RED}\";;
*)
if [ -n \"\${ENV}\" ]; then
+13
View File
@@ -0,0 +1,13 @@
#!/bin/sh
set -e
NAME="$(basename "$(pwd)")"
[ "$1" = -1 ] && echo "ERROR: unexpected error"
[ "$1" = 1 ] && echo "ERROR: $NAME config error" \
&& sv d "$NAME" && exit 0
[ "$1" = 2 ] && echo "ERROR: $NAME exit error" \
&& sv d "$NAME" && exit 0
exec /etc/init.d/"$NAME" stop 2>&1
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
set -e
NAME="$(basename "$(dirname "$(pwd)")")"
LOG_DIR="/var/log/runit/$NAME"
LOG_GROUP=adm
LOG_USER=nobody
SUPERVISE_DIR="/var/run/runit/supervise/${NAME}.log"
mkdir -p "$SUPERVISE_DIR" && chmod 700 "$SUPERVISE_DIR"
[ ! -h supervise ] && rm -rf supervise && ln -s "$SUPERVISE_DIR" supervise
mkdir -p "$LOG_DIR" && chmod 750 "$LOG_DIR"
chown -R "$LOG_USER":"$LOG_GROUP" "$LOG_DIR"
exec chpst -u "$LOG_USER" svlogd -tt "$LOG_DIR"
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env /lib/runit/invoke-run
# shellcheck shell=sh
set -e
NAME="$(basename "$(dirname "$0")")"
SUPERVISE_DIR="/var/run/runit/supervise/$NAME"
mkdir -p "$SUPERVISE_DIR" && chmod 700 "$SUPERVISE_DIR"
[ ! -h supervise ] && rm -rf supervise && ln -s "$SUPERVISE_DIR" supervise
sv once "$NAME"
exec /etc/init.d/"$NAME" start 2>&1
+1
View File
@@ -3,6 +3,7 @@
- name: config - set MYOS config in /etc/default/myos
with_items:
- APP_NAME={{ lookup('env','ANSIBLE_APP_NAME') }}
- APP_TYPE={{ lookup('env','ANSIBLE_APP_TYPE') }}
- MYOS={{ lookup('env','ANSIBLE_MYOS') }}
lineinfile:
+5
View File
@@ -27,5 +27,10 @@
name: "{{item.name}}"
state: "{{item.state}}"
enabled: "{{item.enabled}}"
runlevels:
- 2
- 3
- 4
- 5
become: yes
-5
View File
@@ -46,11 +46,6 @@
- unset user_count process_count
lineinfile: dest=~/.bashrc create=yes line='{{item}}'
- name: user - update ~/.profile
with_items:
- source ~/.sh_profile
lineinfile: dest=~/.profile create=yes line='{{item}}'
- name: user - update ~/.config/git/ignore
with_items:
- '.nfs*'
+5
View File
@@ -27,5 +27,10 @@
name: "{{item.name}}"
state: "{{item.state}}"
enabled: "{{item.enabled}}"
runlevels:
- 2
- 3
- 4
- 5
become: yes