Acabo de crear un servicio de systemd para que el sistema de ventas SPOS3 se inicie automáticamente al iniciar el servidor. Esto fue a pedido de un cliente y aquí te comparto cómo lo he hecho.
La forma más recomendable es usar systemd con systemctl para crear el propio servicio del sistema.
Creando servicio
Antes de crear el servicio debes conocer la ruta absoluta del ejecutable, su working directory y la ubicación del log.
Luego crea el servicio creando un nuevo archivo en /etc/systemd/system/
. Yo lo he llamado spos3.service así que su ubicación completa es
/etc/systemd/system/spos3.service
y se ve así:
[Unit]
Description=Sistema de ventas by parzibyte
After=network.target
[Service]
Type=simple
ExecStart=/home/parzibyte/proyectos_go/api/tiendas
StandardOutput=append:/home/parzibyte/log_itsolutions.log
StandardError=append:/home/parzibyte/log_itsolutions.log
WorkingDirectory=/home/parzibyte/proyectos_go/api/
Restart=always
User=parzibyte
[Install]
WantedBy=multi-user.target
La ruta absoluta del compilado es /home/parzibyte/proyectos_go/api/tiendas
, es decir, el ejecutable se llama tiendas
. Y
quiero que su log se encuentre en /home/parzibyte/log_itsolutions.log
.
Eso solo habrá creado el servicio. Falta habilitarlo e iniciarlo
Instalamos el servicio con sudo systemctl enable spos3
. Esto solo se hace una vez. Si quisieras deshabilitarlo harías un sudo systemctl disable spos3
.
Ya con esto se iniciaría automáticamente en el siguiente reinicio, pero hasta este momento todavía no se ha iniciado.
Para iniciarlo manualmente usa sudo systemctl start spos3
y (cuando sea necesario) puedes detenerlo con sudo systemctl stop spos3
.
Con esto el sistema de ventas se va a estar iniciando cuando el servidor se reinicie.
Podemos ver el estado con sudo systemctl status spos3
y su log con sudo journalctl -u spos3
Salida del estado del servicio:
sudo systemctl status spos3
● spos3.service - Sistema de ventas by parzibyte
Loaded: loaded (/etc/systemd/system/spos3.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2025-08-07 12:16:28 CST; 2min 29s ago
Main PID: 651 (tiendas)
Tasks: 5 (limit: 498)
Memory: 13.4M
CPU: 57ms
CGroup: /system.slice/spos3.service
└─651 /home/parzibyte/proyectos_go/api/tiendas
Aug 07 12:16:28 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Started Sistema de ventas by parzibyte.
Salida del journal:
sudo journalctl -u spos3
Aug 07 11:53:58 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Started Sistema de ventas by parzibyte.
Aug 07 11:56:01 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Stopping Sistema de ventas by parzibyte...
Aug 07 11:56:01 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: spos3.service: Deactivated successfully.
Aug 07 11:56:01 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Stopped Sistema de ventas by parzibyte.
Aug 07 11:57:53 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Started Sistema de ventas by parzibyte.
Aug 07 11:58:44 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Stopping Sistema de ventas by parzibyte...
Aug 07 11:58:44 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: spos3.service: Deactivated successfully.
Aug 07 11:58:44 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Stopped Sistema de ventas by parzibyte.
-- Boot 4b0f47331c294425b49d8949977dfa43 --
Aug 07 12:16:28 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Started Sistema de ventas by parzibyte.
Aug 07 12:19:10 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Stopping Sistema de ventas by parzibyte...
Aug 07 12:19:10 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: spos3.service: Deactivated successfully.
Aug 07 12:19:10 ubuntu-s-1vcpu-512mb-10gb-sfo3-01 systemd[1]: Stopped Sistema de ventas by parzibyte.
Y así nuestro sistema de ventas siempre iniciará con el sistema operativo