serv-enable 1.73 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2016  Etersoft
# Copyright (C) 2012, 2016  Vitaly Lipatov <lav@etersoft.ru>
5
#
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
	local SERVICE="$1"

28
	is_service_autostart $1 && info "Service $1 is already enabled for startup" && return
29 30

	case $SERVICETYPE in
31
		service-chkconfig)
32
			if is_anyservice $SERVICE ; then
33 34 35
				sudocmd anyservice $SERVICE on
				return
			fi
36 37
			sudocmd chkconfig --add $1 || return
			sudocmd chkconfig $1 on
38 39
			;;
		service-upstart)
40
			sudocmd chkconfig --add $1 || return
41 42
			sudocmd chkconfig $1 on
			;;
43
		service-initd|service-update)
44 45
			sudocmd update-rc.d $1 defaults
			;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
46 47 48
		systemd)
			sudocmd systemctl enable $1
			;;
49
		runit)
50
			epm assure $SERVICE
51 52 53
			[ -r "/etc/sv/$SERVICE" ] || fatal "Can't find /etc/sv/$SERVICE"
			sudocmd ln -s /etc/sv/$SERVICE /var/service/
			;;
54
		*)
55
			fatal "Have no suitable command for $SERVICETYPE"
56 57 58 59
			;;
	esac

}
60 61 62 63 64

serv_enable()
{
	__serv_enable "$1" || return
	# start if need
Vitaly Lipatov's avatar
Vitaly Lipatov committed
65 66
	is_service_running $1 && info "Service $1 is already running" && return
	serv_start $1
67
}