[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Unix developers

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 22
Thread images: 2

File: images.jpg (5KB, 228x221px) Image search: [Google]
images.jpg
5KB, 228x221px
Right now I have a server daemon that runs in a terminal window. I want it to just run without presenting any interface, like a normal service.

How do I do that on mac/linux?
>>
File: 1496921892309.jpg (8KB, 320x320px) Image search: [Google]
1496921892309.jpg
8KB, 320x320px
>>61066615
try tmux or dtach
>>
i want to do it without using nohup or disown >>61066653
i just want the init system to launch the service at login
>>
If it's run by a user, then fork it into the background. And if you want to run it as an os service, read about systemd services (and cry)
>>
>>61066676
>read about systemd services (and cry)
that's what i was afraid of.

and on osx it's not much easier. you have to use launchd, create a manifest file and all kinds of stuff. welp, guess i'll be reading today
>>
>>61066717
Systemd supports legacy init style config files, but it's terribly inconsistent, throws weird errors and will just waste your time.
>>
>>61066615
Mac is a device.
Linux is a kernel.
>>
>>61066972
i have it set up with my port number (just using sockets) and it's listed in the launchd process, and even has a process ID. however it will not execute properly. do i need to make changes to the program for it to behave correctly as a daemon or is there probably just something wrong with my launchd configuration file?
>>
here's the config file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DaemonTest</key>
<string>com.example.program</string>
<key>Program</key>
<string>/Users/moot/program</string>
<key>Label</key>
<string>com.example.program</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockServiceName</key>
<string>8888</string>
<key>SockType</key>
<string>dgram</string>
<key>SockFamily</key>
<string>IPv4</string>
</dict>
</dict>
</dict>
</plist>

>>
kind of a dumb question, but should i remove print statements before making the executable a daemon? could that cause an error?
>>
Systemd services are bretty easy

[Unit]
Description=My Service Name

[Service]
ExecStart=/usr/local/bin/my-program --args


That's all there is for a systemd service, anything you print will get logged / visible in the output of `systemctl status` or journald if you have it.

Auto restart on crash is one extra line
Auto start on boot is one extra line
Changing user/group/working directory is one extra line

Sysvinit scripts require 100+ line switch statement and manual PID file tracking.

$ find /etc/init.d/ -type f -exec wc -l {} \; | sort -h | tac | head
617 /etc/init.d/libvirt-guests
371 /etc/init.d/checkroot.sh
355 /etc/init.d/apache2
283 /etc/init.d/nfs-common
279 /etc/init.d/exim4
263 /etc/init.d/rc
251 /etc/init.d/udev
232 /etc/init.d/libvirtd
209 /etc/init.d/alsa-utils
207 /etc/init.d/networking
>>
>>61066676
>read about systemd services (and cry)
Are you retarded? systemd unit files are the easiest things in the world
>>
>>61067483
my problem is it works fine when i run in from the terminal, but when i launch it with systemd it runs but there's an error.

do i need to make any changes to the code to get it to run as a daemon?
>>
>>61066615

>>61067483
This guy is right.
Also there's system/user units so that non-sudoers can restart it if they want.

> the easy way
./myprogram > /dev/null 2&>1 &

> the ssh way
screen
./myprogram
C-a C-d

> the hacky login-time way
echo \n./myprogram >> ~/.bashrc

> the right way
Systemd
>>
>>61067624
>error
i mean i don't see an error.

i'm using system() to call a command line based on a network packet. just a proof of concept as of now, i'm aware of the security implications. i didn't think i would i need to change it to posix compliant code just to get it to run though
>>
>>61067666
Are you using relative paths in your call to system()? Check $PATH, try calling system with /usr/bin/my-child-process instead of my-child-process
>>
>>61067293
No, it'll just fail silently because that's the UNIX Way. :^)
>>
>>61067483
cool, thanks to you my program will be officially supporting gnu/linux
>>
>>61066671
So write an init script for it. I think systemd can still launch sysv init scripts and they're a bit easier to understand.
>>
>>61068462
are scripts an acceptable solution for software intended to be used by normies though?

that's the reason i want to be as elegant as possible with systemd, and launchctl
>>
>>61066615
There's pretty extensive documentation on how to create daemons for both Mac and Linux. For Linux specifically, you need to figure out which init system your distro uses.
>>
>>61066653
This
Thread posts: 22
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.