1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/garage_ynh.git synced 2024-09-03 18:36:32 +02:00

Clarify the confusing 'virtualisation' variable thingies ...

This commit is contained in:
Alexandre Aubin 2023-08-21 16:51:34 +02:00
parent 490814db06
commit db6def2d96
8 changed files with 34 additions and 53 deletions

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
if [ "$VIRTUALISATION" = "true" ]
# If we're inside a container
if systemd-detect-virt -c -q
then then
data_dir=__DATA_DIR__ data_dir=__DATA_DIR__
format=$1 format=$1

View file

@ -5,7 +5,7 @@ Wants=network-online.target
[Service] [Service]
User=__APP__ User=__APP__
Environment='RUST_LOG=garage=info' 'VIRTUALISATION=__VIRTUALISATION__' 'RUST_BACKTRACE=1' Environment='RUST_LOG=garage=info' 'VIRTUALISATION=__SYSTEM_IS_INSIDE_CONTAINER__' 'RUST_BACKTRACE=1'
ExecStartPre=+__INSTALL_DIR__/mount_disk.sh ExecStartPre=+__INSTALL_DIR__/mount_disk.sh
ExecStart=__INSTALL_DIR__/garage -c __INSTALL_DIR__/garage.toml server ExecStart=__INSTALL_DIR__/garage -c __INSTALL_DIR__/garage.toml server
ExecStopPost=+__INSTALL_DIR__/umount_disk.sh ExecStopPost=+__INSTALL_DIR__/umount_disk.sh
@ -17,16 +17,16 @@ StandardError=inherit
# Depending on specificities of your service/app, you may need to tweak these # Depending on specificities of your service/app, you may need to tweak these
# .. but this should be a good baseline # .. but this should be a good baseline
# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html # Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
__VIRT_PROTECTION__PrivateTmp=yes __COMMENT_IF_SYSTEM_IS_INSIDE_CONTAINER__PrivateTmp=yes
#PrivateDevices=yes #PrivateDevices=yes
# RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 # RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes RestrictNamespaces=yes
RestrictRealtime=yes RestrictRealtime=yes
#DevicePolicy=closed #DevicePolicy=closed
__VIRT_PROTECTION__ProtectSystem=full __COMMENT_IF_SYSTEM_IS_INSIDE_CONTAINER__ProtectSystem=full
__VIRT_PROTECTION__ProtectControlGroups=yes __COMMENT_IF_SYSTEM_IS_INSIDE_CONTAINER__ProtectControlGroups=yes
#ProtectKernelModules=yes #ProtectKernelModules=yes
__VIRT_PROTECTION__ProtectKernelTunables=yes __COMMENT_IF_SYSTEM_IS_INSIDE_CONTAINER__ProtectKernelTunables=yes
LockPersonality=yes LockPersonality=yes
SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap

View file

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
if [ "$VIRTUALISATION" = "true" ]
# If we're inside a container
if systemd-detect-virt -c -q
then then
data_dir=__DATA_DIR__ data_dir=__DATA_DIR__
nbd=$(cat $data_dir/nbd_index) nbd=$(cat $data_dir/nbd_index)

View file

@ -4,27 +4,22 @@
# COMMON VARIABLES # COMMON VARIABLES
#================================================= #=================================================
GARAGE_VERSION="0.8.2"
if systemd-detect-virt -c -q
then
system_is_inside_container="true"
# used to comment systemd isolation to allow mount disk
comment_if_system_is_inside_container="#"
else
system_is_inside_container="false"
comment_if_system_is_inside_container=""
fi
#================================================= #=================================================
# PERSONAL HELPERS # PERSONAL HELPERS
#================================================= #=================================================
systemd-detect-virt -c -q
if [ $? ]
then #system is inside a container,
export VIRTUALISATION=true
virtualisation=true
# comment systemd isolation to allow mount disk
virt_protection="#"
else
virtualisation=false
export VIRTUALISATION=false
# uncomment systemd isolation
virt_protection=""
fi
GARAGE_VERSION="0.8.2"
garage_connect() { garage_connect() {
local command="$1" local command="$1"
local peer="$2" local peer="$2"

View file

@ -17,7 +17,7 @@ ynh_abort_if_errors
final_path=$(ynh_app_setting_get $app final_path) final_path=$(ynh_app_setting_get $app final_path)
node_id=$(ynh_app_setting_get $app node_id) node_id=$(ynh_app_setting_get $app node_id)
datadir=$(ynh_app_setting_get $app datadir) datadir=$(ynh_app_setting_get $app datadir)
if [ "$virtualisation" = "true" ] if [[ "$system_is_inside_container" == "true" ]]
then then
nbd_index=$(cat $datadir/nbd_index) nbd_index=$(cat $datadir/nbd_index)
fi fi
@ -28,7 +28,7 @@ get__weight() {
} }
set__weight() { set__weight() {
if [ "$virtualisation" = "true" ] if [[ "$system_is_inside_container" == "true" ]]
then then
systemctl stop $app systemctl stop $app
old_weight="$(ynh_app_setting_get --app=$app --key=weight)" old_weight="$(ynh_app_setting_get --app=$app --key=weight)"

View file

@ -66,26 +66,14 @@ chown $app:$app "$install_dir/garage.toml"
#================================================= #=================================================
ynh_script_progression --message="Creating a data directory..." --weight=5 ynh_script_progression --message="Creating a data directory..." --weight=5
if [ "$virtualisation" = "true" ] if [[ "$system_is_inside_container" == "true" ]]
then then
ynh_print_warn --message="This may take time regarding disk size…" ynh_print_warn --message="This may take time regarding disk size…"
fi
#=================================================
# create data partition
#=================================================
if [ "$virtualisation" = "true" ]
then
# to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size. # to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size.
qemu-img create -f qcow2 $data_dir/garage_data.qcow2 "$weight"G qemu-img create -f qcow2 $data_dir/garage_data.qcow2 "$weight"G
VIRTUALISATION=true $install_dir/mount_disk.sh true $install_dir/mount_disk.sh true
fi $install_dir/umount_disk.sh
if [ "$virtualisation" = "true" ]
then
VIRTUALISATION=true $install_dir/umount_disk.sh
fi fi
#================================================= #=================================================

View file

@ -13,11 +13,6 @@ source /usr/share/yunohost/helpers
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
if [ "$virtualisation" = "true" ]
then
export VIRTUALISTATION=true
fi
#================================================= #=================================================
# REMOVE NODE CONFIGURATION # REMOVE NODE CONFIGURATION
#================================================= #=================================================
@ -60,7 +55,7 @@ ynh_script_progression --message="Removing logrotate configuration..." --weight
ynh_remove_logrotate ynh_remove_logrotate
if [ "$virtualisation" = "true" ] if [[ "$system_is_inside_container" == "true" ]]
then then
#================================================= #=================================================
# REMOVE VIRTUAL DISK # REMOVE VIRTUAL DISK

View file

@ -26,9 +26,8 @@ ynh_script_progression --message="Restoring the data directory..." --weight=1
mkdir -p "$data_dir/data" mkdir -p "$data_dir/data"
if [ "$virtualisation" = "true" ] if [[ "$system_is_inside_container" == "true" ]]
then then
export VIRTUALISATION=true
# to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size. # to be sure to not exceed size limit, i use a virtual disk with a fix size to have a max limit size.
qemu-img create -f qcow2 $data_dir/garage_data.qcow2 "$weight"G qemu-img create -f qcow2 $data_dir/garage_data.qcow2 "$weight"G
$install_dir/mount_disk.sh true $install_dir/mount_disk.sh true