Author Topic: CentOS jts3servermod service script  (Read 13268 times)

Gamle

  • JTS3ServerMod Internal
  • *****
  • Posts: 2
    • View Profile
CentOS jts3servermod service script
« on: April 13, 2016, 05:49:05 PM »
Create JTS3ServerMod as a service.
nano /etc/init.d/jts3servermod
Copy the service script and paste it. Then save the file.
chmod 755 /etc/init.d/jts3servermod
chkconfig --add jts3servermod

// If you want the bot to automatic start on system boot.
chkconfig --level 2345 jts3servermod on

Service script
Code: [Select]
#!/bin/sh
# chkconfig: 2345 99 10
USER="ts3bot"
TS3BOT='/home/ts3bot/JTS3ServerMod'
STARTSCRIPT="$TS3BOT/jts3servermod_startscript.sh"
cd $TS3BOT
case "$1" in
'start')
su $USER -c "$STARTSCRIPT start"
;;
'stop')
su $USER -c "$STARTSCRIPT stop"
;;
'restart')
su $USER -c "$STARTSCRIPT restart"
;;
'status')
su $USER -c "$STARTSCRIPT status"
;;
'java')
su $USER -c "$STARTSCRIPT status"
;;
*)
echo "Usage $0 start|stop|restart|status|java"
esac

ATTENTION: I'm not a extremely experienced linux user, so there can be some code/command mistake. I just share the code for the people there can't create a service script by them self.

stachu540

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: CentOS jts3servermod service script
« Reply #1 on: April 14, 2016, 12:34:03 AM »
I'll share my SystemD service Config. When he is don't need a startscript. Works fine for me.

When you need to creating SystemD service we must create a file. In this case we're going to writting this command:

nano /usr/lib/systemd/system/jts3servermod.service

and copy all script include changes on: WorkingDirectory, ExecStart and User. It is just important where is our files and .jar file as our launcher.
Code: [Select]
[Unit]
Description=JTS3ServerMod
After=network.target
 
[Service]
WorkingDirectory=/home/ts3bot
User=ts3bot
ExecStart=java -mx30M -jar /home/ts3bot/JTS3ServerMod.jar &
TimeoutSec=300
RestartSec=15
Restart=always
 
[Install]
WantedBy=multi-user.target


After changeing script and source files we saving file content. And all is done.
Everything when we should doing to launching script is 2 important commands.
1. we need enable service by command: systemctl enable jts3servermod
2. now time to launching our service writting: systemctl start jts3servermod

And that's all.

ps. Everything about SystemD services can be found here

UncleSam

  • JTS3ServerMod Internal
  • *****
  • Posts: 35
    • View Profile
Re: CentOS jts3servermod service script
« Reply #2 on: July 11, 2016, 10:19:50 PM »
I switched to Ubuntu 16.04 LTS and had to rewrite my JTS3ServerMod boot script. Sry it was a little bit too late. First I created one and then "oh ... lets search in the forum"  :o

(So it is tested for Ubuntu 16.04 LTS)

So I found two ways to start the bot. Each one has its benefits:

First way:
Execute is by using the new jts3servermod_startscript.sh from Stefan


Pro:
- Uses technology from stefan
Con:
- Is not having any benefits from SystemD


Code:
Code: [Select]
[Unit]
Description=JTS3Servermod
# add mysql.service or postgresql.service depending on your database to the line below
After=network.target mysql.service
Before=shutdown.target reboot.target halt.target


[Service]
WorkingDirectory=/home/tsbots/JTS3ServerMod_HostingEdition/
ExecStart=/home/tsbots/JTS3ServerMod_HostingEdition/jts3servermod_startscript.sh start
ExecStop=/home/tsbots/JTS3ServerMod_HostingEdition/jts3servermod_startscript.sh stop
Type=oneshot
User=tsbots
Group=tsbots
RemainAfterExit=yes


[Install]
WantedBy=multi-user.target


Second way (my prefered):
Execut is directly by using java command


Pro:
- Benefits like "Restart" is possible and used (as soon as the service stopps without systemd stop command it restarts again)


Code:
Code: [Select]
[Unit]
Description=JTS3Servermod
# add mysql.service or postgresql.service depending on your database to the line below
After=network.target mysql.service


[Service]
PIDFile=/home/tsbots/JTS3ServerMod_HostingEdition/jts3servermod.pid
WorkingDirectory=/home/tsbots/JTS3ServerMod_HostingEdition/
ExecStart=/usr/bin/java -Xms1G -Xmx3G -jar JTS3ServerMod.jar
Type=simple
Restart=always
RestartSec=15
User=tsbots
Group=tsbots



[Install]
WantedBy=multi-user.target


Maybe someone is interested in this code - I use the upper one for all my programs/tools which already have good old sysvinit start scripts (never change a running system)  ;D
« Last Edit: July 11, 2016, 11:05:24 PM by UncleSam »