Systemd o Upstart o System V

Rápido recordatorio de  encontrar fácilmente (no es 100% seguro, dependerá de las distros) si estamos usando systemd/upstart/systemV

 

if [[ `/sbin/init --version` =~ upstart ]]; then echo using upstart;
elif [[ `systemctl` =~ -\.mount ]]; then echo using systemd;
elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then echo using sysv-init;
else echo cannot tell; fi
strings /sbin/init | grep -q "/lib/systemd" && echo SYSTEMD
strings /sbin/init | grep -q "sysvinit" && echo SYSVINIT
strings /sbin/init | grep -q "upstart" && echo UPSTART

Máquina de pruebas es una Amazon Linux AMI release 2017.09

El primer test


# bash check_bash.sh
using upstart

El segundo test


UPSTART

El caso en  concreto para este Linux AWS AMI es que funciona con una mezcla de systemV y upstart y me despistó un poco. Un ejemplo de upstart script sería:


description "node-exporter from prometheus"
start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
umask 022
chdir /
# console log - uncomment log stdout/stderr to /var/log/upstart/
# console none # Ubuntu 12.04++ requires explicitly saying we don't want to log anything

exec /usr/local/bin/node_exporter

Listar servicios


# initctl list

Arrancar upstart service


# sudo initctl start node-export
node-export start/running, process 21704

Comprobar upstart service


# sudo initctl status node-export
node-export start/running, process 21704

El mismo caso pero en systemd


[Unit]
Description=Node Exporter

[Service]
User=prometheus
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=default.target

 


# systemctl daemon-reload
# systemctl enable node_exporter.service
# systemctl start node_exporter.service

Links

 

Leave a Reply

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