Uso esto en repositorios git para facilitar el proceso de despliegue
a-simple-systemd-service-autoinstall-script.sh
#!/bin/bash
# Este script instala y habilita/inicia un servicio systemd
# También instala el archivo de servicio
export NAME=MyService
cat >/etc/systemd/system/${NAME}.service <<EOF
# TODO Copia y pega el archivo .service de systemd aquí
EOF
# Habilitar e iniciar servicio
systemctl enable --now ${NAME}.serviceEl siguiente ejemplo instala automáticamente un .service de systemd para docker-compose:
a-simple-systemd-service-autoinstall-script-2.sh
#!/bin/bash
# Este script instala y habilita/inicia un servicio systemd
# También instala el archivo de servicio
export NAME=MyService
cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
Requires=docker.service
After=docker.service
[Service]
Restart=always
User=root
Group=docker
WorkingDirectory=$(pwd)
# Apagar contenedor (si está corriendo) antes de que la unidad esté siendo iniciada
ExecStartPre=$(which docker-compose) -f docker-compose.yml down
# Iniciar contenedor cuando la unidad es iniciada
ExecStart=$(which docker-compose) -f docker-compose.yml up
# Detener contenedor cuando la unidad es detenida
ExecStop=$(which docker-compose) -f docker-compose.yml down
[Install]
WantedBy=multi-user.target
EOF
# Habilitar e iniciar servicio
systemctl enable --now ${NAME}.serviceSi este artículo te ha ayudado, considera invitarme a un café o hacer una donación vía PayPal para apoyar la investigación y publicación de nuevos artículos en TechOverflow