#1 Le 12/09/2008, à 15:41
- Astroman
[Résolu] Script Start/Stop Apache + SQL
Bonjour,
J'ai installer un serveur Apache et une base de données SQL pour faire mes développements PHP en local.
Je voudrais créer un tout petit script pour allumer et éteindre Apache et MYSQL à ma guise en saisissant simplement start ou stop dans mon terminal après avoir lancé mon script.
Pour le faire j'utilise actuellement les commandes si dessous dans un terminal :
Start :
sudo /etc/init.d/apache2 start
sudo /etc/init.d/mysql start
Stop :
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/mysql stop
Comment est-ce que je peut faire? Quel langage utiliser?
Merci
Mon site Web - Passion Astro & Météo
Dernière modification par Astroman (Le 13/09/2008, à 10:35)
Astroman o O o Ubuntu 12.04 LTS
Un problème résolu ? Indiquez le en modifiant le titre du sujet ;)
Hors ligne
#2 Le 12/09/2008, à 16:26
- beudbeud
Re : [Résolu] Script Start/Stop Apache + SQL
j'avais développé un petit script pour ça
#!/bin/bash
#script par Beudbeud
##définition des fonctions status
#ssh
status_ssh()
{
ps -A | grep ssh >/dev/null 2>&1
if (test $? -eq 1); then
SSH=`echo arrété`
else SSH=`echo démarré`
fi
}
#apache2
status_apache()
{
ps -A | grep apache >/dev/null 2>&1
if (test $? -eq 1); then
APACHE=`echo arrété`
else APACHE=`echo démarré`
fi
}
#mysql
status_mysql()
{
ps -A | grep mysql >/dev/null 2>&1
if (test $? -eq 1); then
MYSQL=`echo arrété`
else MYSQL=`echo démarré`
fi
}
#samba
status_samba()
{
ps -A | grep smbd >/dev/null 2>&1
if (test $? -eq 1); then
SAMBA=`echo arrété`
else SAMBA=`echo démarré`
fi
}
#bluetooth
status_bluetooth()
{
ps -A | grep bluetooth >/dev/null 2>&1
if (test $? -eq 1); then
BLUE=`echo arrété`
else BLUE=`echo démarré`
fi
}
##récupération status
status_ssh
status_mysql
status_apache
status_samba
status_bluetooth
## Affichage de la liste des services
ACT=$(zenity --list --checklist --width=300 --height=233 \
--title "Services" \
--text="Quel service doit etre démarré ou redemarré ?" \
--column="Selection" --column="Services" --column="Status"\
FALSE "ssh" `echo $SSH`\
TRUE "apache" `echo $APACHE`\
TRUE "mysql" `echo $MYSQL`\
FALSE "samba" `echo $SAMBA`\
FALSE "bluetooth" `echo $BLUE`\
);
if [ "${PIPESTATUS[0]}" != "0" ]; then
exit
fi
##selection des services
# ssh
echo "$ACT" | grep "ssh" >/dev/null
if [ "$?" = 0 ] ; then
ps -A | grep ssh >/dev/null 2>&1
if (test $? -eq 1); then
gksudo '/etc/init.d/ssh start'
else gksudo '/etc/init.d/ssh stop'
fi
fi
# apache2
echo "$ACT" | grep "apache" >/dev/null
if [ "$?" = 0 ] ; then
ps -A | grep apache >/dev/null 2>&1
if (test $? -eq 1); then
gksudo '/etc/init.d/apache2 start'
else gksudo '/etc/init.d/apache2 stop'
fi
fi
# mysql
echo "$ACT" | grep "mysql" >/dev/null
if [ "$?" = 0 ] ; then
ps -A | grep mysql >/dev/null 2>&1
if (test $? -eq 1); then
gksu '/etc/init.d/mysql start'
else gksudo '/etc/init.d/mysql stop'
fi
fi
# samba
echo "$ACT" | grep "samba" >/dev/null
if [ "$?" = 0 ] ; then
ps -A | grep smbd >/dev/null 2>&1
if (test $? -eq 1); then
gksudo '/etc/init.d/samba start'
else gksudo '/etc/init.d/samba stop'
fi
fi
# bluetooth
echo "$ACT" | grep "bluetooth" >/dev/null
if [ "$?" = 0 ] ; then
ps -A | grep bluetooth >/dev/null 2>&1
if (test $? -eq 1); then
gksudo '/etc/init.d/bluetooth start'
bluetooth-applet --singleton
else gksudo '/etc/init.d/samba stop'
killall bluetooth-applet
fi
fi
##récupération status
status_ssh
status_mysql
status_apache
status_samba
status_bluetooth
##récapitulatif
zenity --list --width=250 --height=233 \
--title "Récapitulatif" \
--text="Nouveau status des services" \
--column="Services" --column="Status"\
"ssh" `echo $SSH`\
"apache" `echo $APACHE`\
"mysql" `echo $MYSQL`\
"samba" `echo $SAMBA`\
"bluetooth" `echo $BLUE`\
Télécharger les émissions de Arte +7 avec Arte +7 recorder
Theme pour Ubuntu Bisigi Project
Vostro 1510 Ubuntu 10.04
Hors ligne
#3 Le 12/09/2008, à 16:47
- Astroman
Re : [Résolu] Script Start/Stop Apache + SQL
#hehedotcom\'isback : Ton idée me conduit aux alias, un petit tour dans la doc http://doc.ubuntu-fr.org/alias et je recherche le fichier .bashrc dans ma $HOME mais rien en vue.
Comment est-ce que je peut le créer ?
Je suis sous Ubuntu 8.04
beudbeud : Où est-ce que j peut insérer ton script ?
Merci pour vos réponses
Astroman o O o Ubuntu 12.04 LTS
Un problème résolu ? Indiquez le en modifiant le titre du sujet ;)
Hors ligne
#4 Le 12/09/2008, à 18:03
- rniamo
Re : [Résolu] Script Start/Stop Apache + SQL
s'il n'y est pas créé le, pour info le mieux est :
#!/bin/bash
# based on a function found in bashtstyle-ng 5.0b1
# Original author Christopher Roy Bratusek (http://www.nanolx.org)
# Last modified by ayoli (http://ayozone.org) 2008-02-04 17:16:43 +0100 CET
function pre_prompt {
newPWD="${PWD}"
user="whoami"
host=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
datenow=$(date "+%a, %d %b %y")
let promptsize=$(echo -n "\n--($user@$host ddd, DD mmm YY dd mm YY)---(${PWD})---" \
| wc -c | tr -d " ")
let fillsize=${COLUMNS}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}—"
let fillsize=${fillsize}-1
done
if [ "$fillsize" -lt "0" ]
then
let cutt=3-${fillsize}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cutt\}\)\(.*\)/\2/")"
fi
}
PROMPT_COMMAND=pre_prompt
export black="\[\033[0;38;5;0m\]"
export red="\[\033[0;38;5;1m\]"
export green="\[\033[0;38;5;2m\]"
export yellow="\[\033[0;38;5;3m\]"
export blue="\[\033[0;38;5;4m\]"
export magenta="\[\033[0;38;5;55m\]"
export cyan="\[\033[0;38;5;6m\]"
export white="\[\033[0;38;5;7m\]"
export coldblue="\[\033[0;38;5;33m\]"
export smoothblue="\[\033[0;38;5;111m\]"
export iceblue="\[\033[0;38;5;45m\]"
export turqoise="\[\033[0;38;5;50m\]"
export smoothgreen="\[\033[0;38;5;42m\]"
PS1="$green┌─($coldblue\u@\h \$(date \"+%a, %d %b %y\") \$(date \"+%H:%M:%Y\")$green)─\${fill}─($coldblue\$newPWD$green)────
$green└──>$white "
# bash_history settings: size and no duplicates and no lines w/ lead spaces
exportHISTCONTROL="ignoreboth"
export HISTSIZE=2048
# aliases #############################################
# enable color support of ls and also add handy aliases
eval `dircolors -b`
alias ls='ls --color=auto'
alias dir='ls --color=auto --format=vertical'
alias vdir='ls --color=auto --format=long'
# some more ls aliases
alias ll='ls -lhX'
alias la='ls -A'
alias ldir='ls -lhA |grep ^d'
alias lfiles='ls -lhA |grep ^-'
#alias l='ls -CF'
# To see something coming into ls output: lss
alias lss='ls -lrt | grep $1'
# To check a process is running in a box with a heavy load: pss
alias pss='ps -ef | grep $1'
# usefull alias to browse your filesystem for heavy usage quickly
alias ducks='ls -A | grep -v -e '\''^\.\.$'\'' |xargs -i du -ks {} |sort -rn |head -16 | awk '\''{print $2}'\'' | xargs -i du -hs {}'
# cool colors for manpages
alias man="TERMINFO=~/.terminfo TERM=mostlike LESS=C PAGER=less man"
##########################################################
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
Ajoute les fonctions que tu veux dedans et créé toi un alias si besoin.
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#5 Le 12/09/2008, à 19:19
- beudbeud
Re : [Résolu] Script Start/Stop Apache + SQL
donc on crée un répertoire script
mkdir script
on édite le script
gedit service
la tu colle le script
on sauvegarde et ferme gedit
on rajoute l'exécution
chmod +x script/service
ensuite clic droit sur le tableau de bord et faire lanceur d'application personnalisé
la tu met le nom que tu veux et tu fait parcourir et tu va cherché le script dans le dossier script
et pour finir validé
Dernière modification par beudbeud (Le 12/09/2008, à 19:20)
Télécharger les émissions de Arte +7 avec Arte +7 recorder
Theme pour Ubuntu Bisigi Project
Vostro 1510 Ubuntu 10.04
Hors ligne
#6 Le 12/09/2008, à 19:29
- rniamo
Re : [Résolu] Script Start/Stop Apache + SQL
pas mal en console comme solution (si c'est pour un serveur)
< Quelques un des mes programmes | Cuisine Facile (pour les gourmands) | Fast MVC for PHP >
\ ^__^
\ (o o)\_______
(___)\ )\
Hors ligne
#7 Le 13/09/2008, à 10:35
- Astroman
Re : [Résolu] Script Start/Stop Apache + SQL
Merci a vous 2,
beudbeud : le script marche bien.
rniamo :je vais approfondir l'utilisation des alias.
Post résolu !!
Astroman o O o Ubuntu 12.04 LTS
Un problème résolu ? Indiquez le en modifiant le titre du sujet ;)
Hors ligne
#8 Le 16/02/2009, à 15:34
- Kazuyo
Re : [Résolu] Script Start/Stop Apache + SQL
edit: hum trompé de topic désolé...
Dernière modification par Kazuyo (Le 16/02/2009, à 15:35)
Hors ligne