2003-08-06 00:35:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: localpkg
|
|
|
|
# REQUIRE: abi
|
|
|
|
# BEFORE: securelevel
|
|
|
|
# KEYWORD: FreeBSD shutdown
|
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="localpkg"
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
_arg1="$1"
|
2003-08-06 00:35:13 +00:00
|
|
|
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
# script_is_rcd script
|
|
|
|
# Checks that script is an rc.d style script.
|
|
|
|
# Returns 0 if it is, otherwise, it returns 1.
|
|
|
|
#
|
|
|
|
script_is_rcd()
|
2003-08-06 00:35:13 +00:00
|
|
|
{
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
local _s match
|
|
|
|
_s="$1"
|
|
|
|
|
|
|
|
[ -z "$_s" ] && return 1
|
2004-07-27 16:59:35 +00:00
|
|
|
match=`grep -I -c -m1 '^# PROVIDE:' "$_s" 2> /dev/null`
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
[ "$match" = "1" ] && return 0
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# cooked_scriptlist type
|
|
|
|
# Uses values from rc.conf(5) to prepare a list of scripts to
|
|
|
|
# execute. It assumes the global variable script_name_sep and IFS are set
|
|
|
|
# properly. If type is set to the string "rcd" the list will contain only
|
|
|
|
# rc.d style scripts and they will be ordered according to thier
|
|
|
|
# dependencies. If it is set to "rcOG" then it will contain
|
|
|
|
# only old style ports startup scripts. The list is echoed on stdout.
|
|
|
|
#
|
|
|
|
cooked_scriptlist()
|
|
|
|
{
|
|
|
|
local _type slist fpattern skip
|
|
|
|
|
|
|
|
slist=""
|
|
|
|
_type="$1"
|
|
|
|
case "$_type" in
|
|
|
|
rcd)
|
|
|
|
fpattern="*"
|
|
|
|
;;
|
|
|
|
rcOG)
|
|
|
|
fpattern="*.sh"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
for dir in ${local_startup}; do
|
|
|
|
if [ -d "${dir}" ]; then
|
|
|
|
for script in ${dir}/${fpattern}; do
|
|
|
|
|
|
|
|
# Weed out scripts that don't belong in the
|
|
|
|
# category that we are preparing.
|
|
|
|
#
|
|
|
|
if [ "$_type" = "rcd" ]; then
|
|
|
|
case "$script" in
|
|
|
|
*.sample|*-dist)
|
|
|
|
continue;;
|
|
|
|
esac
|
|
|
|
script_is_rcd "$script" || continue
|
|
|
|
else
|
|
|
|
script_is_rcd "$script" && continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
slist="${slist}${script_name_sep}${script}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# If this is an rc.d list put the scripts in the right order.
|
2003-08-06 00:35:13 +00:00
|
|
|
#
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
if [ "$_type" = "rcd" ]; then
|
|
|
|
skip="-s nostart"
|
|
|
|
[ `/sbin/sysctl -n security.jail.jailed` -eq 1 ] && \
|
|
|
|
skip="$skip -s nojail"
|
|
|
|
|
|
|
|
# Some scripts do not define a FreeBSD keyword, so we can't
|
|
|
|
# specify it in a keep list.
|
|
|
|
slist=`/sbin/rcorder ${skip} ${slist} 2>/dev/null`
|
|
|
|
|
|
|
|
# Substitute the newlines used by rcorder(8) with the
|
|
|
|
# script separator.
|
|
|
|
slist=`echo $slist | /usr/bin/tr "\n" "$script_name_sep"`
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n $slist
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_start()
|
|
|
|
{
|
|
|
|
local slist
|
|
|
|
|
2003-08-06 00:35:13 +00:00
|
|
|
case ${local_startup} in
|
|
|
|
[Nn][Oo] | '')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
slist=""
|
|
|
|
if [ -z "${script_name_sep}" ]; then
|
|
|
|
script_name_sep=" "
|
|
|
|
fi
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
|
|
|
|
# Do rc.d style scripts.
|
|
|
|
#
|
|
|
|
script_save_sep="$IFS"
|
|
|
|
IFS="${script_name_sep}"
|
|
|
|
slist=`cooked_scriptlist rcd`
|
|
|
|
debug "localpkg rc.d scripts: $slist"
|
|
|
|
for script in ${slist}; do
|
|
|
|
run_rc_script "$script" "$_arg1"
|
2003-08-06 00:35:13 +00:00
|
|
|
done
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
IFS="${script_save_sep}"
|
|
|
|
|
|
|
|
# Do old-style ports startup scripts.
|
|
|
|
#
|
|
|
|
echo -n 'Local package initialization:'
|
2003-08-06 00:35:13 +00:00
|
|
|
script_save_sep="$IFS"
|
|
|
|
IFS="${script_name_sep}"
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
slist=`cooked_scriptlist rcOG`
|
|
|
|
debug "localpkg rcOG scripts: $slist"
|
2003-08-06 00:35:13 +00:00
|
|
|
for script in ${slist}; do
|
|
|
|
if [ -x "${script}" ]; then
|
|
|
|
(set -T
|
|
|
|
trap 'exit 1' 2
|
|
|
|
${script} start)
|
|
|
|
elif [ -f "${script}" -o -L "${script}" ]; then
|
|
|
|
echo -n " (skipping ${script##*/}, not executable)"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
IFS="${script_save_sep}"
|
|
|
|
echo '.'
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
pkg_stop()
|
|
|
|
{
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
local slist
|
2003-08-06 00:35:13 +00:00
|
|
|
|
|
|
|
# For each dir in $local_startup, search for init scripts matching *.sh
|
|
|
|
case ${local_startup} in
|
|
|
|
[Nn][Oo] | '')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -z "${script_name_sep}" ]; then
|
|
|
|
script_name_sep=" "
|
|
|
|
fi
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
|
|
|
|
# Do old-style scripts
|
|
|
|
#
|
2003-08-06 00:35:13 +00:00
|
|
|
script_save_sep="$IFS"
|
|
|
|
IFS="${script_name_sep}"
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
slist=`cooked_scriptlist rcOG`
|
|
|
|
debug "localpkg rcOG scripts: $slist"
|
|
|
|
echo -n 'Shutting down local packages:'
|
2003-08-06 00:35:13 +00:00
|
|
|
for script in `reverse_list ${slist}`; do
|
|
|
|
if [ -x "${script}" ]; then
|
|
|
|
(set -T
|
|
|
|
trap 'exit 1' 2
|
|
|
|
${script} stop)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
IFS="${script_save_sep}"
|
|
|
|
echo '.'
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
|
|
|
|
# Do rc.d style scripts
|
|
|
|
#
|
|
|
|
script_save_sep="$IFS"
|
|
|
|
IFS="${script_name_sep}"
|
|
|
|
slist=`cooked_scriptlist rcd`
|
|
|
|
debug "localpkg rc.d scripts: $slist"
|
|
|
|
for script in `reverse_list ${slist}`; do
|
|
|
|
run_rc_script "$script" $_arg1
|
|
|
|
done
|
2003-08-06 00:35:13 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
Ports related rc.d cleanups:
o Separate out local (ports) scripts that use rc.d, and the old style
startup/shutdown scripts and execute them separately. On startup the
rc.d style scripts are executed first and then the old-style scripts.
On shutdown, exactly the reverse happens.
o The rc.d ports scripts should now behave more like base system scripts.
Scripts ending in .sh will be sourced into the current shell, while the
rest will be executed in a subshell. Previously, all ports scripts,
regardless of the .sh suffix, were executed in a subshell.
o The parent script, /etc/rc.d/localpkg, passes its command line arguments
straight to the rc.d ports scripts. This means they should now honor
faststop and faststart commands as well. Old style scripts, should not see
any differences. They will still get either a start or stop command.
o The initial phrase shown during shutdown has been changed to use
"local packages" instead of "daemon processes" to be more inline with the
phrase used during local package startup. The phrases are also used only for
old-style ports script startup/shutdown, whereas previously they were being
used for both rc.d and old-style scripts. This should make startup/shutdown
output a bit less ugly.
Discussed with: portmgr
Has Reservations: eik
2004-07-24 14:56:21 +00:00
|
|
|
|
|
|
|
# We can't use the normal rc.subr(8) start/stop plumbing
|
|
|
|
# because we call run_rc_script(), which unsets all the
|
|
|
|
# global variables that said plumbing needs.
|
|
|
|
#
|
|
|
|
case "$1" in
|
|
|
|
start|faststart)
|
|
|
|
pkg_start
|
|
|
|
;;
|
|
|
|
stop|faststop)
|
|
|
|
pkg_stop
|
|
|
|
;;
|
|
|
|
restart|fastrestart)
|
|
|
|
pkg_stop
|
|
|
|
pkg_start
|
|
|
|
;;
|
|
|
|
esac
|