Error al iniciar <myapp> .service: Unidad <myapp> .service no encontrado


13

Creé un script init.d super básico para mi bot de python:

#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    echo "starting torbot"
    python /home/ctote/dev/slackbots/torbot/torbot.py
    # example: daemon program_name &
}

stop() {
    # code to stop app comes here
    # example: killproc program_name
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac

Y se han establecido torbot.pypara ser +xy #!/usr/local/bin/pythonen la cima. Sin embargo, cuando intento iniciarlo, obtengo:

:/var/lock/subsys$ sudo service torbot start Failed to start torbot.service: Unit torbot.service not found.

¿Me estoy perdiendo de algo?

Respuestas:


4

Si está utilizando ubuntu 16.04 o más reciente, es posible que desee revisar el documento de systemd sobre creación de archivos de servicio

El script es para el antiguo sistema init y es administrado por una capa de compatibilidad heredada.


2

Para mí, estoy usando Ubuntu 16.04.

Primero cambie la función init

. /etc/init.d/functions

a

. /lib/lsb/init-functions

Luego, en shell, cree enlaces simbólicos desde / etc / rc * a mi script:

sudo update-rc.d <myapp> defaults 95

¿Qué significa 95 aquí?
Gherman

@Gherman es prioridad
turson

1

Ok, intenté algunos pasos en esta respuesta de stackoverflow (¿ Ejecutando script de arranque en 17.04? ) Y funcionaron Mi entorno es el siguiente

  1. Ubuntu a las 17.10
  2. Tengo una aplicación python en el servidor Gunicorn 19.x, necesito iniciar esta aplicación como un servicio.

En primer lugar, debe escribir un archivo foo.service.

[Unit] 
Description=FooServer 

[Service] 
Restart=on-failure
WorkingDirectory=/path/to/your/working/directory/where the foo lives
ExecStart=/what/process/will call foo eg: in my case I used gunicorn app:app
ExecReload=/bin/kill -HUP $MAINPID 
KillSignal=SIGINT 

[Install] 
WantedBy=multi-user.target

El significado de cada palabra en el lado izquierdo del signo '=' y su equivalente en el inicio (al anterior) está en el enlace https://wiki.ubuntu.com/SystemdForUpstartUsers

Una vez que el archivo esté listo, supongamos que lo nombra como 'foo.service' (la extensión .service es importante)

Necesita colocar el archivo en /lib/systemd/system

Después de lo cual debe habilitar el servicio llamando

systemctl enable foo

Lo que le pedirá que ingrese su contraseña de root, ya que creará enlaces simbólicos.

Si ha llegado hasta aquí sin problemas, está bien. Por lo tanto, se crea su servicio. El inicio es llamando

sudo service foo start

systemctl status foopara ver el estado sudo service foo stoppara detener el servicio



0

Tuve el mismo problema, esta es la solución que funcionó para mí. Tratar:

sudo systemctl daemon-reload

sudo systemctl enable daemon_app.service

sudo systemctl start daemon_app.service

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.