1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

F #1737: Improve systemd support (#1772)

This commit is contained in:
Vlastimil Holer 2018-02-21 17:06:20 +01:00 committed by Ruben S. Montero
parent b53cf7cadc
commit 9bd8acc524
30 changed files with 220 additions and 83 deletions

View File

@ -114,6 +114,7 @@ The argument expression *[OPTIONAL]* is used to set non-default values for:
parsers yes if you want to rebuild flex/bison files
new_xmlpc yes if you have an xmlrpc-c version >= 1.31
sunstone yes if you want to build sunstone minified files
systemd yes if you want to build systemd support
### Installation

View File

@ -143,6 +143,15 @@ if xmlrpc_dir!='none':
main_env.Append(LIBPATH=[xmlrpc_dir+"/lib", xmlrpc_dir+"/lib64"])
main_env.Append(CPPPATH=[xmlrpc_dir+"/include"])
# systemd
systemd=ARGUMENTS.get('systemd', 'no')
if systemd=='yes':
main_env.Append(systemd='yes')
main_env.Append(CPPFLAGS=["-DSYSTEMD"])
main_env.Append(LIBS=['systemd'])
else:
main_env.Append(systemd='no')
# build lex/bison
build_parsers=ARGUMENTS.get('parsers', 'no')
if build_parsers=='yes':

View File

@ -15,6 +15,14 @@ if [ -z "$IFADDR" ]; then
exit 1
fi
###
if which systemctl &>/dev/null && [ -d /etc/systemd ]; then
IS_SYSTEMD=yes
else
IS_SYSTEMD=no
fi
case $ACTION in
leader)
sudo ip address add $IFADDR dev $INTERFACE
@ -26,10 +34,22 @@ leader)
sleep 1
done
if which oneflow-server &>/dev/null &&
[ ! -e /var/run/one/oneflow.pid ];
then
oneflow-server start
if [ "${IS_SYSTEMD}" = 'yes' ]; then
if systemctl is-enabled opennebula-flow >/dev/null 2>&1; then
sudo -n systemctl start opennebula-flow
fi
if systemctl is-enabled opennebula-gate >/dev/null 2>&1; then
sudo -n systemctl start opennebula-gate
fi
else
if [ -e /usr/lib/one/oneflow/oneflow-server.rb ]; then
sudo -n service opennebula-flow start
fi
if [ -e /usr/lib/one/onegate/onegate-server.rb ]; then
sudo -n service opennebula-gate start
fi
fi
;;
@ -38,10 +58,22 @@ follower)
sudo ip address del $IFADDR dev $INTERFACE
fi
if which oneflow-server &>/dev/null &&
[ -e /var/run/one/oneflow.pid ];
then
oneflow-server stop
if [ "${IS_SYSTEMD}" = 'yes' ]; then
if systemctl is-active opennebula-flow >/dev/null 2>&1; then
sudo -n systemctl stop opennebula-flow
fi
if systemctl is-active opennebula-gate >/dev/null 2>&1; then
sudo -n systemctl stop opennebula-gate
fi
else
if [ -e /usr/lib/one/oneflow/oneflow-server.rb ]; then
sudo -n service opennebula-flow stop
fi
if [ -e /usr/lib/one/onegate/onegate-server.rb ]; then
sudo -n service opennebula-gate stop
fi
fi
;;

View File

@ -8,5 +8,6 @@ Cmnd_Alias ONE_ISCSI = /sbin/iscsiadm, /usr/sbin/tgt-admin, /usr/sbin/tgtadm
Cmnd_Alias ONE_OVS = /usr/bin/ovs-ofctl, /usr/bin/ovs-vsctl
Cmnd_Alias ONE_XEN = /usr/sbin/xentop, /usr/sbin/xl, /usr/sbin/xm
Cmnd_Alias ONE_CEPH = /usr/bin/rbd
Cmnd_Alias ONE_HA = /usr/bin/systemctl start opennebula-flow, /usr/bin/systemctl stop opennebula-flow, /usr/bin/systemctl start opennebula-gate, /usr/bin/systemctl stop opennebula-gate, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH, ONE_HA

View File

@ -1,15 +1,15 @@
[Unit]
Description=OpenNebula econe Server
After=syslog.target
After=network.target
After=syslog.target network.target
After=opennebula.service
AssertFileNotEmpty=/var/lib/one/.one/ec2_auth
[Service]
Type=simple
Group=oneadmin
User=oneadmin
ExecStartPre=-/usr/sbin/logrotate -f /etc/logrotate.d/opennebula-econe -s /var/lib/one/.logrotate.status
ExecStart=/usr/bin/ruby /usr/lib/one/ruby/cloud/econe/econe-server.rb
PIDFile=/var/run/one/econe-server.pid
[Install]
WantedBy=multi-user.target

View File

@ -1,16 +1,15 @@
[Unit]
Description=OpenNebula Flow Service
After=syslog.target
After=network.target
After=syslog.target network.target
After=opennebula.service
AssertFileNotEmpty=/var/lib/one/.one/oneflow_auth
[Service]
Type=forking
Type=simple
Group=oneadmin
User=oneadmin
ExecStartPre=-/bin/bash -c 'for i in {1..20}; do test -f /var/lib/one/.one/oneflow_auth && break; sleep 1; done'
ExecStart=/usr/bin/oneflow-server start
ExecStop=/usr/bin/oneflow-server stop
PIDFile=/var/run/one/oneflow.pid
ExecStartPre=-/usr/sbin/logrotate -f /etc/logrotate.d/opennebula-flow -s /var/lib/one/.logrotate.status
ExecStart=/usr/bin/ruby /usr/lib/one/oneflow/oneflow-server.rb
[Install]
WantedBy=multi-user.target

View File

@ -1,15 +1,15 @@
[Unit]
Description=OpenNebula Gate Service
After=syslog.target
After=network.target
After=syslog.target network.target
After=opennebula.service
AssertFileNotEmpty=/var/lib/one/.one/onegate_auth
[Service]
Type=simple
Group=oneadmin
User=oneadmin
ExecStartPre=-/usr/sbin/logrotate -f /etc/logrotate.d/opennebula-gate -s /var/lib/one/.logrotate.status
ExecStart=/usr/bin/ruby /usr/lib/one/onegate/onegate-server.rb
PIDFile=/var/run/one/onegate.pid
[Install]
WantedBy=multi-user.target

View File

@ -1,14 +1,12 @@
[Unit]
Description=OpenNebula noVNC Server
After=syslog.target
After=network.target
Before=opennebula-sunstone.service
After=syslog.target network.target
[Service]
Type=forking
Group=oneadmin
User=oneadmin
ExecStartPre=-/usr/sbin/logrotate -f /etc/logrotate.d/opennebula-novnc -s /var/lib/one/.logrotate.status
ExecStart=/usr/bin/novnc-server start
PIDFile=/var/lock/one/.novnc.lock

View File

@ -1,20 +1,16 @@
[Unit]
Description=OpenNebula Cloud Scheduler Daemon
After=syslog.target
After=network.target
After=remote-fs.target
After=syslog.target network.target remote-fs.target
After=opennebula.service
BindTo=opennebula.service
[Service]
Type=simple
Group=oneadmin
User=oneadmin
ExecStartPre=-/usr/sbin/logrotate -f /etc/logrotate.d/opennebula-scheduler -s /var/lib/one/.logrotate.status
ExecStart=/usr/bin/mm_sched
ExecStop=/bin/kill -TERM $MAINPID
PIDFile=/var/run/one/sched.pid
Restart=on-failure
RestartSec=1
[Install]
WantedBy=multi-user.target

View File

@ -1,19 +1,16 @@
[Unit]
Description=OpenNebula Web UI Server
After=syslog.target
After=network.target
After=syslog.target network.target
After=opennebula.service
After=opennebula-novnc.service
BindTo=opennebula-novnc.service
Wants=opennebula-novnc.service
AssertFileNotEmpty=/var/lib/one/.one/sunstone_auth
[Service]
Type=simple
Group=oneadmin
User=oneadmin
ExecStartPre=-/usr/sbin/logrotate -f /etc/logrotate.d/opennebula-sunstone -s /var/lib/one/.logrotate.status
ExecStart=/usr/bin/ruby /usr/lib/one/sunstone/sunstone-server.rb
ExecStartPre=-/usr/sbin/logrotate -s /tmp/logrotate.state -f /etc/logrotate.d/opennebula
PIDFile=/var/run/one/sunstone.pid
[Install]
WantedBy=multi-user.target

View File

@ -1,28 +1,19 @@
[Unit]
Description=OpenNebula Cloud Controller Daemon
After=syslog.target
After=network.target
After=remote-fs.target
After=syslog.target network.target remote-fs.target
After=mariadb.service mysql.service
Before=opennebula-scheduler.service
BindTo=opennebula-scheduler.service
Wants=opennebula-scheduler.service
[Service]
Type=simple
Type=notify
Group=oneadmin
User=oneadmin
# Start daemon in foreground mode, when starting as forking process the
# daemon shuts down without obvious reason.
ExecStartPre=-/usr/sbin/logrotate -f /etc/logrotate.d/opennebula -s /var/lib/one/.logrotate.status
ExecStart=/usr/bin/oned -f
# Log file location must exist
ExecStartPre=/bin/mkdir -p /var/log/one
ExecStartPre=/bin/chown oneadmin:oneadmin /var/log/one
ExecStartPre=-/usr/sbin/logrotate -s /tmp/logrotate.state -f /etc/logrotate.d/opennebula
ExecStop=/bin/kill -TERM $MAINPID
ExecStopPost=/bin/rm -f /var/lock/one/one
ExecStopPost=/usr/share/one/follower_cleanup
PIDFile=/var/run/one/oned.pid
PIDFile=/var/lock/one/one
Restart=on-failure
RestartSec=1
[Install]
WantedBy=multi-user.target

View File

@ -8,5 +8,6 @@ Cmnd_Alias ONE_ISCSI = /usr/bin/iscsiadm, /usr/sbin/tgt-admin, /usr/sbin/tgtadm
Cmnd_Alias ONE_OVS = /usr/bin/ovs-ofctl, /usr/bin/ovs-vsctl
Cmnd_Alias ONE_XEN = /usr/sbin/xentop, /usr/sbin/xl, /usr/sbin/xm
Cmnd_Alias ONE_CEPH = /usr/bin/rbd
Cmnd_Alias ONE_HA = /bin/systemctl start opennebula-flow, /bin/systemctl stop opennebula-flow, /bin/systemctl start opennebula-gate, /bin/systemctl stop opennebula-gate, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH, ONE_HA

View File

@ -8,5 +8,6 @@ Cmnd_Alias ONE_ISCSI = /usr/bin/iscsiadm, /usr/sbin/tgt-admin, /usr/sbin/tgtadm
Cmnd_Alias ONE_OVS = /usr/bin/ovs-ofctl, /usr/bin/ovs-vsctl
Cmnd_Alias ONE_XEN = /usr/sbin/xentop, /usr/sbin/xl, /usr/sbin/xm
Cmnd_Alias ONE_CEPH = /usr/bin/rbd
Cmnd_Alias ONE_HA = /bin/systemctl start opennebula-flow, /bin/systemctl stop opennebula-flow, /bin/systemctl start opennebula-gate, /bin/systemctl stop opennebula-gate, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH, ONE_HA

View File

@ -1,4 +1,4 @@
#! /bin/sh
#! /bin/bash
### BEGIN INIT INFO
# Provides: opennebula
# Required-Start: $remote_fs $syslog
@ -38,7 +38,22 @@ do_start()
{
mkdir -p /var/run/one /var/lock/one
chown oneadmin /var/run/one /var/lock/one
logrotate -f /etc/logrotate.d/opennebula /etc/logrotate.d/opennebula-scheduler
su oneadmin -s /bin/sh -c 'one start'
ONE_START=$?
# wait for the service to be ready
RETRIES=30
while ! onegroup list >/dev/null 2>&1; do
RETRIES=$((RETRIES - 1))
if [ ${RETRIES} -le 0 ]; then
return 2
fi
sleep 2
done
return $ONE_START
}
#
@ -51,6 +66,7 @@ do_stop()
do_start_sched()
{
logrotate -f /etc/logrotate.d/opennebula-scheduler
su oneadmin -s /bin/sh -c 'one start-sched'
}

View File

@ -36,6 +36,7 @@ do_start()
{
mkdir -p /var/run/one /var/lock/one /var/log/one
chown oneadmin /var/run/one /var/lock/one /var/log/one
logrotate -f /etc/logrotate.d/opennebula-econe
su oneadmin -s /bin/sh -c "$DAEMON start"
}

View File

@ -36,6 +36,7 @@ do_start()
{
mkdir -p /var/run/one /var/lock/one /var/log/one
chown oneadmin /var/run/one /var/lock/one /var/log/one
logrotate -f /etc/logrotate.d/opennebula-flow
su oneadmin -s /bin/sh -c "$DAEMON start"
}

View File

@ -36,6 +36,7 @@ do_start()
{
mkdir -p /var/run/one /var/lock/one /var/log/one
chown oneadmin /var/run/one /var/lock/one /var/log/one
logrotate -f /etc/logrotate.d/opennebula-gate
su oneadmin -s /bin/sh -c "$DAEMON start"
}

View File

@ -35,6 +35,7 @@ do_start()
{
mkdir -p /var/lock/one /var/log/one
chown oneadmin /var/lock/one /var/log/one
logrotate -f /etc/logrotate.d/opennebula-novnc
su oneadmin -s /bin/sh -c "$DAEMON start"
}

View File

@ -37,6 +37,7 @@ do_start()
service opennebula-novnc start
mkdir -p /var/run/one /var/lock/one /var/log/one
chown oneadmin /var/run/one /var/lock/one /var/log/one
logrotate -f /etc/logrotate.d/opennebula-sunstone
su oneadmin -s /bin/sh -c "$DAEMON start-sunstone"
}

View File

@ -8,5 +8,6 @@ Cmnd_Alias ONE_ISCSI = /usr/bin/iscsiadm, /usr/sbin/tgt-admin, /usr/sbin/tgtadm
Cmnd_Alias ONE_OVS = /usr/bin/ovs-ofctl, /usr/bin/ovs-vsctl
Cmnd_Alias ONE_XEN = /usr/sbin/xentop, /usr/sbin/xl, /usr/sbin/xm
Cmnd_Alias ONE_CEPH = /usr/bin/rbd
Cmnd_Alias ONE_HA = /bin/systemctl start opennebula-flow, /bin/systemctl stop opennebula-flow, /bin/systemctl start opennebula-gate, /bin/systemctl stop opennebula-gate, /usr/sbin/service opennebula-flow start, /usr/sbin/service opennebula-flow stop, /usr/sbin/service opennebula-gate start, /usr/sbin/service opennebula-gate stop
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_CEPH, ONE_HA

View File

@ -6,20 +6,8 @@ compress
weekly
rotate 52
/var/log/one/one_xmlrpc.log {
missingok
notifempty
copytruncate
}
/var/log/one/oned.log {
missingok
notifempty
copytruncate
}
/var/log/one/sched.log {
missingok
notifempty
copytruncate
/var/log/one/one_xmlrpc.log /var/log/one/oned.log {
missingok
notifempty
copytruncate
}

View File

@ -0,0 +1,13 @@
delaycompress
dateext
dateformat -%Y%m%d-%s
compress
weekly
rotate 52
/var/log/one/econe-server.log {
missingok
notifempty
copytruncate
}

View File

@ -0,0 +1,13 @@
delaycompress
dateext
dateformat -%Y%m%d-%s
compress
weekly
rotate 52
/var/log/one/oneflow.log {
missingok
notifempty
copytruncate
}

View File

@ -0,0 +1,13 @@
delaycompress
dateext
dateformat -%Y%m%d-%s
compress
weekly
rotate 52
/var/log/one/onegate.log {
missingok
notifempty
copytruncate
}

View File

@ -0,0 +1,13 @@
delaycompress
dateext
dateformat -%Y%m%d-%s
compress
weekly
rotate 52
/var/log/one/novnc.log {
missingok
notifempty
copytruncate
}

View File

@ -0,0 +1,13 @@
delaycompress
dateext
dateformat -%Y%m%d-%s
compress
weekly
rotate 52
/var/log/one/sched.log {
missingok
notifempty
copytruncate
}

View File

@ -0,0 +1,13 @@
delaycompress
dateext
dateformat -%Y%m%d-%s
compress
weekly
rotate 52
/var/log/one/sunstone.log {
missingok
notifempty
copytruncate
}

View File

@ -7,5 +7,6 @@ Cmnd_Alias ONE_LVM = /sbin/lvcreate, /sbin/lvremove, /sbin/lvs, /sbin/vgdisplay,
Cmnd_Alias ONE_ISCSI = /sbin/iscsiadm, /usr/sbin/tgt-admin, /usr/sbin/tgtadm
Cmnd_Alias ONE_OVS = /usr/bin/ovs-ofctl, /usr/bin/ovs-vsctl
Cmnd_Alias ONE_XEN = /usr/sbin/xentop, /usr/sbin/xl, /usr/sbin/xm
Cmnd_Alias ONE_HA = /usr/bin/systemctl start opennebula-flow, /usr/bin/systemctl stop opennebula-flow, /usr/bin/systemctl start opennebula-gate, /usr/bin/systemctl stop opennebula-gate, /sbin/service opennebula-flow start, /sbin/service opennebula-flow stop, /sbin/service opennebula-gate start, /sbin/service opennebula-gate stop
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN
oneadmin ALL=(ALL) NOPASSWD: ONE_MISC, ONE_NET, ONE_LVM, ONE_ISCSI, ONE_OVS, ONE_XEN, ONE_HA

18
share/sudoers/sudo_commands.rb Normal file → Executable file
View File

@ -26,7 +26,17 @@ CMDS = {
:ISCSI => %w(iscsiadm tgt-admin tgtadm),
:OVS => %w(ovs-ofctl ovs-vsctl),
:XEN => %w(xentop xl xm),
:CEPH => %w(rbd)
:CEPH => %w(rbd),
:HA => [
'systemctl start opennebula-flow',
'systemctl stop opennebula-flow',
'systemctl start opennebula-gate',
'systemctl stop opennebula-gate',
'service opennebula-flow start',
'service opennebula-flow stop',
'service opennebula-gate start',
'service opennebula-gate stop'
],
}
KEYS = CMDS.keys
@ -39,10 +49,12 @@ KEYS.each do |label|
_abs_cmds = []
cmds.each do |cmd|
abs_cmd = `which #{cmd} 2>/dev/null`
cmd_parts = cmd.split
abs_cmd = `which #{cmd_parts[0]} 2>/dev/null`
if !abs_cmd.empty?
_abs_cmds << abs_cmd.strip
cmd_parts[0] = abs_cmd.strip
_abs_cmds << cmd_parts.join(' ')
else
not_found_cmds << cmd
end

View File

@ -32,6 +32,10 @@
#include <sys/stat.h>
#include <pthread.h>
#ifdef SYSTEMD
#include <systemd/sd-daemon.h>
#endif
using namespace std;
/* -------------------------------------------------------------------------- */
@ -1091,6 +1095,12 @@ void Nebula::start(bool bootstrap_only)
throw runtime_error("Could not start the Request Manager");
}
#ifdef SYSTEMD
// ---- Notify service manager ----
sd_notify(0, "READY=1");
#endif
// -----------------------------------------------------------
// Wait for a SIGTERM or SIGINT signal
// -----------------------------------------------------------