How to run an application and contact it from outside?

Richard G

Verified User
Joined
Jul 6, 2008
Messages
13,831
Location
Maastricht
I've got Directadmin and want to run an application via my admin useraccount.

I can start the application using a shell script like this.

./run.sh

And the run.sh contains:
#!/bin/sh
./appbinary

The application is running, which I can see with ps x as well if I'm logged in as root and as admin.

Problem is that users need to be able to reach the application from outside for example on poort 2080.
But when I open port 2080 incoming and outgoing, the application is still not reachable.

What am I doing wrong of what am I forgetting?
 
Ah thank you for the quick reply Sellerone!

Strange.. it's a VPS. But I disabled the firewall to test if this was the problem.
When I try to enable it again from within directadmin it says this:
Due to restrictions in DirectAdmin you must login to the root shell to enable csf using:

csf -e

...Done.
And the firewall is not started. I don't have that problems on other dedicated servers. Which restrictions can cause this and how can I take care these restrictions are not present anymore?

I tried your command but this only gives an empty line:
[root@server extra]# netstat -antp | grep :2080
[root@server extra]#

But if I do a ps -faux I see this:
admin 19715 0.0 0.1 57732 1180 ? Ssl 14:41 0:00 ./appname
So the process is running but probably as you suspected not binding.
 
Thanks, your hint brought me the solution Sellerone, I started the binarie wrongly.
I changed ./appname to /home/user/appname and then things were working.
So that problem is fixed.

Any clue about the csf notice of not having rights in Directadmin to restart the firewall?
 
Honestly no, i use to enable/disable from ssh.

Maybe you should try to uninstall and re-install using plugin manager in directadmin.

Regards
 
I just remembered I had some other questions about this.

I also made a ./restart.sh shell script to stop the application and start it up again.
Now there are 2 questions:
1.) is there an easy way to let the admin start the ./run.sh and ./restart.sh scripts from directadmin? And if yes, how is it done?
2.) Can the start script (run.sh) be executed automatically after a reboot, and how? It must be started as the user and not as root.
 
Now there are 2 questions:
1.) is there an easy way to let the admin start the ./run.sh and ./restart.sh scripts from directadmin? And if yes, how is it done?

You should create a valid init script for your program and put it in a proper place according to your OS type, usually some more commands will be required to register the init script.

So you'd better read the docs and Google in order to learn details on the subject, as it comes out of the forums goals ( a little bit ).


2.) Can the start script (run.sh) be executed automatically after a reboot, and how? It must be started as the user and not as root.

As soon as you write a valid init script and start using of a pid-file, you'll be able to add it in service monitor of directadmin.
 
Thank you, but I don't want an init script, it's only a 1 user thing (in this case admin) and I don't need it in the DA service monitor.
Building a real init script is not the easy way.:)

You could compare it with IRC, ventrilo or something, that's also started from the user's directory.
I just want to be able to start and stop the script from the DA control panel, no monitoring needed.
 
I can't give you any direct step-by-step recommendation, as I don't know what OS you are using, but you might want to google or read your OS docs on subject of using rc.local. You can specify your script there.


I just want to be able to start and stop the script from the DA control panel, no monitoring needed.

If service monitor (Show Status of Services) does not suit you (it's possible to start|restart|stop services there), I don't know any other way but to write your own plugin for that.
 
I'm running on Centos 5.5.
As far as I know, all things run from rc.local will run as root, but it should be running under the useraccount.
However I found a way to switch user in a script.
But I guess when it's not easy to do it from within DA, I will have to learn the admin to just use the shell. He has to learn anyway sometime.;)

Thanks!
 
If i dont remember badly you should run as user in two ways:

1 - use user crontab
2 - use su, should be like su -u USER -c COMMANDLINE

Regards
 
Yep, I can use the users crontab to check if the app is running.
But I'm also going to learn the admin how to use SSH, it's about time anyway.:)

Thanks for the tips!
 
You can't do it via the DA interface indeed, because there is no room for custom adjustments in the crontab like @reboot.

However, I added it as the user via SSH with the crontab -e command.
After that, rebooted the VPS and it worked like a charm, thank you very much!
 
Thank you Sellerone, but as you can read in my previous reply, it's already working.
I used the same as you have in point 1.

Richard G said:
However, I added it as the user via SSH with the crontab -e command.
So it's already working fine, but thanks for the reply!
 
Please, note, as it's mentioned in comments to the article, to which I gave you a link, it will work only after a reboot:

1. Only works after a reboot. If you do a shutdown, or if the box crashes (as in plug vs vacuum) …. and then start, it doesn’t get run.

I did not verify that, and nothing have I found in man crontab http://www.manpagez.com/man/5/crontab/ So it's up to you to check it.
 
As far as i remember it work every time the machine start, no matter if reboot shutdown or whatever.. but i should have bad memory :)
 
Back
Top