View previous topic :: View next topic |
Author |
Message |
bibi.skuk Guru
Joined: 01 Aug 2005 Posts: 425
|
Posted: Thu Nov 24, 2005 12:18 pm Post subject: [doc]script init, liste des fonctions disponibles |
|
|
Après quelques recherches, j'ai constaté que les fonctions utilisables dans les scripts d'init n'etait pas toutes documentées... je vais essayer de reparer cet oubli.
Ce document est dédié a tout ceux qui veulent faire des scripts d'init ( /etc/init.d/* ). Il n'est pas complet, mais je vais essayer d'y ajouter tout ce que je peux au fur et a mesure.
Voici une liste de ce que j'ai pu trouver pour le moment.
/sbin/functions.sh
Ici se trouvent une bonne partie des fonctions pratiques... en voici une liste, avec le commentaire qui les accompagne (en anglais dans un premier temps, je ferai les traductions/test/exemple par la suite).
Code: | void import_addon(char *addon) |
Import code from the specified addon if it exists
Notify bootsplash/splashutils/gensplash/whatever about
important events.
This will override the splash() function...
Code: | void profiling(...) |
Notify bootsplash/whatever about important events.
Notify bootlogger about important events.
Code: | void get_bootconfig() |
Get the BOOTLEVEL and SOFTLEVEL by setting
'bootlevel' and 'softlevel' via kernel
parameters.
Code: | void get_libdir(void) |
prints the current libdir {lib,lib32,lib64}
Code: | void esyslog(char* priority, char* tag, char* message) |
use the system logger to log a message
Code: | void eindent(int num) |
increase the indent used for e-commands.
Code: | void eoutdent(int num) |
decrease the indent used for e-commands.
Code: | void esetdent(int num) |
hard set the indent used for e-commands.
num defaults to 0
Code: | void einfo(char* message) |
show an informative message (with a newline)
Code: | void einfon(char* message) |
show an informative message (without a newline)
Code: | void ewarn(char* message) |
show a warning message + log it
Log warnings to system log
Code: | void eerror(char* message) |
show an error message + log it
Log errors to system log
Code: | void ebegin(char* message) |
show a message indicating the start of a process
Code: | void _eend(int error, char *efunc, char* errstr) |
indicate the completion of process, called from eend/ewend
if error, show errstr via efunc
This function is private to functions.sh. Do not call it from a
script.
Code: | void eend(int error, char* errstr) |
indicate the completion of process
if error, show errstr via eerror
Code: | void ewend(int error, char* errstr) |
indicate the completion of process
if error, show errstr via ewarn
v-e-commands honor RC_VERBOSE which defaults to no.
The condition is negated so the return value will be zero.
Code: | char *KV_major(string) |
Return the Major (X of X.Y.Z) kernel version
Code: | char *KV_minor(string) |
Return the Minor (Y of X.Y.Z) kernel version
Code: | char *KV_micro(string) |
Return the Micro (Z of X.Y.Z) kernel version.
Code: | int KV_to_int(string) |
Convert a string type kernel version (2.4.0) to an int (132096)
for easy compairing or versions ...
We make version 2.2.0 the minimum version we will handle as
a sanity check ... if its less, we fail ...
Return the kernel version (major, minor and micro concated) as an integer.
Assumes X and Y of X.Y.Z are numbers. Also assumes that some leading
portion of Z is a number.
e.g. 2.4.25, 2.6.10, 2.6.4-rc3, 2.2.40-poop, 2.0.15+foo
Code: | bool get_bootparam(param) |
return 0 if gentoo=param was passed to the kernel
EXAMPLE: if get_bootparam "nodevfs" ; then ....
Parse gentoo option
echo "YES"
Safer way to list the contents of a directory,
as it do not have the "empty dir bug".
Code: | char *dolisting(param) |
print a list of the directory contents
NOTE: quote the params if they contain globs.
also, error checking is not that extensive ...
Code: | void save_options(char *option, char *optstring) |
save the settings ("optstring") for "option"
Code: | char *get_options(char *option) |
get the "optstring" for "option" that was saved
by calling the save_options function
Code: | char *add_suffix(char * configfile) |
Returns a config file name with the softlevel suffix
appended to it. For use with multi-config services.
Code: | char *get_base_ver() |
get the version of baselayout that this system is running
Network filesystems list for common use in rc-scripts.
This variable is used in is_net_fs and other places such as
localmount.
Code: | bool is_net_fs(path) |
return 0 if path is the mountpoint of a networked filesystem
EXAMPLE: if is_net_fs / ; then ...
/proc/mounts is always accurate but may not always be available
return 0 if the currently running system is User Mode Linux
EXAMPLE: if is_uml_sys ; then ...
Code: | bool is_vserver_sys() |
return 0 if the currently running system is a Linux VServer
EXAMPLE: if is_vserver_sys ; then ...
return 0 if the currently running system is an unprivileged Xen domain
EXAMPLE: if is_xenU_sys ; then ...
Code: | bool get_mount_fstab(path) |
return the parameters to pass to the mount command generated from fstab
EXAMPLE: cmd=$( get_mount_fstab /proc )
cmd=${cmd:--t proc none /proc}
mount -n ${cmd}
Code: | char *reverse_list(list) |
Returns the reversed order of list
Code: | void start_addon(addon) |
Starts addon.
Code: | void start_volumes() |
Starts all volumes in RC_VOLUME_ORDER.
Code: | void stop_addon(addon) |
Stops addon.
Code: | void stop_volumes() |
Stops all volumes in RC_VOLUME_ORDER (reverse order).
Code: | bool is_older_than(reference, files/dirs to check) |
return 0 if any of the files/dirs are newer than
the reference file
EXAMPLE: if is_older_than a.out *.o ; then ...
Code: | char* bash_variable(char *variable) |
Turns the given variable into something that bash can use
Basically replaces anything not a-z,A-Z into a _
Requotes params so they're suitable to be eval'd, just like this would:
set -- 1 2 "3 4"
/usr/bin/getopt -- '' "$@" | sed 's/^ -- //'
/sbin/runscript.sh
Les fonctions interessantes de /sbin/runscript.sh sont les suivantes :
- svc_start : execute la fonction start definie dans le fichier /etc/init.d/*
- svc_restart : execute la fonction restart definie dans ce même fichier. Le comportement par defaut de cette fonction est le suivant:
Code: |
svc_restart() {
if ! service_stopped "${myservice}" ; then
svc_stop || return "$?"
fi
svc_start || return "$?"
}
|
en gros, a moins de vouloir avoir quelque chose de special dans la focntion restart, il ne sert a rien de la preciser.
svc_status : renvoie le statut du service :
inactive|starting|started|stopping|stopped
avec des couleurs delon le statut...
svc_homegrown : permet d'executer une fonction definie par l'utilisateur. par exemple :
Code: |
foo() {
einfo "toto"
}
start() {
svc_homegrown( foo ) #execute la fonction foo()
}
|
Voila, c'est tout pour le moment...
A venir : les fonctions de runscript.sh et des rc-*.sh...
Pour plus d'information sur les init script :
http://www.gentoo.org/doc/fr/handbook/handbook-x86.xml?part=2&chap=4
Suggestion, commentaire et lettres d'insultes appréciées... |
|
Back to top |
|
|
Enlight Advocate
Joined: 28 Oct 2004 Posts: 3519 Location: Alsace (France)
|
Posted: Thu Nov 24, 2005 8:19 pm Post subject: |
|
|
Heu... chez moi /sbin/functions.sh c'est du shellscript. |
|
Back to top |
|
|
bibi.skuk Guru
Joined: 01 Aug 2005 Posts: 425
|
Posted: Thu Nov 24, 2005 10:20 pm Post subject: |
|
|
Enlight wrote: | Heu... chez moi /sbin/functions.sh c'est du shellscript. |
Oui, c'est du shell script, mais c'est documenté comme ca... de maniere a savoir a peu pres comment on s'en sert... |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|