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?
>>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