Batchuri pornire, restart, stop

Discutii despre tot ce nu se incadreaza in celelalte categorii.

Moderators: Moderatori ajutatori, Moderatori

smileye
Fost moderator
Fost moderator
Posts: 4648
Joined: 12 Jun 2012, 15:18
Detinator Steam: Da
Reputatie: Fost moderator
Has thanked: 258 times
Been thanked: 38 times
Contact:

17 Jan 2014, 17:03

Are cineva niste batchuri pentru a porni/restarta/opri un server anume pentru debian ?
RoyalServer 2
Clint
Membru, skill +2
Membru, skill +2
Posts: 550
Joined: 31 Mar 2013, 15:18
Detinator Steam: Da
Has thanked: 35 times
Been thanked: 21 times

17 Jan 2014, 20:27

Ce server?

Foloseste un editor (ex: nano):

Code: Select all

sudo apt-get install nano #pentru Debian

Code: Select all

nano numescript.sh #numescript.sh este numele scriptului tau
* Primul rand din fisier trebuie sa fie urmatorul:

Code: Select all

#!/bin/bash
* Dupa poti sa creezi niste variabile (ex: numele executabilului de la server,localizarea filelor,server.cfg, etc.)

Code: Select all

director='/home/user/server'                        # Inlocuiesti /home/user/server cu directorul unde este server tau.
server='hlds_run'                                            # hlds_run in caz ca folosesti un server de CS.
start=`comanda_prin_care_pornesti_serverul` # Pui intre ghilimele comanda de start
stop=`comanda_prin_care_opresti_serverul`   # Pui intre ghilimele comanda de stop 
* Un C pentru fiecare comanda start,stop.

Code: Select all

start() {

Code: Select all

stop() {
* Conditia if
start | Afiseaza codul
# Conditia if este folosita pentru luarea deciziilor in scripturile shell, daca valoarea conditiei este 1 sau YES atunci comanda este executata. 

if pgrep -u $USER -f $server > /dev/null;then # Aceasta conditie verifica prin comanda pgrep daca userul cu care esti logat are portit un proces cu numele hlds_run setat de tine ca $server
   # Prima valoare este then=1=yes
   echo "[START] Serverul este pornit deja, foloseste {stop|restart}"

   else 
   # A 2-a valoare este else=0=no
   $start
   echo "[START] Server pornit"
fi
}
stop | Afiseaza codul
if pgrep -u $USER -f $server > /dev/null;then # Aceasta conditie verifica prin comanda pgrep daca userul cu care esti logat are portit un proces cu numele hlds_run setat de tine ca $server
   # Prima valoare este then=1=yes
   $stop
   echo "[STOP] Server oprit"

   else 
   # A 2-a valoare este else=0=no
   echo "[STOP] Serverul este oprit deja"
fi
}
* Ca sa poti sa executi comenzile de start,stop,restart pe rand trebuie create casute.
case | Afiseaza codul
case "$1" in
      start)
       start
        ;;
      stop)
       stop
        ;;
      restart)
       stop
       sleep 1 # Doarme pentru o secunda
       start
        ;;
        *)
       echo "Foloseste comenzile {start|stop|restart}"
        ;;
    esac
Acum scriptul ar trebui sa fie de forma asta
numescript.sh | Afiseaza codul
#!/bin/bash

director='/home/user/server'                # Inlocuiesti /home/user/server cu directorul unde este server tau.
server='hlds_run'                              # hlds_run in caz ca folosesti un server de CS.
start=`comanda_prin_care_pornesti_serverul` # Pui intre ghilimele comanda de start
stop=`comanda_prin_care_opresti_serverul`   # Pui intre ghilimele comanda de stop

start() {
if pgrep -u $USER -f $server > /dev/null;then # Aceasta conditie verifica prin comanda pgrep daca userul cu care esti logat are portit un proces cu numele hlds_run setat de tine ca $server
   # Prima valoare este then=1=yes
   echo "[START] Serverul este pornit deja, foloseste {stop|restart}"

   else 
   # A 2-a valoare este else=0=no
   $start
   echo "[START] Server pornit"
fi
}

stop() {
if pgrep -u $USER -f $server > /dev/null;then # Aceasta conditie verifica prin comanda pgrep daca userul cu care esti logat are portit un proces cu numele hlds_run setat de tine ca $server
   # Prima valoare este then=1=yes
   $stop
   echo "[STOP] Server oprit"

   else 
   # A 2-a valoare este else=0=no
   echo "[STOP] Serverul este oprit deja"
fi
}

case "$1" in
      start)
       start
        ;;
      stop)
       stop
        ;;
      restart)
       stop
       sleep 1 # Doarme pentru o secunda
       start
        ;;
        *)
       echo "Foloseste comenzile {start|stop|restart}"
        ;;
    esac
* Executabil prin comanda:

Code: Select all

chmod 755 numescript.sh
Last edited by Clint on 17 Jan 2014, 20:34, edited 1 time in total.
Stay chill.
smileye
Fost moderator
Fost moderator
Posts: 4648
Joined: 12 Jun 2012, 15:18
Detinator Steam: Da
Reputatie: Fost moderator
Has thanked: 258 times
Been thanked: 38 times
Contact:

17 Jan 2014, 20:29

Server de cs 1.6 vreau sa instalez, dar nu reusesc ca tot imi da crash, l-am instalat prin steamcmd, iar fara batchuri nu reusesc nimic daca vreau sa fac mai multe servere.

Cum pot completa start si stop?

start = ./hlds_run -game cstrike +map de_dust2 +ip ipextern +port 27015 +maxplayers 32 +rcon_password BzbqF3v9 +sv_lan 0 & ??
Last edited by smileye on 17 Jan 2014, 20:41, edited 1 time in total.
Clint
Membru, skill +2
Membru, skill +2
Posts: 550
Joined: 31 Mar 2013, 15:18
Detinator Steam: Da
Has thanked: 35 times
Been thanked: 21 times

17 Jan 2014, 20:40

Foloseste acest tutorial http://forum.fioriginal.ro/tutorial-ins ... -t770.html
Sau downloadeaza arhiva gata facuta. Iar cu "batchurile" pune un user pentru fiecare server, nu le tine ca root !
Stay chill.
smileye
Fost moderator
Fost moderator
Posts: 4648
Joined: 12 Jun 2012, 15:18
Detinator Steam: Da
Reputatie: Fost moderator
Has thanked: 258 times
Been thanked: 38 times
Contact:

17 Jan 2014, 20:42

Clint wrote:Foloseste acest tutorial http://forum.fioriginal.ro/tutorial-ins ... -t770.html
Sau downloadeaza arhiva gata facuta. Iar cu "batchurile" pune un user pentru fiecare server, nu le tine ca root !
Cu stopul nu ma descurc, ma chinui cu ps -x si sa vad pidurile ca sa le opresc.Cum pot pune un user pentru fiecare server ca nu is cunoscator.Trebuie sa instalez cand vreau sa fac tot alt server, sa reiau tutorialul si sa pun din nou batchul sa pornesc/opresc serverul?
Clint
Membru, skill +2
Membru, skill +2
Posts: 550
Joined: 31 Mar 2013, 15:18
Detinator Steam: Da
Has thanked: 35 times
Been thanked: 21 times

17 Jan 2014, 20:46

Code: Select all

adduser test
Tinele in /home/$USER

Pentru stop executat ca test shell.
kill -9 $(pgrep -u $USER -f hlds_run)
Last edited by Clint on 17 Jan 2014, 20:49, edited 1 time in total.
Stay chill.
smileye
Fost moderator
Fost moderator
Posts: 4648
Joined: 12 Jun 2012, 15:18
Detinator Steam: Da
Reputatie: Fost moderator
Has thanked: 258 times
Been thanked: 38 times
Contact:

17 Jan 2014, 20:47

Clint wrote:

Code: Select all

adduser test
Tinele in /home/$USER
Cand se adauga userul, ininte de instalarea serverului?
Nu exista tutoriale video pentru asta?Is obosit si nu prea imi dau seama cum ar veni.
Clint
Membru, skill +2
Membru, skill +2
Posts: 550
Joined: 31 Mar 2013, 15:18
Detinator Steam: Da
Has thanked: 35 times
Been thanked: 21 times

17 Jan 2014, 20:55

Pai cand creezi un user o sa se faca un folder in /home cu numele acestuia, si aici pui fisierele de pe server... foloseste un server ftp (pure-ftpd sau proftpd) nu lucra ca root deoarece nu o sa mai ai acces ca user dupaceea si o sa trebuiasca sa ii dai iar permisiuni.
Stay chill.
smileye
Fost moderator
Fost moderator
Posts: 4648
Joined: 12 Jun 2012, 15:18
Detinator Steam: Da
Reputatie: Fost moderator
Has thanked: 258 times
Been thanked: 38 times
Contact:

17 Jan 2014, 21:03

Clint wrote:Pai cand creezi un user o sa se faca un folder in /home cu numele acestuia, si aici pui fisierele de pe server... foloseste un server ftp (pure-ftpd sau proftpd) nu lucra ca root deoarece nu o sa mai ai acces ca user dupaceea si o sa trebuiasca sa ii dai iar permisiuni.
Pun fisierele care le am descarcate deja? ex. copiez folderul cu serverul hlds/cs/srv1 in acel user?
Clint
Membru, skill +2
Membru, skill +2
Posts: 550
Joined: 31 Mar 2013, 15:18
Detinator Steam: Da
Has thanked: 35 times
Been thanked: 21 times

17 Jan 2014, 21:17

Mda... dar asta inseamna ca trebuie sa-i spui fiecarui bash unde este localizat serverul, mai exact hlds_run (in caz ca le ai ceva de genu /home/user/hlds/hlds_run), dar poti sa uploadezi direct hlds in /home/user, si folosesti in bash comanda $HOME/./hlds_run +...
Stay chill.
smileye
Fost moderator
Fost moderator
Posts: 4648
Joined: 12 Jun 2012, 15:18
Detinator Steam: Da
Reputatie: Fost moderator
Has thanked: 258 times
Been thanked: 38 times
Contact:

17 Jan 2014, 21:23

Clint wrote:Mda... dar asta inseamna ca trebuie sa-i spui fiecarui bash unde este localizat serverul, mai exact hlds_run (in caz ca le ai ceva de genu /home/user/hlds/hlds_run), dar poti sa uploadezi direct hlds in /home/user, si folosesti in bash comanda $HOME/./hlds_run +...
Asa fac si cei care gazduiesc sute de servere, firmele astea?Face la fiecare server cate un bash?Cu gamecp nu ar fi mai usor sa fac?
Clint
Membru, skill +2
Membru, skill +2
Posts: 550
Joined: 31 Mar 2013, 15:18
Detinator Steam: Da
Has thanked: 35 times
Been thanked: 21 times

17 Jan 2014, 21:34

smileye wrote:
Clint wrote:Mda... dar asta inseamna ca trebuie sa-i spui fiecarui bash unde este localizat serverul, mai exact hlds_run (in caz ca le ai ceva de genu /home/user/hlds/hlds_run), dar poti sa uploadezi direct hlds in /home/user, si folosesti in bash comanda $HOME/./hlds_run +...
Asa fac si cei care gazduiesc sute de servere, firmele astea?Face la fiecare server cate un bash?Cu gamecp nu ar fi mai usor sa fac?
Acum este treaba ta, tu ai cerut "Batchuri pornire, restart, stop".Daca vrei foloseste si GameCP, dar 1-nu este gratis,2-iti trebuie web-server si o baza de date, care consuma.

P.S. : @ Asa fac si cei care gazduiesc sute de servere, firmele astea?Face la fiecare server cate un bash? :-?? Una e 100 de servere si alta e 4 - 5.
Stay chill.
Post Reply

Return to “Discutii generale”

  • Information