Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/src/modules/systemd/mcore-system-service.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2651 - (show annotations) (download)
Tue Nov 10 15:00:32 2015 UTC (8 years, 5 months ago) by niro
File size: 1825 byte(s)
-fixed a typo
1 #!/bin/bash
2
3 MCORE_LIBDIR="@@MCORE_LIBDIR@@"
4 source @@SYSCONFDIR@@/mcore/mcore.conf
5 source ${MCORE_LIBDIR}/include/common.global.class
6 source ${MCORE_LIBDIR}/include/daemon.global.class
7
8 die() { echo "ERROR: $@"; exit 1; }
9
10 control_service()
11 {
12 local command="$1"
13 local service="$2"
14 local chrooted
15
16 if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]]
17 then
18 chrooted="system_chroot"
19 case ${command} in
20 start|stop|restart|reload)
21 eecho "Command not available while \$MROOT is set"
22 return 1
23 ;;
24 esac
25 fi
26
27 if [[ -n $(${chrooted} systemctl status ${service} | grep 'Reason: No such file or directory') ]]
28 then
29 eecho "Service '${service}' unknown!"
30 return 1
31 fi
32
33 # auto-append .service to fix issues while $MROOT is set
34 if [[ -n $(echo ${service} | grep -v '.service$\|.target$\|.mount$\|.socket$\|.timer$') ]]
35 then
36 service="${service}.service"
37 decho "\$service replaced with '${service}'"
38 fi
39
40 case "${command}" in
41 start) ${chrooted} systemctl start "${service}" ;;
42 stop) ${chrooted} systemctl stop "${service}" ;;
43 restart) ${chrooted} systemctl try-restart "${service}" ;;
44 reload) ${chrooted} systemctl reload-or-try-restart "${service}" ;;
45 enable) ${chrooted} systemctl enable "${service}" ;;
46 disable) ${chrooted} systemctl disable "${service}" ;;
47 status) ${chrooted} systemctl status "${service}" ;;
48 enabled) ${chrooted} systemctl is-enabled "${service}"; rvecho "$?" ;;
49 runlevel) rvecho "$(readline ${MROOT}@@SYSTEMDSYSTEMCONFDIR@@/default.target)" ;;
50 *) return 1 ;;
51 esac
52 }
53
54 # very basic getops
55 for argv in $*
56 do
57 case $1 in
58 --start|--stop|--restart|--reload|--enable|--disable|--status|--enabled|--runlevel) command="${1//--}" ;;
59 --service) shift; service="$1" ;;
60 esac
61 shift
62 done
63
64 [[ -n ${command} ]] || die "No command given"
65 control_service "${command}" "${service}"