Doomsider's Starmade Daemon

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    My newest project was born out of the need to access console commands from SSH. After a little searching I was able to adapt a existing script to fit my needs and perhaps the needs of many others. Without further ado, I present Doomsider's Starmade Daemon (DSD).

    Verion .13 October 26, 2013

    https://drive.google.com/file/d/0B519td3ku8G1bld5OXZ6dFlleTg/edit?usp=sharing

    alternative link

    ftp://ftp.nasszone.com/daemon/13/starmaded

    What do I do with it?

    You put it in your /etc/init.d and then

    chmod ug+x /etc/init.d/starmaded

    to make it executable

    What the hell does it do?

    Good question, a little of everything here is a quick overview of the commands

    All of these commands come at the end of /etc/init.d/starmaded (IE: /etc/init.d/stamaded start)

    start - Starts the server
    stop - Stops the server with a server message and countdown approx 2 mins
    ebrake - Stop the server without a server message approx 30 seconds
    destroy - Deletes Server no recovery
    install - Download a new starter and do a install
    reinstall - Destroys current server and installs new fresh one
    smrestore filename - Selected file unzips into the parent folder of starmade
    smdo command - Issues a server command. Use quotes if there are spaces
    smsay words - Say something as the server. Use quotes if there are spaces
    backup - backs up current Starmade directory as zip
    backupstar - Stops cron and server, makes backup, restarts cron and server
    status - See if server is running
    cronstop - Removes all cronjobs
    cronrestore - Restores all cronjobs
    cronbackup - Backs up your cron file
    upgrade - Runs the starters upgrade routine
    upgradestar - Stops cron and server, runs upgrade, restarts cron and server
    restart - Stops and starts server
    smplayermaxset number - Change max players to this setting. Helpful to set to 0 for maintenance
    detect - See if the server is frozen and restart if it is
    log - Logs admin, chat, player, and kills

    screenlog - Starts a screen which starts the log function

    check - Checks for new version. If found send message, stop server, backup, download and install new verion

    precheck - Checks for new PRE version. if found send message, stop server, backup, download and install new verion

    smban - Bans a player by their names and IP address

    version .04

    Fix for Chat (Schema Changed it to /chat so I fixed it)

    smdetect - Detects if the server is frozen by sending the time and date and then checking the outputlog to see if server recieved. This will only work if you use startout to generate a log file

    Version .05

    Added port option to support running daemon with multiple copies of Starmade on same server. Also added new log function smlog which records Players logged on off, kills, admin commands, chat, and active players. Look forwards to a code rewrite for the next version as things have gotten sloppy.

    version .06

    I added in a variable for screen names so it will be easier to run multiple copies of starmade on the same server with different daemon scripts. I re-wrote for several hours troubleshooting and making the code more consistent. I improved and altered every function in the script with new routines. I added in path variables for logging and changed the start function to always log. smlog and smdetect are now log and detect respectively. I have several different projects so stay tuned for future developments.

    version .07

    Added a new command screenlog that starts the logging session in a screen. I fixed the stop routine and start routine to be more accurate in dealing with screens. I addressed a bug that would allow dead screens to prevent the server from starting by adding screen -wipe where needed. I reworked the logging function and removed the script that linked chatID to player name. Chat will still be logged it just won't have the persons name in place of the chatID.

    Vesrion .08-.09

    Fixed start function by adding in -port:$PORT to allow servers to use other ports
    Fixed install function it had a error on a add_user command
    Added a routine to screenlog to ensure multiple copies will not run
    Changed back to using ps aux to detect servers due to inconsistency with screen
    Added in grep for port:$port and grep -v tee to remove fale positives
    Fixed Backup to correctly detect is zip has been installed or not

    Completely re-did logging to update it to current server output. Added new logging in as well.

    Version .10

    Fixed ship and station names with a space so they work with logging. Fixed a bug that transposed playername into ship log. Added check and precheck to help automate updates. Added a destroy routine to remove ships and station from their respective logs when they are destroyed or removed. Fixed other minor bugs and reformated script to be more readable. I will go back and add more comments in later to make what the script is doing more clear. Added in chat commands, please see !HELP ingame for a list. Added in a Ranking system to control access to chat commands, you will have to add yourself to rank.log with the chosen RANK5 name to be able to set ranks.

    Version .11

    Added routine to allow anyone in admins.txt to use !RANKSET. Fixed Shipbuy log. Fixed Chat Import and Despawn commands. Added routine into detect to prevent the server from resetting while repairing the database. Added services into main start line so if you are running a modified or renamed StarMade.jar it will work. Added Chat commands to give players items and cash as well as adding people to whitelist and listing people on whitelist

    Version .12

    Added a routine to shutdown screenlog in case it was still running. Moved variables from screenlog to the beggining of the daemon to make it more easy to configure. Changed output log variable so it was more consistent. Added a line that can be uncommented right after server start to begin screen logging for admin commands. Added in a !RAKCOMMAND to allow users to see what their ranks can do. Added in !BANHAMMER command so a client with the proper rank can now ban a player with name and IP. Added a new function called smban which essentially does the same thing as banhammer only can be used from command line. Fixed some other minor bugs and did some formatting. Still have some concerns about some of the logging function. You can always comment out everything but chat string if you just want chat commands on you server.

    Version .13

    I decided to rewrite logging directory structure. Screen logging is now default and all logs are dumped into starterpath/logs. At Schema's request jstack does a threaddump.log when ebrake is used for the detect routine. I run the detect routine ever 5 minutes with cronjob to see if the server is reponsive, if not it will restart the server. You can send you threddump.log to Schema so he can troubleshoot the crashes better. I also added a few comments and formatted a bit to make things easier to seperate.

    Whats this cron crap?

    Since this script was originally written for NASS I had to make sure it would work with the existing cronjobs that keep the server running and start things like backup. You can remove or ignore it if you do not use cronjobs to automate your server

    Multi Server Support

    The Daemon can assist in running more than one server on the same machine. Just rename the daemon to anything you want and then chenge the path vairables, screen ID, and the port to something different than your current server. Then you can then run either daemon file to control the proper server.

    Currently I would suggest running the deamon from the root directory of you Starmade servers and naming each daemon the name of the server it is running. This can greatly help to simplify running more than one server on the same machine.

    Anything else?

    No not really, be sure to edit this and change the settings at the beggining of the file to match your setup. I designed this Daemon so it can be called from other scripts to make your life easier. Do with it as you please. It is free as in beer - Cheers! (Some people have been confused by this saying, basically it is open source an you can do whatever you want with the code)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    I went through and simplified the variables and added a new command. I also added some checks to see if files, directories, and commands are there. Cheers! :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Ok I finished the next version of DSD. I added a logging option and a way to set the max players for maintenance.
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Version .04 is out. I fixed the chat function and added smdetect which can be used to see if the server is being unrepsonsive. Special thanks to Fire219 and Crazy6227 for helping test this version. You guys are rockstars! :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Ok it took me many weeks of work but I added a logging functionality that records active players, player log in and out, admin commands, chat, and kills. I will be adding to this code in the near future so let me know if you want anything in particular done. Next up is a cleanup and rewrite of the main script so I can keep it nice and tight.
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    You\'re welcome, glad it was useful for you :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Ok so I went through and completly re-worked most of the code to make it conform and be more consistant. I re-wrote many commands to be more efficient as well as troubleshoot bugs. I simplified some of the commands and added in a ton more comments for those who are trying to understand the code for their own scripts. I also added in a name for the screen so it will be easier than ever to run mutliple copies of Starmade on the same server. I feel really good about this release as I have met all my goals so far. Cheers! :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Ok, I fixed some bugs and re-did the logging function and added a way to run it in on a screen. I cannot accurately link the playername with chatID. The method I used was reliant on the fact that when playername was issued it came right before chatID. The problem with this is if someone else has a faster computer/internet they can get in before you and effectively steal you chatID. Hence no accurate way to link the two varaibles. This is a bummer as it puts my chat commands and IRC intergration on hold for now.

    Let me know if there are any new ideas or issue with the Daemon. Cheers! :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Ok script kiddies I got the next version of the Daemon done. .08 was an internal build and not released so this next version is .09. I spent a ridicolous amount of time with the logging function but I hope to do a lot of cool things with it soon. Be sure to edit the variables in the beggining like paths and also the location of the Daemon in the screenlog command as well as the name for the screenlog screen itself. Cheers :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Next version of the Daemon is done. I addressed some issues with logging and added in the long awaited chat command and rank system. Let me know if you have any problems with it. Cheers! :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Ok had to do antoher version to address some bugs and ad some features. I hope you all like it :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Just finished off .12 of the Daemon. Added new chat commands and the smban function I have been meaning to for a long time. If anyone out there knows BASH well I really need some peer review, I have written an awful lot for this script but I still think I am a bash beginner. At any rate, Cheers :)
     

    Doomsider

    Server scriptologist
    Joined
    Jan 21, 2013
    Messages
    215
    Reaction score
    43
    Did some bug hunting and directory structure rewrites. I am hoping the Daemon is pretty solid now let me know if you have any issues.
     
    Joined
    Aug 11, 2013
    Messages
    86
    Reaction score
    9
    Hey, I think this is a great project. I\'ve started myself something similar for our server but this is bigger, better, stronger.

    I\'ll try to use it in my local test server and if I have time, I\'ll take a look at the code. It\'s supposed I know bash, but I\'ve learnt it 10 years ago and it\'s... well, not as good as it was xD
     
    Joined
    Jul 9, 2013
    Messages
    14
    Reaction score
    2
    • Purchased!
    Nice script, i\'m currently reading and try to fully understanding the whole script. And I found a little \"bug\"

    in line 43:


    su - $USERNAME -c \"$1\"


    I don\'t know much about other systems as debian-based systems. But on Debian



    su -


    operate as \"login as root\", respectively operate as root.

    but if you remove the dash



    su $USERNAME -c \"$1\"


    the user substitude works.

    I hope this helps anyone ;)



    Cheers!

    - Zodiak



    PS: Under which licence is the script published?