Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
eepm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
eepm
Commits
b9dbd9ab
Commit
b9dbd9ab
authored
Apr 12, 2023
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
serv: replace tab with 4 spaces
parent
f204e69b
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
543 additions
and
543 deletions
+543
-543
serv
bin/serv
+14
-14
serv-cat
bin/serv-cat
+18
-18
serv-common
bin/serv-common
+27
-27
serv-disable
bin/serv-disable
+26
-26
serv-edit
bin/serv-edit
+10
-10
serv-enable
bin/serv-enable
+33
-33
serv-exists
bin/serv-exists
+18
-18
serv-list
bin/serv-list
+30
-30
serv-list_all
bin/serv-list_all
+43
-43
serv-list_failed
bin/serv-list_failed
+21
-21
serv-list_startup
bin/serv-list_startup
+23
-23
serv-log
bin/serv-log
+37
-37
serv-off
bin/serv-off
+4
-4
serv-on
bin/serv-on
+4
-4
serv-print
bin/serv-print
+2
-2
serv-reload
bin/serv-reload
+22
-22
serv-restart
bin/serv-restart
+26
-26
serv-start
bin/serv-start
+26
-26
serv-status
bin/serv-status
+74
-74
serv-stop
bin/serv-stop
+26
-26
serv-test
bin/serv-test
+26
-26
serv-try_restart
bin/serv-try_restart
+13
-13
serv-usage
bin/serv-usage
+20
-20
No files found.
bin/serv
View file @
b9dbd9ab
...
...
@@ -46,18 +46,18 @@ check_tty
# FIXME: add upstart support (Ubuntu?)
set_service_type
()
{
local
CMD
local
CMD
set_distro_info
set_target_pkg_env
set_distro_info
set_target_pkg_env
case
"
$DISTRCONTROL
"
in
sysvinit
)
CMD
=
"service-chkconfig"
;;
systemd
)
CMD
=
"systemd"
;;
sysvinit
)
CMD
=
"service-chkconfig"
;;
systemd
)
CMD
=
"systemd"
;;
esac
# override system control detection result
...
...
@@ -72,16 +72,16 @@ ANYSERVICE=$(print_command_path anyservice)
# TODO: done it on anyservice part
is_anyservice
()
{
[
-n
"
$ANYSERVICE
"
]
||
return
[
-n
"
$1
"
]
||
return
# check if anyservice is exists and checkd returns true
$ANYSERVICE
"
$1
"
checkd 2>/dev/null
[
-n
"
$ANYSERVICE
"
]
||
return
[
-n
"
$1
"
]
||
return
# check if anyservice is exists and checkd returns true
$ANYSERVICE
"
$1
"
checkd 2>/dev/null
}
phelp
()
{
echo
"
$Descr
echo
"
$Descr
$Usage
Commands:
$(
get_help HELPCMD
)
...
...
bin/serv-cat
View file @
b9dbd9ab
...
...
@@ -19,23 +19,23 @@
serv_cat
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
systemd
)
docmd systemctl
cat
"
$SERVICE
"
"
$@
"
;;
*
)
case
$BASEDISTRNAME
in
"alt"
)
local
INITFILE
=
/etc/init.d/
$SERVICE
[
-r
"
$INITFILE
"
]
||
fatal
"Can't find init file
$INITFILE
"
docmd
cat
$INITFILE
return
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
esac
case
$SERVICETYPE
in
systemd
)
docmd systemctl
cat
"
$SERVICE
"
"
$@
"
;;
*
)
case
$BASEDISTRNAME
in
"alt"
)
local
INITFILE
=
/etc/init.d/
$SERVICE
[
-r
"
$INITFILE
"
]
||
fatal
"Can't find init file
$INITFILE
"
docmd
cat
$INITFILE
return
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
esac
}
bin/serv-common
View file @
b9dbd9ab
...
...
@@ -20,31 +20,31 @@
# Common call service
serv_common
()
{
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
fatal
"Have no idea how to call anyservice service with args"
fi
sudocmd service
$SERVICE
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
"
$@
"
;;
systemd
)
# run init script directly (for nonstandart commands)
if
[
-x
$INITDIR
/
$SERVICE
]
;
then
sudocmd
$INITDIR
/
$SERVICE
"
$@
"
else
sudocmd systemctl
"
$@
"
$SERVICE
fi
;;
runit
)
sudocmd sv
$SERVICE
"
$@
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
fatal
"Have no idea how to call anyservice service with args"
fi
sudocmd service
$SERVICE
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
"
$@
"
;;
systemd
)
# run init script directly (for nonstandart commands)
if
[
-x
$INITDIR
/
$SERVICE
]
;
then
sudocmd
$INITDIR
/
$SERVICE
"
$@
"
else
sudocmd systemctl
"
$@
"
$SERVICE
fi
;;
runit
)
sudocmd sv
$SERVICE
"
$@
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-disable
View file @
b9dbd9ab
...
...
@@ -23,32 +23,32 @@ load_helper serv-status
# Enable service by default
serv_disable
()
{
local
SERVICE
=
"
$1
"
local
SERVICE
=
"
$1
"
is_service_autostart
$1
||
{
info
"Service
$1
already disabled for startup"
&&
return
;
}
is_service_autostart
$1
||
{
info
"Service
$1
already disabled for startup"
&&
return
;
}
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
off
return
fi
sudocmd chkconfig
$1
off
;;
service-initd|service-update
)
sudocmd update-rc.d
$1
remove
;;
systemd
)
sudocmd systemctl disable
$1
;;
openrc
)
sudocmd rc-update del
$1
default
;;
runit
)
sudocmd
rm
-fv
/var/service/
$SERVICE
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
off
return
fi
sudocmd chkconfig
$1
off
;;
service-initd|service-update
)
sudocmd update-rc.d
$1
remove
;;
systemd
)
sudocmd systemctl disable
$1
;;
openrc
)
sudocmd rc-update del
$1
default
;;
runit
)
sudocmd
rm
-fv
/var/service/
$SERVICE
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-edit
View file @
b9dbd9ab
...
...
@@ -19,15 +19,15 @@
serv_edit
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
systemd
)
sudocmd systemctl edit
"
$@
"
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
systemd
)
sudocmd systemctl edit
"
$@
"
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
}
bin/serv-enable
View file @
b9dbd9ab
...
...
@@ -23,39 +23,39 @@ load_helper serv-status
# Enable service by default
serv_enable
()
{
local
SERVICE
=
"
$1
"
local
SERVICE
=
"
$1
"
is_service_autostart
$1
&&
info
"Service
$1
is already enabled for startup"
&&
return
is_service_autostart
$1
&&
info
"Service
$1
is already enabled for startup"
&&
return
case
$SERVICETYPE
in
service-chkconfig
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
on
return
fi
sudocmd chkconfig
--add
$1
||
return
sudocmd chkconfig
$1
on
;;
service-upstart
)
sudocmd chkconfig
--add
$1
||
return
sudocmd chkconfig
$1
on
;;
service-initd|service-update
)
sudocmd update-rc.d
$1
defaults
;;
systemd
)
sudocmd systemctl
enable
$1
;;
openrc
)
sudocmd rc-update add
$1
default
;;
runit
)
assure_exists
$SERVICE
[
-r
"/etc/sv/
$SERVICE
"
]
||
fatal
"Can't find /etc/sv/
$SERVICE
"
sudocmd
ln
-s
/etc/sv/
$SERVICE
/var/service/
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
on
return
fi
sudocmd chkconfig
--add
$1
||
return
sudocmd chkconfig
$1
on
;;
service-upstart
)
sudocmd chkconfig
--add
$1
||
return
sudocmd chkconfig
$1
on
;;
service-initd|service-update
)
sudocmd update-rc.d
$1
defaults
;;
systemd
)
sudocmd systemctl
enable
$1
;;
openrc
)
sudocmd rc-update add
$1
default
;;
runit
)
assure_exists
$SERVICE
[
-r
"/etc/sv/
$SERVICE
"
]
||
fatal
"Can't find /etc/sv/
$SERVICE
"
sudocmd
ln
-s
/etc/sv/
$SERVICE
/var/service/
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-exists
View file @
b9dbd9ab
...
...
@@ -19,23 +19,23 @@
serv_exists
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
systemd
)
# too direct way: test -s /lib/systemd/system/dm.service
docmd systemctl
cat
"
$SERVICE
"
"
$@
"
>
/dev/null 2>/dev/null
;;
*
)
case
$BASEDISTRNAME
in
"alt"
)
local
INITFILE
=
/etc/init.d/
$SERVICE
[
-r
"
$INITFILE
"
]
||
return
return
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
esac
case
$SERVICETYPE
in
systemd
)
# too direct way: test -s /lib/systemd/system/dm.service
docmd systemctl
cat
"
$SERVICE
"
"
$@
"
>
/dev/null 2>/dev/null
;;
*
)
case
$BASEDISTRNAME
in
"alt"
)
local
INITFILE
=
/etc/init.d/
$SERVICE
[
-r
"
$INITFILE
"
]
||
return
return
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
esac
}
bin/serv-list
View file @
b9dbd9ab
...
...
@@ -20,34 +20,34 @@
# List running services
serv_list
()
{
[
-n
"
$short
"
]
||
info
"Running services:"
case
$SERVICETYPE
in
#
service-chkconfig)
#
;;
service-upstart
)
sudocmd initctl list
;;
service-update
)
sudocmd service
--status-all
;;
systemd
)
if
[
-n
"
$short
"
]
;
then
docmd systemctl list-units
--type
=
service
"
$@
"
|
grep
'\.service'
|
sed
-e
's|\.service.*||'
-e
's|^ *||'
else
docmd systemctl list-units
--type
=
service
"
$@
"
fi
;;
openrc
)
sudocmd rc-status
;;
*
)
# hack to improve list speed
[
"
$UID
"
=
0
]
||
{
sudocmd
$PROGDIR
/serv
--quiet
list
;
return
;
}
load_helper serv-list_all
load_helper serv-status
for
i
in
$(
quiet
=
1 serv_list_all
)
;
do
is_service_running
$i
>
/dev/null
&&
echo
$i
done
;;
esac
[
-n
"
$short
"
]
||
info
"Running services:"
case
$SERVICETYPE
in
#
service-chkconfig)
#
;;
service-upstart
)
sudocmd initctl list
;;
service-update
)
sudocmd service
--status-all
;;
systemd
)
if
[
-n
"
$short
"
]
;
then
docmd systemctl list-units
--type
=
service
"
$@
"
|
grep
'\.service'
|
sed
-e
's|\.service.*||'
-e
's|^ *||'
else
docmd systemctl list-units
--type
=
service
"
$@
"
fi
;;
openrc
)
sudocmd rc-status
;;
*
)
# hack to improve list speed
[
"
$UID
"
=
0
]
||
{
sudocmd
$PROGDIR
/serv
--quiet
list
;
return
;
}
load_helper serv-list_all
load_helper serv-status
for
i
in
$(
quiet
=
1 serv_list_all
)
;
do
is_service_running
$i
>
/dev/null
&&
echo
$i
done
;;
esac
}
bin/serv-list_all
View file @
b9dbd9ab
...
...
@@ -20,47 +20,47 @@
# List all available services
serv_list_all
()
{
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
[
-n
"
$short
"
]
;
then
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig
--list
|
cut
-f1
|
grep
-v
"^$"
|
grep
-v
"xinetd:$"
|
cut
-f
1
-d
" "
else
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig
--list
|
cut
-f1
|
grep
-v
"^$"
|
grep
-v
"xinetd:$"
fi
if
[
-n
"
$ANYSERVICE
"
]
;
then
if
[
-n
"
$short
"
]
;
then
sudocmd anyservice
--quiet
list |
cut
-f
1
-d
" "
else
sudocmd anyservice
--quiet
list
fi
return
fi
;;
service-initd|service-update
)
if
[
-n
"
$short
"
]
;
then
sudocmd
ls
$INITDIR
/ |
grep
-v
README |
cut
-f
1
-d
" "
else
sudocmd
ls
$INITDIR
/ |
grep
-v
README
fi
;;
systemd
)
if
[
-n
"
$short
"
]
;
then
docmd systemctl list-unit-files
--type
=
service
"
$@
"
|
sed
-e
's|\.service.*||'
|
grep
-v
'unit files listed'
|
grep
-v
'^$'
else
docmd systemctl list-unit-files
--type
=
service
"
$@
"
fi
;;
openrc
)
if
[
-n
"
$short
"
]
;
then
sudocmd rc-service
-l
|
cut
-f
1
-d
" "
else
sudocmd rc-service
-l
fi
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
[
-n
"
$short
"
]
;
then
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig
--list
|
cut
-f1
|
grep
-v
"^$"
|
grep
-v
"xinetd:$"
|
cut
-f
1
-d
" "
else
# service --status-all for Ubuntu/Fedora
sudocmd chkconfig
--list
|
cut
-f1
|
grep
-v
"^$"
|
grep
-v
"xinetd:$"
fi
if
[
-n
"
$ANYSERVICE
"
]
;
then
if
[
-n
"
$short
"
]
;
then
sudocmd anyservice
--quiet
list |
cut
-f
1
-d
" "
else
sudocmd anyservice
--quiet
list
fi
return
fi
;;
service-initd|service-update
)
if
[
-n
"
$short
"
]
;
then
sudocmd
ls
$INITDIR
/ |
grep
-v
README |
cut
-f
1
-d
" "
else
sudocmd
ls
$INITDIR
/ |
grep
-v
README
fi
;;
systemd
)
if
[
-n
"
$short
"
]
;
then
docmd systemctl list-unit-files
--type
=
service
"
$@
"
|
sed
-e
's|\.service.*||'
|
grep
-v
'unit files listed'
|
grep
-v
'^$'
else
docmd systemctl list-unit-files
--type
=
service
"
$@
"
fi
;;
openrc
)
if
[
-n
"
$short
"
]
;
then
sudocmd rc-service
-l
|
cut
-f
1
-d
" "
else
sudocmd rc-service
-l
fi
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-list_failed
View file @
b9dbd9ab
...
...
@@ -19,25 +19,25 @@
serv_list_failed
()
{
case
$SERVICETYPE
in
#
service-chkconfig|service-upstart)
#
# service --status-all for Ubuntu/Fedora
#
#sudocmd chkconfig --list | cut -f1
#
;;
#
service-initd|service-update)
#
sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README
#
;;
systemd
)
sudocmd systemctl
--failed
;;
*
)
load_helper serv-list_startup
load_helper serv-status
for
i
in
$(
short
=
1 serv_list_startup
)
;
do
is_service_running
>
/dev/null
$i
&&
continue
echo
;
echo
$i
serv_status
$i
done
;;
esac
case
$SERVICETYPE
in
#
service-chkconfig|service-upstart)
#
# service --status-all for Ubuntu/Fedora
#
#sudocmd chkconfig --list | cut -f1
#
;;
#
service-initd|service-update)
#
sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README
#
;;
systemd
)
sudocmd systemctl
--failed
;;
*
)
load_helper serv-list_startup
load_helper serv-status
for
i
in
$(
short
=
1 serv_list_startup
)
;
do
is_service_running
>
/dev/null
$i
&&
continue
echo
;
echo
$i
serv_status
$i
done
;;
esac
}
bin/serv-list_startup
View file @
b9dbd9ab
...
...
@@ -19,27 +19,27 @@
serv_list_startup
()
{
load_helper serv-list_all
load_helper serv-status
case
$SERVICETYPE
in
#
service-chkconfig|service-upstart)
#
# service --status-all for Ubuntu/Fedora
#
#sudocmd chkconfig --list | cut -f1
#
;;
#
service-initd|service-update)
#
sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README
#
;;
systemd
)
#sudocmd systemctl list-unit-files
# TODO: native command? implement --short for list (only names)
for
i
in
$(
short
=
1 serv_list_all
)
;
do
is_service_autostart
>
/dev/null 2>/dev/null
$i
&&
echo
$i
done
;;
*
)
for
i
in
$(
short
=
1 serv_list_all
)
;
do
is_service_autostart
>
/dev/null 2>/dev/null
$i
&&
echo
$i
done
;;
esac
load_helper serv-list_all
load_helper serv-status
case
$SERVICETYPE
in
#
service-chkconfig|service-upstart)
#
# service --status-all for Ubuntu/Fedora
#
#sudocmd chkconfig --list | cut -f1
#
;;
#
service-initd|service-update)
#
sudocmd ls -1 /etc/init.d/* | sed -e "s|/etc/init.d/||g" | grep -v README
#
;;
systemd
)
#sudocmd systemctl list-unit-files
# TODO: native command? implement --short for list (only names)
for
i
in
$(
short
=
1 serv_list_all
)
;
do
is_service_autostart
>
/dev/null 2>/dev/null
$i
&&
echo
$i
done
;;
*
)
for
i
in
$(
short
=
1 serv_list_all
)
;
do
is_service_autostart
>
/dev/null 2>/dev/null
$i
&&
echo
$i
done
;;
esac
}
bin/serv-log
View file @
b9dbd9ab
...
...
@@ -19,47 +19,47 @@
__serv_log_altlinux
()
{
local
SERVICE
=
"
$1
"
local
PRG
=
"less"
[
"
$2
"
=
"-f"
]
&&
PRG
=
"tail -f"
local
SERVICE
=
"
$1
"
local
PRG
=
"less"
[
"
$2
"
=
"-f"
]
&&
PRG
=
"tail -f"
case
"
$SERVICE
"
in
postfix
)
sudocmd
$PRG
/var/log/mail/all /var/log/mail/errors
;;
sshd
)
sudocmd
$PRG
/var/log/auth/all
;;
cups
)
sudocmd
$PRG
/var/log/cups/access_log /var/log/cups/error_log
;;
fail2ban
)
sudocmd
$PRG
/var/log/
$SERVICE
.log
;;
*
)
fatal
"Have no suitable for
$SERVICE
service"
;;
esac
case
"
$SERVICE
"
in
postfix
)
sudocmd
$PRG
/var/log/mail/all /var/log/mail/errors
;;
sshd
)
sudocmd
$PRG
/var/log/auth/all
;;
cups
)
sudocmd
$PRG
/var/log/cups/access_log /var/log/cups/error_log
;;
fail2ban
)
sudocmd
$PRG
/var/log/
$SERVICE
.log
;;
*
)
fatal
"Have no suitable for
$SERVICE
service"
;;
esac
}
serv_log
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
systemd
)
sudocmd journalctl
-b
-u
"
$SERVICE
"
"
$@
"
;;
*
)
case
$BASEDISTRNAME
in
"alt"
)
FF
=
""
;
[
"
$1
"
=
"-f"
]
&&
FF
=
"-f"
__serv_log_altlinux
"
$SERVICE
"
$FF
return
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
esac
case
$SERVICETYPE
in
systemd
)
sudocmd journalctl
-b
-u
"
$SERVICE
"
"
$@
"
;;
*
)
case
$BASEDISTRNAME
in
"alt"
)
FF
=
""
;
[
"
$1
"
=
"-f"
]
&&
FF
=
"-f"
__serv_log_altlinux
"
$SERVICE
"
$FF
return
;;
*
)
fatal
"Have no suitable for
$DISTRNAME
command for
$SERVICETYPE
"
;;
esac
esac
}
bin/serv-off
View file @
b9dbd9ab
...
...
@@ -24,9 +24,9 @@ load_helper serv-status
# Enable service by default
serv_off
()
{
local
SERVICE
=
"
$1
"
local
SERVICE
=
"
$1
"
is_service_running
$1
&&
{
serv_stop
$1
||
return
;
}
is_service_autostart
$1
||
{
info
"Service
$1
already disabled for startup"
&&
return
;
}
serv_disable
$SERVICE
is_service_running
$1
&&
{
serv_stop
$1
||
return
;
}
is_service_autostart
$1
||
{
info
"Service
$1
already disabled for startup"
&&
return
;
}
serv_disable
$SERVICE
}
bin/serv-on
View file @
b9dbd9ab
...
...
@@ -23,8 +23,8 @@ load_helper serv-status
serv_on
()
{
serv_enable
"
$1
"
||
return
# start if need
is_service_running
$1
&&
info
"Service
$1
is already running"
&&
return
serv_start
$1
serv_enable
"
$1
"
||
return
# start if need
is_service_running
$1
&&
info
"Service
$1
is already running"
&&
return
serv_start
$1
}
bin/serv-print
View file @
b9dbd9ab
...
...
@@ -19,6 +19,6 @@
serv_print
()
{
echo
"Detected init system:
$SERVICETYPE
"
[
-n
"
$ANYSERVICE
"
]
&&
echo
"anyservice is detected too"
echo
"Detected init system:
$SERVICETYPE
"
[
-n
"
$ANYSERVICE
"
]
&&
echo
"anyservice is detected too"
}
bin/serv-reload
View file @
b9dbd9ab
...
...
@@ -22,27 +22,27 @@ load_helper serv-status
# Reload service (try send SIGHUP or so on to reread config)
serv_reload
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
reload
return
fi
sudocmd service
$SERVICE
reload
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
reload
"
$@
"
;;
systemd
)
sudocmd systemctl reload
$SERVICE
"
$@
"
;;
*
)
info
"Fallback to restart..."
load_helper serv-restart
serv_restart
"
$SERVICE
"
"
$@
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
reload
return
fi
sudocmd service
$SERVICE
reload
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
reload
"
$@
"
;;
systemd
)
sudocmd systemctl reload
$SERVICE
"
$@
"
;;
*
)
info
"Fallback to restart..."
load_helper serv-restart
serv_restart
"
$SERVICE
"
"
$@
"
;;
esac
}
bin/serv-restart
View file @
b9dbd9ab
...
...
@@ -22,31 +22,31 @@ load_helper serv-status
# Restart service (start if it was not running)
serv_restart
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
restart
return
fi
sudocmd service
$SERVICE
restart
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
restart
"
$@
"
;;
systemd
)
sudocmd systemctl restart
$SERVICE
"
$@
"
;;
runit
)
sudocmd sv restart
"
$SERVICE
"
;;
openrc
)
sudocmd rc-service restart
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
restart
return
fi
sudocmd service
$SERVICE
restart
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
restart
"
$@
"
;;
systemd
)
sudocmd systemctl restart
$SERVICE
"
$@
"
;;
runit
)
sudocmd sv restart
"
$SERVICE
"
;;
openrc
)
sudocmd rc-service restart
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-start
View file @
b9dbd9ab
...
...
@@ -20,31 +20,31 @@
# Start service
serv_start
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
start
return
fi
sudocmd service
$SERVICE
start
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
start
"
$@
"
;;
systemd
)
sudocmd systemctl start
"
$SERVICE
"
"
$@
"
;;
runit
)
sudocmd sv up
"
$SERVICE
"
;;
openrc
)
sudocmd rc-service start
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
start
return
fi
sudocmd service
$SERVICE
start
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
start
"
$@
"
;;
systemd
)
sudocmd systemctl start
"
$SERVICE
"
"
$@
"
;;
runit
)
sudocmd sv up
"
$SERVICE
"
;;
openrc
)
sudocmd rc-service start
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-status
View file @
b9dbd9ab
...
...
@@ -20,91 +20,91 @@
# FIXME: sudo ask password, but we do not print command before
is_service_running
()
{
local
SERVICE
=
"
$1
"
local
OUTPUT
# TODO: real status can be checked only with grep output
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$1
;
then
OUTPUT
=
"
$(
sudorun anyservice
$1
status 2>/dev/null
)
"
||
return
1
echo
"
$OUTPUT
"
|
grep
-q
"is stopped"
&&
return
1
return
0
fi
OUTPUT
=
"
$(
sudorun service
$1
status 2>/dev/null
)
"
||
return
1
echo
"
$OUTPUT
"
|
grep
-q
"is stopped"
&&
return
1
return
0
;;
service-initd|service-update
)
sudorun
$INITDIR
/
$1
status
>
/dev/null 2>/dev/null
;;
systemd
)
a
=
''
systemctl status
$1
>
/dev/null 2>/dev/null
;;
runit
)
sudorun sv status
"
$SERVICE
"
>
/dev/null 2>/dev/null
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
local
SERVICE
=
"
$1
"
local
OUTPUT
# TODO: real status can be checked only with grep output
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$1
;
then
OUTPUT
=
"
$(
sudorun anyservice
$1
status 2>/dev/null
)
"
||
return
1
echo
"
$OUTPUT
"
|
grep
-q
"is stopped"
&&
return
1
return
0
fi
OUTPUT
=
"
$(
sudorun service
$1
status 2>/dev/null
)
"
||
return
1
echo
"
$OUTPUT
"
|
grep
-q
"is stopped"
&&
return
1
return
0
;;
service-initd|service-update
)
sudorun
$INITDIR
/
$1
status
>
/dev/null 2>/dev/null
;;
systemd
)
a
=
''
systemctl status
$1
>
/dev/null 2>/dev/null
;;
runit
)
sudorun sv status
"
$SERVICE
"
>
/dev/null 2>/dev/null
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
# FIXME: sudo ask password, but we do not print command before
is_service_autostart
()
{
local
SERVICE
=
"
$1
"
local
SERVICE
=
"
$1
"
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
$ANYSERVICE
$SERVICE
isautostarted
return
fi
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
$ANYSERVICE
$SERVICE
isautostarted
return
fi
# FIXME: check for current runlevel
LANG
=
C sudorun chkconfig
$1
--list
|
grep
-q
"[35]:on"
;;
service-initd|service-update
)
test
-L
"
$(
echo
/etc/rc5.d/S??
$1
)
"
;;
systemd
)
a
=
''
systemctl is-enabled
$1
;;
runit
)
test
-L
"/var/service/
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
# FIXME: check for current runlevel
LANG
=
C sudorun chkconfig
$1
--list
|
grep
-q
"[35]:on"
;;
service-initd|service-update
)
test
-L
"
$(
echo
/etc/rc5.d/S??
$1
)
"
;;
systemd
)
a
=
''
systemctl is-enabled
$1
;;
runit
)
test
-L
"/var/service/
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
serv_status
()
{
is_service_autostart
$1
&&
echo
"Service
$1
is scheduled to run on startup"
||
echo
"Service
$1
will NOT run on startup"
is_service_autostart
$1
&&
echo
"Service
$1
is scheduled to run on startup"
||
echo
"Service
$1
will NOT run on startup"
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
status
return
fi
sudocmd service
$SERVICE
status
"
$@
"
;;
service-update
)
sudocmd
$INITDIR
/
$SERVICE
status
"
$@
"
;;
systemd
)
docmd systemctl
-l
status
$SERVICE
"
$@
"
;;
runit
)
sudocmd sv status
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
status
return
fi
sudocmd service
$SERVICE
status
"
$@
"
;;
service-update
)
sudocmd
$INITDIR
/
$SERVICE
status
"
$@
"
;;
systemd
)
docmd systemctl
-l
status
$SERVICE
"
$@
"
;;
runit
)
sudocmd sv status
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-stop
View file @
b9dbd9ab
...
...
@@ -20,31 +20,31 @@
# Stop service
serv_stop
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
stop
return
fi
sudocmd service
$SERVICE
stop
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
stop
"
$@
"
;;
systemd
)
sudocmd systemctl stop
$SERVICE
"
$@
"
;;
runit
)
sudocmd sv down
"
$SERVICE
"
;;
openrc
)
sudocmd rc-service stop
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
if
is_anyservice
$SERVICE
;
then
sudocmd anyservice
$SERVICE
stop
return
fi
sudocmd service
$SERVICE
stop
"
$@
"
;;
service-initd|service-update
)
sudocmd
$INITDIR
/
$SERVICE
stop
"
$@
"
;;
systemd
)
sudocmd systemctl stop
$SERVICE
"
$@
"
;;
runit
)
sudocmd sv down
"
$SERVICE
"
;;
openrc
)
sudocmd rc-service stop
"
$SERVICE
"
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
}
bin/serv-test
View file @
b9dbd9ab
...
...
@@ -19,31 +19,31 @@
serv_test
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICE
in
cups|cupsd
)
docmd cupsd
-t
;;
nginx
)
docmd nginx
-t
;;
sshd
)
docmd sshd
-t
;;
httpd2|httpd|apache|apache2
)
if
is_command httpd2
;
then
docmd httpd2
-t
elif
is_command apache2
;
then
docmd apache2
-t
fi
;;
postfix
)
docmd /etc/init.d/postfix check
;;
*
)
fatal
"
$SERVICE
is not supported yet. Please report if you know how to test"
;;
esac
case
$SERVICE
in
cups|cupsd
)
docmd cupsd
-t
;;
nginx
)
docmd nginx
-t
;;
sshd
)
docmd sshd
-t
;;
httpd2|httpd|apache|apache2
)
if
is_command httpd2
;
then
docmd httpd2
-t
elif
is_command apache2
;
then
docmd apache2
-t
fi
;;
postfix
)
docmd /etc/init.d/postfix check
;;
*
)
fatal
"
$SERVICE
is not supported yet. Please report if you know how to test"
;;
esac
}
bin/serv-try_restart
View file @
b9dbd9ab
...
...
@@ -22,18 +22,18 @@ load_helper serv-status
# Try restart service (if it is running)
serv_try_restart
()
{
local
SERVICE
=
"
$1
"
shift
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
systemd
)
sudocmd systemctl try-restart
$SERVICE
"
$@
"
;;
*
)
info
"Fallback to restart..."
is_service_running
$SERVICE
||
{
info
"Service
$SERVICE
is not running, restart skipping…"
;
return
0
;
}
load_helper serv-restart
serv_restart
"
$SERVICE
"
"
$@
"
;;
esac
case
$SERVICETYPE
in
systemd
)
sudocmd systemctl try-restart
$SERVICE
"
$@
"
;;
*
)
info
"Fallback to restart..."
is_service_running
$SERVICE
||
{
info
"Service
$SERVICE
is not running, restart skipping…"
;
return
0
;
}
load_helper serv-restart
serv_restart
"
$SERVICE
"
"
$@
"
;;
esac
}
bin/serv-usage
View file @
b9dbd9ab
...
...
@@ -19,31 +19,31 @@
_print_additional_usage
()
{
echo
"serv addition usage: {on|off|try-restart|usage}"
echo
"serv addition usage: {on|off|try-restart|usage}"
}
# Print usage of the service
serv_usage
()
{
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
# CHECKME: many services print out usage in stderr, it conflicts with printout command
#sudocmd service $SERVICE 2>&1
sudorun service
$SERVICE
2>&1
;;
service-initd|service-update
)
#sudocmd /etc/init.d/$SERVICE 2>&1
sudorun service
$SERVICE
2>&1
;;
systemd
)
sudocmd systemctl
$SERVICE
2>&1
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
local
SERVICE
=
"
$1
"
shift
case
$SERVICETYPE
in
service-chkconfig|service-upstart
)
# CHECKME: many services print out usage in stderr, it conflicts with printout command
#sudocmd service $SERVICE 2>&1
sudorun service
$SERVICE
2>&1
;;
service-initd|service-update
)
#sudocmd /etc/init.d/$SERVICE 2>&1
sudorun service
$SERVICE
2>&1
;;
systemd
)
sudocmd systemctl
$SERVICE
2>&1
;;
*
)
fatal
"Have no suitable command for
$SERVICETYPE
"
;;
esac
_print_additional_usage
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment