serv-enable 1.35 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 21 22 23
#

load_helper serv-start
load_helper serv-status

# Enable service by default
24
serv_enable()
25 26 27 28 29
{
	is_service_running $1 || serv_start $1 || return
	is_service_autostart $1 && echo "Service $1 already enabled for startup" && return

	case $SERVICETYPE in
30
		service-chkconfig)
31 32
			sudocmd chkconfig --add $1 || return
			sudocmd chkconfig $1 on
33 34
			;;
		service-upstart)
35
			sudocmd chkconfig --add $1 || return
36 37
			sudocmd chkconfig $1 on
			;;
38
		service-initd|service-update)
39 40
			sudocmd update-rc.d $1 defaults
			;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
41 42 43
		systemd)
			sudocmd systemctl enable $1
			;;
44
		*)
45
			fatal "Have no suitable command for $SERVICETYPE"
46 47 48 49
			;;
	esac

}