• Need a way to autostart gmod server when hosting reboots
    5 replies, posted
Hi I need help, I've been searching everywhere for a way to execute a command when my hosting boots so I don't need to have acces to a computer everytine hosting gets restarted for any reason. I've been on holidays without internet and when back home 3 hosting were restarted so I lost uptime and users. I have 4 gmod servers on ubuntu 12.04 and 2 on ubuntu 14.04 and the command I use for starting the server starts screen and runs the gmod server. Thanks EDIT: I've already tried using crontab but for some reason It does not work for me, maybe I'm doing sometging wrong
I have a Ubuntu server and I know there's a command that'll allow you to add a cron job to start the server should the server shutdown. Let me search quickly. [editline]5th August 2014[/editline] Yeah, go into the user that has the server and do, 'crontab -e' to pull up a editor. It should show a screen full telling about cron, but all you need to do is go down and make a new line along the lines of, @reboot /path/to/server/script -parameters before saving. So it should now start the server with the parameters on boot. [editline]5th August 2014[/editline] [url]https://help.ubuntu.com/community/CronHowto[/url]
[QUOTE=WhiteHusky;45603327]I have a Ubuntu server and I know there's a command that'll allow you to add a cron job to start the server should the server shutdown. Let me search quickly. [editline]5th August 2014[/editline] Yeah, go into the user that has the server and do, 'crontab -e' to pull up a editor. It should show a screen full telling about cron, but all you need to do is go down and make a new line along the lines of, @reboot /path/to/server/script -parameters before saving. So it should now start the server with the parameters on boot.[/QUOTE] Thanks for your answer, Ive already tried this without succes so I think I did something wrong. Anyways I will try this tomorrow when Im back home. I think I was writting screen before the command and that made it to not work but I don't know
[QUOTE=alrynec;45603403]Thanks for your answer, Ive already tried this without succes so I think I did something wrong. Anyways I will try this tomorrow when Im back home. I think I was writting screen before the command and that made it to not work but I don't know[/QUOTE] You could post what you have in your user's cron, of course removing any abusable information, so we can see what is going wrong.
[QUOTE=WhiteHusky;45603446]You could post what you have in your user's cron, of course removing any abusable information, so we can see what is going wrong.[/QUOTE] Ok tomorrow I will post my crontab file here, thank you!
[QUOTE=WhiteHusky;45603446]You could post what you have in your user's cron, of course removing any abusable information, so we can see what is going wrong.[/QUOTE] Ok here I have my crontab file # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any').# # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command @reboot screen ./server_1/srcds_run -game garrysmod +maxplayers 23 +gamemode darkrp +map gm_construct So I saved the file and rebooted the hosting and waited some minutes then type screen -r to see if the server has been started but theres no screen to be resumed. May I try to run the server with an alternative to screen? What am I doing wrong? Thanks EDIT: After editing the crontab file when I've restared the host and logged in I got a new email, the content of the email is here, related to crontab: From root@darkrp Wed Aug 6 17:30:20 2014 Return-Path: <root@darkrp> Received: from darkrp (localhost.localdomain [127.0.0.1]) by darkrp (8.14.4/8.14.4/Debian-2.1ubuntu4) with ESMTP id s76LUKr8000633 for <root@darkrp>; Wed, 6 Aug 2014 17:30:20 -0400 Received: (from root@localhost) by darkrp (8.14.4/8.14.4/Submit) id s76LUIad000435 for root; Wed, 6 Aug 2014 17:30:18 -0400 Date: Wed, 6 Aug 2014 17:30:18 -0400 Message-Id: <201408062130.s76LUIad000435@darkrp> From: root@darkrp (Cron Daemon) To: root@darkrp Subject: Cron <root@darkrp> screen ./server_1/srcds_run -game garrysmod +maxplayers 23 +gamemode darkrp +map gm_construct Content-Type: text/plain; charset=ANSI_X3.4-1968 X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <HOME=/root> X-Cron-Env: <PATH=/usr/bin:/bin> X-Cron-Env: <LOGNAME=root> Must be connected to a terminal. I don't know what does It mean, I think it's trying to say that the command is invalid but I have no idea how to fix that. PD: I know running server as root is unsafe but It's my test server not public. [editline]6th August 2014[/editline] Finally the issue was to write screen before the command, For some reason It's not necesary and now I've set all my servers to autostart when host reboots. Also I want to make a automatic reset shedule on crontab, and reset all the servers every week. Thank you WhiteHusky you helped me a lot!
Sorry, you need to Log In to post a reply to this thread.