serv-status 2.07 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#
# Copyright (C) 2012  Etersoft
# Copyright (C) 2012  Vitaly Lipatov <lav@etersoft.ru>
#
6 7 8
# 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
# the Free Software Foundation, either version 3 of the License, or
9 10 11 12 13
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
15
#
16 17
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18 19
#

20
# FIXME: sudo ask password, but we do not print command before
21 22
is_service_running()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
23
	case $SERVICETYPE in
24
		service-chkconfig|service-upstart)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
25 26
			$SUDO service $1 status >/dev/null
			;;
27
		service-initd|service-update)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
28 29 30 31 32 33 34 35 36 37
			$SUDO /etc/init.d/$1 status >/dev/null
			;;
		systemd)
			#sudocmd systemctl is-enabled $1
			fatal "FIXME: don't know how detect current startup state"
			;;
		*)
			fatal "Do not known command for $SERVICETYPE"
			;;
	esac
38 39
}

40
# FIXME: sudo ask password, but we do not print command before
41 42
is_service_autostart()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
43
	case $SERVICETYPE in
44
		service-chkconfig|service-upstart)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
45 46
			LANG=C $SUDO chkconfig $1 --list | grep -q "5:on"
			;;
47
		service-initd|service-update)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
48 49 50
			fatal "FIXME: don't know how detect current startup state"
			;;
		systemd)
51
			sudocmd systemctl is-enabled $1.service
Vitaly Lipatov's avatar
Vitaly Lipatov committed
52 53 54 55 56
			;;
		*)
			fatal "Do not known command for $SERVICETYPE"
			;;
	esac
57 58 59 60 61
}

serv_status()
{
	is_service_autostart $1 && echo "Service $1 is sheduled to run on startup" || echo "Service $1 will NOT run on startup"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
62

63 64 65
	local SERVICE="$1"
	shift

Vitaly Lipatov's avatar
Vitaly Lipatov committed
66
	case $SERVICETYPE in
67
		service-chkconfig|service-upstart)
68
			sudocmd service $SERVICE status "$@"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
69 70
			;;
		service-update)
71
			sudocmd /etc/init.d/$SERVICE status "$@"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
72 73
			;;
		systemd)
74
			sudocmd systemctl status $SERVICE.service "$@"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
75 76 77 78 79
			;;
		*)
			fatal "Do not known command for $SERVICETYPE"
			;;
	esac
80
}