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" ...@@ -98,8 +98,22 @@ is_active_systemd && CMD="systemd"
SERVICETYPE=$CMD 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() phelp()
......
...@@ -24,6 +24,9 @@ serv_common() ...@@ -24,6 +24,9 @@ serv_common()
shift shift
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
fatal "Have no idea how to call anyservice service with args"
fi
sudocmd service $SERVICE "$@" sudocmd service $SERVICE "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -28,6 +28,10 @@ serv_disable() ...@@ -28,6 +28,10 @@ serv_disable()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE off
return
fi
sudocmd chkconfig $1 off sudocmd chkconfig $1 off
;; ;;
service-initd|service-update) service-initd|service-update)
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -28,6 +28,11 @@ serv_enable() ...@@ -28,6 +28,11 @@ serv_enable()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig) 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 --add $1 || return
sudocmd chkconfig $1 on sudocmd chkconfig $1 on
;; ;;
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -38,6 +38,11 @@ serv_list() ...@@ -38,6 +38,11 @@ serv_list()
for i in $(serv_list_all) ; do for i in $(serv_list_all) ; do
is_service_running $i >/dev/null && echo $i is_service_running $i >/dev/null && echo $i
done done
# TODO: только запущенные
if [ -n "$ANYSERVICE" ] ; then
sudocmd anyservice list
return
fi
;; ;;
esac esac
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012,2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012,2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -24,6 +24,11 @@ serv_list_all() ...@@ -24,6 +24,11 @@ serv_list_all()
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
# service --status-all for Ubuntu/Fedora # service --status-all for Ubuntu/Fedora
sudocmd chkconfig --list | cut -f1 sudocmd chkconfig --list | cut -f1
if [ -n "$ANYSERVICE" ] ; then
sudocmd anyservice list
return
fi
;; ;;
service-initd|service-update) service-initd|service-update)
sudocmd ls $INITDIR/ | grep -v README sudocmd ls $INITDIR/ | grep -v README
......
...@@ -20,4 +20,5 @@ ...@@ -20,4 +20,5 @@
serv_print() serv_print()
{ {
echo "Detected init system: $SERVICETYPE" echo "Detected init system: $SERVICETYPE"
[ -n "$ANYSERVICE" ] && echo "anyservice is detected too"
} }
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -27,6 +27,10 @@ serv_restart() ...@@ -27,6 +27,10 @@ serv_restart()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE restart
return
fi
sudocmd service $SERVICE restart "$@" sudocmd service $SERVICE restart "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -25,6 +25,10 @@ serv_start() ...@@ -25,6 +25,10 @@ serv_start()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE start
return
fi
sudocmd service $SERVICE start "$@" sudocmd service $SERVICE start "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012, 2013 Etersoft # Copyright (C) 2012, 2013, 2016 Etersoft
# Copyright (C) 2012, 2013 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2013, 2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -22,6 +22,10 @@ is_service_running() ...@@ -22,6 +22,10 @@ is_service_running()
{ {
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
$SUDO anyservice $1 status >/dev/null
return
fi
$SUDO service $1 status >/dev/null $SUDO service $1 status >/dev/null
;; ;;
service-initd|service-update) service-initd|service-update)
...@@ -41,7 +45,11 @@ is_service_autostart() ...@@ -41,7 +45,11 @@ is_service_autostart()
{ {
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
# FIXME: check for current runlevel 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" LANG=C $SUDO chkconfig $1 --list | grep -q "[35]:on"
;; ;;
service-initd|service-update) service-initd|service-update)
...@@ -65,6 +73,10 @@ serv_status() ...@@ -65,6 +73,10 @@ serv_status()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE status
return
fi
sudocmd service $SERVICE status "$@" sudocmd service $SERVICE status "$@"
;; ;;
service-update) service-update)
......
#!/bin/sh #!/bin/sh
# #
# Copyright (C) 2012 Etersoft # Copyright (C) 2012, 2016 Etersoft
# Copyright (C) 2012 Vitaly Lipatov <lav@etersoft.ru> # Copyright (C) 2012, 2016 Vitaly Lipatov <lav@etersoft.ru>
# #
# This program is free software: you can redistribute it and/or modify # 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 # it under the terms of the GNU Affero General Public License as published by
...@@ -25,6 +25,10 @@ serv_stop() ...@@ -25,6 +25,10 @@ serv_stop()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
if is_anyservice $SERVICE ; then
sudocmd anyservice $SERVICE stop
return
fi
sudocmd service $SERVICE stop "$@" sudocmd service $SERVICE stop "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
......
...@@ -28,7 +28,7 @@ serv_try_restart() ...@@ -28,7 +28,7 @@ serv_try_restart()
case $SERVICETYPE in case $SERVICETYPE in
service-chkconfig|service-upstart) service-chkconfig|service-upstart)
is_service_running $SERVICE || return 0 is_service_running $SERVICE || return 0
sudocmd service $SERVICE restart "$@" docmd serv $SERVICE restart "$@"
;; ;;
service-initd|service-update) service-initd|service-update)
is_service_running $SERVICE || return 0 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