diff --git a/conf/systemd.service b/conf/systemd.service new file mode 100755 index 0000000..84256fd --- /dev/null +++ b/conf/systemd.service @@ -0,0 +1,26 @@ +[Unit] +Description=__APP__ social network +After=network.target postgresql.service + +[Service] +User=__APP__ +WorkingDirectory=__FINALPATH__ +Environment="HOME=__FINALPATH__" +ExecStart=/usr/local/bin/mix phx.server +ExecReload=/bin/kill $MAINPID +KillMode=process +Restart=on-failure + +; Some security directives. +; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops. +PrivateTmp=true +; Mount /usr, /boot, and /etc as read-only for processes invoked by this service. +ProtectSystem=full +; Sets up a new /dev mount for the process and only adds API pseudo devices like /dev/null, /dev/zero or /dev/random but not physical devices. Disabled by default because it may not work on devices like the Raspberry Pi. +PrivateDevices=false +; Ensures that the service process and all its children can never gain new privileges through execve(). +NoNewPrivileges=true + +[Install] +WantedBy=multi-user.target + diff --git a/scripts/install b/scripts/install index 5287a3a..37d00a7 100755 --- a/scripts/install +++ b/scripts/install @@ -83,11 +83,14 @@ ynh_app_setting_set "$app" port "$port" #================================================= # Add erlang for Debian Jessie + if [ "$(lsb_release --codename --short)" == "jessie" ]; then echo "deb http://binaries.erlang-solutions.com/debian jessie contrib" | tee /etc/apt/sources.list.d/erlang-solutions.list +elif + [ "$(lsb_release --codename --short)" == "stretch" ]; then + echo "deb http://binaries.erlang-solutions.com/debian stretch contrib" | tee /etc/apt/sources.list.d/erlang-solutions.list fi -echo "deb http://binaries.erlang-solutions.com/debian stretch contrib" | tee /etc/apt/sources.list.d/erlang-solutions.list # install dependencies ynh_install_app_dependencies git build-essential postgresql postgresql-contrib openssl g++ apt-transport-https erlang-inets elixir erlang-dev erlang-parsetools erlang-xmerl erlang-tools @@ -152,7 +155,8 @@ ynh_replace_string "__DB_PWD__" "$db_pwd" "$final_path/config/setu #================================================= # SETUP #================================================= - +( cd $final_path && mix deps.get ) +( cd $final_path && MIX_ENV=prod mix ecto.migrate ) #================================================= # SETUP SSOWAT @@ -172,6 +176,11 @@ fi # Give permisiion to the final_path chown -R "$app":"$app" "$final_path" +# Create a dedicated systemd config +ynh_add_systemd_config +systemctl enable "$app" +systemctl start "$app" + #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/remove b/scripts/remove index a1a5d67..69c46b6 100755 --- a/scripts/remove +++ b/scripts/remove @@ -21,6 +21,22 @@ port=$(ynh_app_setting_get "$app" port) db_name=$(ynh_app_setting_get "$app" psql_db) final_path=$(ynh_app_setting_get "$app" final_path) +# STOP AND REMOVE SERVICE +#================================================= + +# Remove the dedicated systemd config +ynh_remove_systemd_config + +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= + +if yunohost service status | grep -q "$app" +then + echo "Remove $app service" + yunohost service remove "$app" +fi + #================================================= # REMOVE DEPENDENCIES #=================================================