[SOLVED] program resisting to run on background. How to convince it?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
program resisting to run on background. How to convince it?
Hi,
I have this program, which after start acts as a server. Developer probably though, it would be great, if I have to start it manually every time, so I also have this great opportunity to close it afterwars with typing `exit`.
if you run it:
./start &
it will reached stopped state.
if I try to do `bg` it will return to stopped state.
It may be the developer purposefully required it to run in foreground because it s a memory hog OR because running it more than once simultaneously can corrupt something (e.g. a database it relies upon). In such a case rather than running it in background, opening a separate session/window to do other tasks while this runs in the first session/window runs this program. That way when you close whatever you're using for sessions/windows it will automatically close this program.
However, if you do want to background it you might try running it with "screen".
it's actually very lightweight, and we have java application servers running on machines on background just fine. So this does not seems as justification. One running process, well I'd be able to run it twice from different windows, so that would be poor safety check. So I'm really missing any justifications.
No, it's not a script, it's a binary:
urserver: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=463d8b2d2a0b3834d3720517f5436b95976f49c7, stripped
good, `screen urserver` works. I starts with it, and I can at least quit terminal.
Would it be able to run it so that it just runs on background entirely and write pid to kill in future?
RUnning it like:
screen "urserver" &
exits emmediately ...
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
You have to create a startup script. Place it in /etc/init.d
Run update-rc.d to start it in the desired run level after startup.
If you have to write the start-up script, copy and modify a similar script. /etc/init.d/ntp might be a good example.
The reason your script ends is that every process initiated in the shell is terminated when the shell is terminated (at logout). Your workaround with screen covers exactly that. Screen is there to continue even after logout.
You could also start the program with NOHUP. But that is still not elegant. If you want a background process, have it run at startup.
The description above is for Debian like systems. Red Hat and Fedora derived systems do it differently. Since you did not complete your profile or mention your distro I had to guess.
I was little bit worried, that if nohup does not work (see first message) that this service won't equally. But I gave it a shot this morning, having service:
I actually have no idea how systemd works and did not invest time to learn it, I just copied service from another service I have, which works (badly, but works)
I run: sudo systemctl start urserver.service
and got SELinux warning popup on permisive selinux setting (what?). (yes, I did not have time to spent all that time to lears selinux, so I have to disable it to be able to work)
Anyway, the service did not start the urserver.
But I actually don't need/want to urserver be running after startup. I just want to type one command to start it, then it's not visible anywhere except of pid file or ps, and another command to kill it. I'm fine with systemd if it works, but as it's not needed to be running on startup(with which I have great difficulty with systemd anyways), I need not to use systemd.
selinux report:
Code:
SELinux is preventing (urserver) from execute access on the file urserver.
***** Plugin catchall (100. confidence) suggests **************************
If you believe that (urserver) should be allowed execute access on the urserver file by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c '(urserver)' --raw | audit2allow -M my-urserver
# semodule -X 300 -i my-urserver.pp
Additional Information:
Source Context system_u:system_r:init_t:s0
Target Context unconfined_u:object_r:user_home_t:s0
Target Objects urserver [ file ]
Source (urserver)
Source Path (urserver)
Port <Unknown>
Host vbDesktop
Source RPM Packages
Target RPM Packages
Policy RPM selinux-policy-3.13.1-260.18.fc26.noarch
Selinux Enabled True
Policy Type targeted
Enforcing Mode Permissive
Host Name vbDesktop
Platform Linux vbDesktop 4.14.16-200.fc26.x86_64 #1 SMP Wed
Jan 31 19:34:52 UTC 2018 x86_64 x86_64
Alert Count 1
First Seen 2018-02-08 08:32:11 CET
Last Seen 2018-02-08 08:32:11 CET
Local ID b50510c7-5d62-4d69-93c6-1166d75bedfa
Raw Audit Messages
type=AVC msg=audit(1518075131.324:638): avc: denied { execute } for pid=30638 comm="(urserver)" name="urserver" dev="dm-0" ino=717756 scontext=system_u:system_r:init_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=1
Hash: (urserver),init_t,user_home_t,file,execute
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.