viernes, 12 de marzo de 2021

Ubuntu 20.04 Arancar un script como servicio. Caso particular de tomcat

1. Definir un servicio simple

Se ha consultado a https://linuxconfig.org/how-to-run-script-on-startup-on-ubuntu-20-04-focal-fossa-server-desktop


1.  Ir a /etc/systemd/system

2. Crear el fichero socket-server.service


[Unit]
After=network.service

[Service]
ExecStart=/home/informatica/MyPrograms/SOCKET_SERVER/startup_SocketServer.sh

[Install]
WantedBy=default.target
3. El script a ejecutar (startup_SocksetServer.sh) es

#!/bin/bash

# 1. show all arguments
echo $@

# 2. Mostra directori
myFolder=`dirname "$0"`
echo "The present working directory is $myFolder"



#3. Execute java program
/home/informatica/MyPrograms/jdk-15.0.2/bin/java -jar $myFolder/socketserver.jar S

4. Cambiar permisos

  1. $ sudo chmod 744 /home/informatica/MyPrograms/SOCKET_SERVER/startup_SocketServer.sh
    $ sudo chmod 664 /etc/systemd/system/socket-server.service
5. Arrancar el servicio

  1. $ sudo systemctl daemon-reload
    $ sudo systemctl enable socket-server.service
    






1 comentario :