LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-07-2018, 01:06 PM   #1
alfonz19@gmail.com
LQ Newbie
 
Registered: Feb 2018
Posts: 12

Rep: Reputation: Disabled
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.

nohup ./urserver &>/dev/null &

no-good.

Are there any other possibilities?
Thanks!
 
Old 02-07-2018, 02:40 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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".

https://www.gnu.org/software/screen/....html#Overview

If you run "file" against the command what does it output? If this is a script you can probably edit it to remove the terminal requirement.
 
Old 02-07-2018, 02:58 PM   #3
alfonz19@gmail.com
LQ Newbie
 
Registered: Feb 2018
Posts: 12

Original Poster
Rep: Reputation: Disabled
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 ...
 
Old 02-07-2018, 07:10 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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.

jlinkels
 
Old 02-08-2018, 01:12 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
if your system uses systemd, you could create a service for it.
if it doesn't require root privileges: https://wiki.archlinux.org/index.php...ing_user_units

PS: debian and derivates also use systemd nowadays.
 
Old 02-08-2018, 03:20 AM   #6
alfonz19@gmail.com
LQ Newbie
 
Registered: Feb 2018
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks guys for replies.

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:

Code:
[Unit]
Description=urserver service
After=suspend.target

[Service]
Type=simple
ExecStart=/opt/urserver-3.6.0.745/urserver
# 2>/dev/null

[Install]
WantedBy=suspend.target basic.target
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
 
Old 02-21-2018, 04:21 PM   #7
alfonz19@gmail.com
LQ Newbie
 
Registered: Feb 2018
Posts: 12

Original Poster
Rep: Reputation: Disabled
screen solves it, thanks to all.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a program run background when startup with rc gbao256 Linux - Newbie 2 12-18-2012 07:50 AM
Alias to run a program in the background diamond_D Linux - Newbie 3 05-04-2012 05:04 PM
Run a program in the background yanom Linux - Desktop 3 04-07-2011 11:14 PM
run program in background karabaja4 Linux - Newbie 3 01-05-2008 12:57 PM
Run a program in the background??? KaptinKABOOM Linux - Software 5 07-06-2004 06:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration