Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### BEGIN INIT INFO
- # Provides: TM2 RPG Server
- # Required-Start: $remote_fs $syslog
- # Required-Stop: $remote_fs $syslog
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: Start TM2 daemon at boot time
- # Description: Enable service provided by daemon.
- ### END INIT INFO
- #!/bin/bash
- TM_DIR="/home/yourdirectory"
- TM_USER="youruser"
- SRV_SUFFIX=${2:-}
- RUN_SCRIPT="manage.py"
- PRV_SRV="/serverpassword=yourpassword"
- start_tm() {
- echo "Lancement du server RPG${SRV_SUFFIX} TrackMania"
- su -l $TM_USER -c "cd $TM_DIR; $TM_DIR/ManiaPlanetServer /dedicated_cfg=dedicated_cfg.rpg${SRV_SUFFIX}.txt /game_settings=MatchSettings/RPG${SRV_SUFFIX}DefaultMaps.txt; pyenv activate pyplaenv; $TM_DIR/rpg${SRV_SUFFIX}_server/$RUN_SCRIPT start --detach --pid-file=$TM_DIR/rpg${SRV_SUFFIX}_server/pyplanet.pid" > /dev/null &
- }
- stop_tm() {
- echo "Arrêt du serveur RPG${SRV_SUFFIX} TrackMania"
- for pid in $(ps -fu "$TM_USER" | grep --regexp "[\._]rpg${SRV_SUFFIX}[\._]" | awk '{print $2}'); do kill -9 $pid; done > /dev/null
- }
- start_pypla() {
- echo "Lancement du contrôleur PyPlanet"
- su -l $TM_USER -c "cd $TM_DIR; pyenv activate pyplaenv; $TM_DIR/rpg${SRV_SUFFIX}_server/$RUN_SCRIPT start --detach --pid-file=$TM_DIR/rpg${SRV_SUFFIX}_server/pyplanet.pid" > /dev/null &
- }
- stop_pypla() {
- echo "Arrêt du contrôleur PyPlanet"
- for pid in $(ps -fu "$TM_USER" | grep -E "python.*[\/]rpg${SRV_SUFFIX}_" | awk '{print $2}'); do kill -9 $pid; done > /dev/null
- }
- case "$1" in
- start)
- start_tm
- ;;
- stop)
- stop_tm
- ;;
- restart)
- stop_tm
- sleep 2
- start_tm
- ;;
- pystart)
- start_pypla
- ;;
- pystop)
- stop_pypla
- ;;
- pyrestart)
- stop_pypla
- sleep 2
- start_pypla
- ;;
- *)
- echo "Usage du script : $0 {start|stop|restart|pystart|pystop|pyrestart}"
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement