Commit 6dd90af9 authored by Vitaly Lipatov's avatar Vitaly Lipatov

serv: add anyservice support

parent a3b42e85
......@@ -98,8 +98,22 @@ is_active_systemd && CMD="systemd"
SERVICETYPE=$CMD
ANYSERVICE=$(which anyservice 2>/dev/null >/dev/null)
ANYSERVDIR="/etc/systemd-lite"
ANYSYSDDIR="/lib/systemd/system"
}
is_anyservice()
{
local SERVICE="$1"
# not, if we have no anyservice at all
[ -n "$ANYSERVICE" ] || return 1
# not, if there is regular service with the name
[ -d "$INITDIR/$SERVICE" ] && return 1
# yes, if the service is anyservice driven
[ -r "$ANYSERVDIR/$SERVICE.service" ]
}
phelp()
......
......@@ -24,6 +24,9 @@ serv_common()
shift
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
fatal "Have no idea how to call anyservice service with args"
fi
sudocmd service $SERVICE "$@"
;;
service-initd|service-update)
......
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -28,6 +28,10 @@ serv_disable()
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE off
return
fi
sudocmd chkconfig $1 off
;;
service-initd|service-update)
......
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -28,6 +28,11 @@ serv_enable()
case $SERVICETYPE in
service-chkconfig)
# can't use is_anyservice here
if [ ! -d "$INITDIR/$SERVICE" ] && [ -n "$ANYSERVICE" ] && [ -r "$ANYSYSDDIR/$SERVICE.service" ] ; then
sudocmd anyservice $SERVICE on
return
fi
sudocmd chkconfig --add $1 || return
sudocmd chkconfig $1 on
;;
......
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -38,6 +38,11 @@ serv_list()
for i in $(serv_list_all) ; do
is_service_running $i >/dev/null && echo $i
done
# TODO: только запущенные
if [ -n "$ANYSERVICE" ] ; then
sudocmd anyservice list
return
fi
;;
esac
}
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012,2016 Etersoft
# Copyright (C) 2012,2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -24,6 +24,11 @@ serv_list_all()
service-chkconfig|service-upstart)
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1
if [ -n "$ANYSERVICE" ] ; then
sudocmd anyservice list
return
fi
;;
service-initd|service-update)
sudocmd ls $INITDIR/ | grep -v README
......
......@@ -20,4 +20,5 @@
serv_print()
{
echo "Detected init system: $SERVICETYPE"
[ -n "$ANYSERVICE" ] && echo "anyservice is detected too"
}
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -27,6 +27,10 @@ serv_restart()
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE restart
return
fi
sudocmd service $SERVICE restart "$@"
;;
service-initd|service-update)
......
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -25,6 +25,10 @@ serv_start()
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE start
return
fi
sudocmd service $SERVICE start "$@"
;;
service-initd|service-update)
......
#!/bin/sh
#
# Copyright (C) 2012, 2013 Etersoft
# Copyright (C) 2012, 2013 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2013, 2016 Etersoft
# Copyright (C) 2012, 2013, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -22,6 +22,10 @@ is_service_running()
{
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
$SUDO anyservice $1 status >/dev/null
return
fi
$SUDO service $1 status >/dev/null
;;
service-initd|service-update)
......@@ -41,6 +45,10 @@ is_service_autostart()
{
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
# if is registered, assume it is autostarted
return 0
fi
# FIXME: check for current runlevel
LANG=C $SUDO chkconfig $1 --list | grep -q "[35]:on"
;;
......@@ -65,6 +73,10 @@ serv_status()
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE status
return
fi
sudocmd service $SERVICE status "$@"
;;
service-update)
......
#!/bin/sh
#
# Copyright (C) 2012 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru>
# Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
......@@ -25,6 +25,10 @@ serv_stop()
case $SERVICETYPE in
service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE stop
return
fi
sudocmd service $SERVICE stop "$@"
;;
service-initd|service-update)
......
......@@ -28,7 +28,7 @@ serv_try_restart()
case $SERVICETYPE in
service-chkconfig|service-upstart)
is_service_running $SERVICE || return 0
sudocmd service $SERVICE restart "$@"
docmd serv $SERVICE restart "$@"
;;
service-initd|service-update)
is_service_running $SERVICE || return 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment