• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Script and cron help needed

Joined
Nov 1, 2008
Messages
4,213 (0.75/day)
Location
Vietnam
System Name Gaming System / HTPC-Server
Processor i7 8700K (@4.8 Ghz All-Core) / R7 5900X
Motherboard Z370 Aorus Ultra Gaming / MSI B450 Mortar Max
Cooling CM ML360 / CM ML240L
Memory 16Gb Hynix @3200 MHz / 16Gb Hynix @3000Mhz
Video Card(s) Zotac 3080 / Colorful 1060
Storage 750G MX300 + 2x500G NVMe / 40Tb Reds + 1Tb WD Blue NVMe
Display(s) LG 27GN800-B 27'' 2K 144Hz / Sony TV
Case Xigmatek Aquarius Plus / Corsair Air 240
Audio Device(s) On Board Realtek
Power Supply Super Flower Leadex III Gold 750W / Andyson TX-700 Platinum
Mouse Logitech G502 Hero / K400+
Keyboard Wooting Two / K400+
Software Windows 10 x64
Benchmark Scores Cinebench R15 = 1542 3D Mark Timespy = 9758
Hi all,
I've been playing around with ubuntu server 16.04, scripts and cron for about 3 hours to no avail and need some serious help. It's rather frustrating as I managed to get what I wanted to do to work on a previous install, I just can't do it any more.

Basically, I have a minecraft spigot server running on an old laptop for my kids and i'd like to have it start in a new screen session on every reboot.

The commands I use to start the server are as follows:

Screen
cd minecraft
java -Xms512M -Xmx1008M -jar ./spigot-1.12.2.jar nogui

And the server starts fine.

I'm trying to make a script that i can put in cron to run @Reboot, but every attempt ends in failure.

I either get thousands of screen sessions open, an eula error (the text file needs to be set to eula=true (which it is already), or it just fails to run.
I've managed to make a script that will start the server (though I've since deleted it), I just can't for the life of me get it to work with cron and screen.

I'd like to run it in a screen session, rather than as a service so I can switch to the session and enter commands if needed.

If anyone could help, I'd greatly appreciate it.
 

re0

New Member
Joined
Jan 27, 2018
Messages
14 (0.01/day)
I haven't got my problem solving head on at the moment, but perhaps you can show us what your cron looks like if you currently have one set?

I understand that the following does not answer your question, but I propose that perhaps you should look at using Linux Game Server Manager (LGSM) if you're not so much into the nitty gritty of Linux since it's really easy to deploy and maintain. Plus, there is a lot of user-friendly documentation, including on how to use cronjobs to monitor, restart and update the server here for LGSM.
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.94/day)
Location
Concord, NH, USA
System Name Apollo
Processor Intel Core i9 9880H
Motherboard Some proprietary Apple thing.
Memory 64GB DDR4-2667
Video Card(s) AMD Radeon Pro 5600M, 8GB HBM2
Storage 1TB Apple NVMe, 4TB External
Display(s) Laptop @ 3072x1920 + 2x LG 5k Ultrafine TB3 displays
Case MacBook Pro (16", 2019)
Audio Device(s) AirPods Pro, Sennheiser HD 380s w/ FIIO Alpen 2, or Logitech 2.1 Speakers
Power Supply 96w Power Adapter
Mouse Logitech MX Master 3
Keyboard Logitech G915, GL Clicky
Software MacOS 12.1
You don't want to use cron for something that you want to start at boot, you need an init script. You also won't need screen if it's running as a service via said init script.
I'd like to run it in a screen session, rather than as a service so I can switch to the session and enter commands if needed.
There is a probably a better way to achieve that than running the process in screen or tmux.

Edit: See the "start-stop-daemon" command.
 
Last edited:

re0

New Member
Joined
Jan 27, 2018
Messages
14 (0.01/day)
^ This

Cron is probably not most suitable for the task as-is. It's better to stick to using cronjobs for scheduling tasks at regular intervals.
 
Joined
Nov 1, 2008
Messages
4,213 (0.75/day)
Location
Vietnam
System Name Gaming System / HTPC-Server
Processor i7 8700K (@4.8 Ghz All-Core) / R7 5900X
Motherboard Z370 Aorus Ultra Gaming / MSI B450 Mortar Max
Cooling CM ML360 / CM ML240L
Memory 16Gb Hynix @3200 MHz / 16Gb Hynix @3000Mhz
Video Card(s) Zotac 3080 / Colorful 1060
Storage 750G MX300 + 2x500G NVMe / 40Tb Reds + 1Tb WD Blue NVMe
Display(s) LG 27GN800-B 27'' 2K 144Hz / Sony TV
Case Xigmatek Aquarius Plus / Corsair Air 240
Audio Device(s) On Board Realtek
Power Supply Super Flower Leadex III Gold 750W / Andyson TX-700 Platinum
Mouse Logitech G502 Hero / K400+
Keyboard Wooting Two / K400+
Software Windows 10 x64
Benchmark Scores Cinebench R15 = 1542 3D Mark Timespy = 9758
But, if I use it as a service, I won't be able to access the server commands, right?

I thought it'd be easy to start a screen on boot, run a command in screen, then detach as I had it set up before. I just can't for the life of me figure it out any more.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software The Matrix

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.94/day)
Location
Concord, NH, USA
System Name Apollo
Processor Intel Core i9 9880H
Motherboard Some proprietary Apple thing.
Memory 64GB DDR4-2667
Video Card(s) AMD Radeon Pro 5600M, 8GB HBM2
Storage 1TB Apple NVMe, 4TB External
Display(s) Laptop @ 3072x1920 + 2x LG 5k Ultrafine TB3 displays
Case MacBook Pro (16", 2019)
Audio Device(s) AirPods Pro, Sennheiser HD 380s w/ FIIO Alpen 2, or Logitech 2.1 Speakers
Power Supply 96w Power Adapter
Mouse Logitech MX Master 3
Keyboard Logitech G915, GL Clicky
Software MacOS 12.1
Using screen or tmux to run a service feels wrong to me, even if it's turned into a service by whatever your flavor of Linux does. If the OP wants to be able to execute commands on the server essentially remotely, I would see if there is a better rcon option for Minecraft so the need for being able to connect into the console is removed as a requirement. There has to be a server monitor thing that you can use to interact with the Minecraft server via a remote console without actually needing the console provided by the server itself.
 
Joined
Nov 1, 2008
Messages
4,213 (0.75/day)
Location
Vietnam
System Name Gaming System / HTPC-Server
Processor i7 8700K (@4.8 Ghz All-Core) / R7 5900X
Motherboard Z370 Aorus Ultra Gaming / MSI B450 Mortar Max
Cooling CM ML360 / CM ML240L
Memory 16Gb Hynix @3200 MHz / 16Gb Hynix @3000Mhz
Video Card(s) Zotac 3080 / Colorful 1060
Storage 750G MX300 + 2x500G NVMe / 40Tb Reds + 1Tb WD Blue NVMe
Display(s) LG 27GN800-B 27'' 2K 144Hz / Sony TV
Case Xigmatek Aquarius Plus / Corsair Air 240
Audio Device(s) On Board Realtek
Power Supply Super Flower Leadex III Gold 750W / Andyson TX-700 Platinum
Mouse Logitech G502 Hero / K400+
Keyboard Wooting Two / K400+
Software Windows 10 x64
Benchmark Scores Cinebench R15 = 1542 3D Mark Timespy = 9758
You could create an init.d or systemd script that fires on boot that creates the screen session and launches minecraft. it shouldn't take much time reading the systemd docs.

https://linuxconfig.org/how-to-automatically-execute-shell-script-at-startup-boot-on-systemd-linux

I did attempt to do that, but I just can't get my head around the coding without step-by-step instructions. My level of understanding of Linux is rather rudimentary. I can understand how to install packages, start services, hell, I even have set up a personal cloud and plex servers along with VPNs, DNS services and secure SSH and SFTP services linux computers with one having (fake) raid for redundancy. I can create basic scripts through copy-paste, but every attempt I make to modify a script, just ends in failure. I just can't get my head around how linux/ubuntu handles start up programs or how to properly code scripts.

I swear that all I did in the past was to do an @Reboot screen -d java . . . . command in cron, but now I can't do that.

I think that I will continue to run the commands manually for now, and then just have it run as a service later. Console access isn't essential, it's just nice to have as it provides a quick and easy way to op, whitelist, blacklist as required if I open the server up to WAN.

Thanks for the help anyway. I'll try to continue with more experimentation and see how it works.

Using screen or tmux to run a service feels wrong to me, even if it's turned into a service by whatever your flavor of Linux does. If the OP wants to be able to execute commands on the server essentially remotely, I would see if there is a better rcon option for Minecraft so the need for being able to connect into the console is removed as a requirement. There has to be a server monitor thing that you can use to interact with the Minecraft server via a remote console without actually needing the console provided by the server itself.

Lots of people have said it is wrong to run a screen on startup, but no one has been able to tell me why. Running it in screen always seemed to be the most simple option to get full console access. I had it working great a while ago on a raspberry PI, but since switching the server to ubuntu, It just doesn't work.
 

Easy Rhino

Linux Advocate
Staff member
Joined
Nov 13, 2006
Messages
15,449 (2.42/day)
Location
Mid-Atlantic
System Name Desktop
Processor i5 13600KF
Motherboard AsRock B760M Steel Legend Wifi
Cooling Noctua NH-U9S
Memory 4x 16 Gb Gskill S5 DDR5 @6000
Video Card(s) Gigabyte Gaming OC 6750 XT 12GB
Storage WD_BLACK 4TB SN850x
Display(s) Gigabye M32U
Case Corsair Carbide 400C
Audio Device(s) On Board
Power Supply EVGA Supernova 650 P2
Mouse MX Master 3s
Keyboard Logitech G915 Wireless Clicky
Software The Matrix
I did attempt to do that, but I just can't get my head around the coding without step-by-step instructions. My level of understanding of Linux is rather rudimentary. I can understand how to install packages, start services, hell, I even have set up a personal cloud and plex servers along with VPNs, DNS services and secure SSH and SFTP services linux computers with one having (fake) raid for redundancy. I can create basic scripts through copy-paste, but every attempt I make to modify a script, just ends in failure. I just can't get my head around how linux/ubuntu handles start up programs or how to properly code scripts.

I swear that all I did in the past was to do an @Reboot screen -d java . . . . command in cron, but now I can't do that.

I think that I will continue to run the commands manually for now, and then just have it run as a service later. Console access isn't essential, it's just nice to have as it provides a quick and easy way to op, whitelist, blacklist as required if I open the server up to WAN.

Thanks for the help anyway. I'll try to continue with more experimentation and see how it works.



Lots of people have said it is wrong to run a screen on startup, but no one has been able to tell me why. Running it in screen always seemed to be the most simple option to get full console access. I had it working great a while ago on a raspberry PI, but since switching the server to ubuntu, It just doesn't work.

I think the point is that the best way to accompish what you want is to use an actual agent to login to your server and run commands. I do believe there are a few free ones out there. That way you can simply have minecraft start on boot and then fire up your client and run commands for days.
 

Aquinus

Resident Wat-man
Joined
Jan 28, 2012
Messages
13,147 (2.94/day)
Location
Concord, NH, USA
System Name Apollo
Processor Intel Core i9 9880H
Motherboard Some proprietary Apple thing.
Memory 64GB DDR4-2667
Video Card(s) AMD Radeon Pro 5600M, 8GB HBM2
Storage 1TB Apple NVMe, 4TB External
Display(s) Laptop @ 3072x1920 + 2x LG 5k Ultrafine TB3 displays
Case MacBook Pro (16", 2019)
Audio Device(s) AirPods Pro, Sennheiser HD 380s w/ FIIO Alpen 2, or Logitech 2.1 Speakers
Power Supply 96w Power Adapter
Mouse Logitech MX Master 3
Keyboard Logitech G915, GL Clicky
Software MacOS 12.1
Lots of people have said it is wrong to run a screen on startup, but no one has been able to tell me why. Running it in screen always seemed to be the most simple option to get full console access. I had it working great a while ago on a raspberry PI, but since switching the server to ubuntu, It just doesn't work.
It's not good practice because it's not just running the service, it's a service (screen or tmux,) running a shell, that's running a service (Minecraft.) The main issue is that it's not hard to start another shell with screen and that if Minecraft is running privileged (as root,) then it becomes a security concern. Root is only as secure as the weakest link and having something like screen running that a non-privileged user can gain access to makes root as a whole insecure. Running screen or tmux is a valid strategy for some kinds of problems but, every time it's not for long running services. There are other benefits to using a init.d script or upstart or something to start Minecraft. There is value in being able to do thing like "sudo invoke.rd minecraft-server [status|stop|start]" without having to enter a screen session to figure it out.

I'm not saying you can't use screen or tmux, you certainly can and it will definitely work. It's just bad practice in my honest opinion.
 
Joined
Nov 1, 2008
Messages
4,213 (0.75/day)
Location
Vietnam
System Name Gaming System / HTPC-Server
Processor i7 8700K (@4.8 Ghz All-Core) / R7 5900X
Motherboard Z370 Aorus Ultra Gaming / MSI B450 Mortar Max
Cooling CM ML360 / CM ML240L
Memory 16Gb Hynix @3200 MHz / 16Gb Hynix @3000Mhz
Video Card(s) Zotac 3080 / Colorful 1060
Storage 750G MX300 + 2x500G NVMe / 40Tb Reds + 1Tb WD Blue NVMe
Display(s) LG 27GN800-B 27'' 2K 144Hz / Sony TV
Case Xigmatek Aquarius Plus / Corsair Air 240
Audio Device(s) On Board Realtek
Power Supply Super Flower Leadex III Gold 750W / Andyson TX-700 Platinum
Mouse Logitech G502 Hero / K400+
Keyboard Wooting Two / K400+
Software Windows 10 x64
Benchmark Scores Cinebench R15 = 1542 3D Mark Timespy = 9758
Ah. I never realized that it would be a security issue. I'll look into how to run it as a service a little further.
 
Top