Linux
Unten finden Sie zwei Beispiele für verschiedene Init-Systeme unter Linux. Passen Sie ggf. die Einstellungen für ihr System an.
Beispielskript für Upstart
Codeblock |
---|
language | bash |
---|
theme | Emacs | language | bash |
---|
|
$ nano /etc/init/mmsd.conf
$ service mmsd start |
Codeblock |
---|
theme | Emacs |
---|
firstline | 1 |
---|
title | /etc/init/mmsd | firstline | 1.conf |
---|
linenumbers | true |
---|
collapse | true |
---|
|
#!upstart
description "Mongo Management Studio Daemon"
author "Litixsoft 2014"
#start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel 0
respawn # restart job if died
respawn limit 5 60 # after 5 trys in 60 seconds abort
script
NODEBIN="/opt/litixsoft/baboonstack/node/0.10.26/usr/bin/node"
APPPATH="/opt/litixsoft/mongo_management_studio/"
NODEAPP="server.js"
LOGFILE="/var/log/mmsd.log"
PIDFILE="/var/run/mmsd.pid"
exec start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --chdir $APPPATH --exec $NODEBIN $NODEAPP
end script |
Beispielskript für init.d
Codeblock |
---|
language | bash |
---|
theme | Emacs | language | bash |
---|
|
$ nano /etc/init.d/mmsd
$ chmod +x /etc/init.d/mmsd
$ update-rc.d mmsd defaults
$ ./etc/init.d/mmsd start |
Codeblock |
---|
language | bash |
---|
theme | Emacs |
---|
languagefirstline | bash1 |
---|
title | /etc/init.d/mmsd | firstline | 1 |
---|
linenumbers | true |
---|
collapse | true |
---|
|
#!/bin/sh
#
# chkconfig: 35 99 99
# description: Mongo Management Studio Daemonize
#
. /etc/rc.d/init.d/functions
USER="nodejs"
NODEBIN="/opt/litixsoft/baboonstack/node/0.10.26/usr/bin/node"
NODEAPP="/opt/litixsoft/mongo_management_studio/server.js"
LOGFILE="/var/log/mmsd.log"
LCKFILE="/var/lock/subsys/mmsd"
do_start()
{
if [ ! -f "$LCKFILE" ] ; then
echo -n $"Starting $NODEAPP: "
runuser -l "$USER" -c "$NODEBIN $NODEAPP >> $LOGFILE &" && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LCKFILE
else
echo "$NODEAPP is locked."
RETVAL=1
fi
}
do_stop()
{
echo -n $"Stopping $NODEAPP: "
pid=`ps -aefw | grep "$NODEBIN $NODEAPP" | grep -v " grep " | awk '{print $2}'`
kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LCKFILE
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL |
Beispielscript für SystemD (hier: CentOS 7):
- Erstellen einer Servicedatei für die Applikation in /etc/systemd/system/mms.service
- Pfade sowie Benutzer und Gruppen anpassen
Codeblock |
---|
language | bash |
---|
title | /etc/systemd/system/mms.service |
---|
|
[Service]
ExecStart=/usr/bin/node /opt/lx-mms/server.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=litixsoft-mms
User=[username that runs the service]
Group=[group the user is in]
WorkingDirectory=/opt/lx-mms/
[Install]
WantedBy=multi-user.target
|
3. Einrichten des Dienstes über "systemctl enable mms", Starten durch "systemctl start mms", Status überprüfen über "systemctl status mms", Stoppen über "systemctl stop mms".