startup – ¿Cómo ejecuto un solo comando al inicio usando systemd?

Pregunta:

Me gustaría iniciar un clúster de Apache Spark después del inicio con el siguiente comando:

sudo ./path/to/spark/sbin/start-all.sh

Luego ejecute este comando cuando el sistema se prepare para reiniciar / apagar:

sudo ./path/to/spark/sbin/stop-all.sh

¿Cómo puedo empezar? ¿Existe una plantilla básica sobre la que pueda construir?

Intenté usar un (archivo: /lib/systemd/system/spark.service ) extremadamente simple:

[Unit]
Description=Spark service

[Service]
ExecStart=sudo ./path/to/spark/sbin/start-all.sh

Que no funciona.

Respuesta:

Su archivo .service debería verse así:

[Unit]
Description=Spark service

[Service]
ExecStart=/path/to/spark/sbin/start-all.sh

[Install]
WantedBy=multi-user.target

Ahora, siga algunos pasos más para habilitar y usar el archivo .service :

  1. Colóquelo en la carpeta /etc/systemd/system con un nombre como myfirst.service .

  2. Asegúrese de que su script sea ejecutable con:

     chmod u+x /path/to/spark/sbin/start-all.sh
  3. Iniciarlo:

     sudo systemctl start myfirst
  4. Habilítelo para que se ejecute en el arranque:

     sudo systemctl enable myfirst
  5. Para:

     sudo systemctl stop myfirst

Notas

  1. No es necesario que inicie Spark con sudo en su servicio, ya que el usuario del servicio predeterminado ya es root.

  2. Mire los enlaces a continuación para ver más opciones de systemd .

es más

Ahora lo que tenemos arriba es rudimentario, aquí hay una configuración completa para Spark:

[Unit]
Description=Apache Spark Master and Slave Servers
After=network.target
After=systemd-user-sessions.service
After=network-online.target
 
[Service]
User=spark
Type=forking
ExecStart=/opt/spark-1.6.1-bin-hadoop2.6/sbin/start-all.sh
ExecStop=/opt/spark-1.6.1-bin-hadoop2.6/sbin/stop-all.sh
TimeoutSec=30
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10
 
[Install]
WantedBy=multi-user.target

Para configurar el servicio:

sudo systemctl start spark.service
sudo systemctl stop spark.service
sudo systemctl enable spark.service

Otras lecturas

Lea los siguientes enlaces. Spark es una configuración compleja, por lo que debe comprender cómo se integra con el servicio init de Ubuntu.

Leave a Comment

Your email address will not be published. Required fields are marked *

web tasarım