1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/simplex_ynh.git synced 2024-09-03 20:26:28 +02:00
This commit is contained in:
Éric Gaspar 2023-05-23 16:39:02 +02:00
parent e4b25e0dca
commit 5b8bf094ed
6 changed files with 67 additions and 0 deletions

50
conf/xftp.systemd.service Normal file
View file

@ -0,0 +1,50 @@
[Unit]
Description=SimpleX: Messaging Protocol Server
After=network.target
[Service]
Type=simple
User=__APP__
Group=__APP__
WorkingDirectory=__INSTALL_DIR__/
ExecStart=__INSTALL_DIR__/xftp-server start
Restart=always
RestartSec=3
KillSignal=SIGINT
# Sandboxing options to harden security
# Depending on specificities of your service/app, you may need to tweak these
# .. but this should be a good baseline
# Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
RestrictNamespaces=yes
RestrictRealtime=yes
DevicePolicy=closed
ProtectClock=yes
ProtectHostname=yes
ProtectProc=invisible
ProtectSystem=full
ProtectControlGroups=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
LockPersonality=yes
SystemCallArchitectures=native
SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap @cpu-emulation @privileged
# Denying access to capabilities that should not be relevant for webapps
# Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
[Install]
WantedBy=multi-user.target

View file

@ -28,6 +28,7 @@ ynh_backup --src_path="/etc/opt/simplex"
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/xftp.service"
#=================================================
# END OF SCRIPT

View file

@ -16,10 +16,12 @@ ynh_script_progression --message="Setting up source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --dest_dir="$install_dir" --source_id="xftp"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
chmod +x $install_dir/smp-server
chmod +x $install_dir/xftp-server
#=================================================
# SPECIFIC SETUP
@ -29,6 +31,7 @@ pushd "$install_dir"
public_ip4="$(curl -s ip.yunohost.org)" || true
ynh_app_setting_set --app=$app --key=public_ip4 --value=$public_ip4
./smp-server init --no-password --ip $public_ip4 -y
./ftp-server init -l -p /srv/xftp "$@"
popd
fingerprint=$(cat /etc/opt/simplex/fingerprint)
@ -43,6 +46,7 @@ ynh_script_progression --message="Adding system configurations related to $app..
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_add_systemd_config --service=xftp --template=../conf/xftp.systemd.service
yunohost service add $app --description="Messaging platform" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
@ -53,6 +57,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name="xftp" --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# END OF SCRIPT

View file

@ -20,6 +20,7 @@ if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
yunohost service remove xftp
fi
#=================================================

View file

@ -32,8 +32,11 @@ chown -R $app:$app "/etc/opt/simplex"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
ynh_restore_file --origin_path="/etc/systemd/system/xftp.service"
systemctl enable xftp.service --quiet
yunohost service add $app --description="Messaging platform" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
yunohost service add xftp --description="Messaging platform" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
#=================================================
# START SYSTEMD SERVICE
@ -41,6 +44,7 @@ yunohost service add $app --description="Messaging platform" --log="/var/log/$ap
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=xftp --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# END OF SCRIPT

View file

@ -32,6 +32,7 @@ ynh_app_setting_set --app=$app --key=fingerprint --value=$fingerprint
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=xftp --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -43,11 +44,13 @@ then
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
ynh_setup_source --dest_dir="$install_dir" --source_id="xftp"
fi
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
chmod +x $install_dir/smp-server
chmod +x $install_dir/xftp-server
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
@ -56,8 +59,10 @@ ynh_script_progression --message="Upgrading system configurations related to $ap
# Create a dedicated systemd config
ynh_add_systemd_config
ynh_add_systemd_config --service=xftp --template=../conf/xftp.systemd.service
yunohost service add $app --description="Messaging platform" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
yunohost service add xftp --description="Messaging platform" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port"
#=================================================
# START SYSTEMD SERVICE
@ -65,6 +70,7 @@ yunohost service add $app --description="Messaging platform" --log="/var/log/$ap
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=xftp --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# END OF SCRIPT