Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
96 lines (80 sloc) 2.16 KB

Daemonize Cheat Sheet

Windows

Download NSSM

Run Command Prompt as an administrator and type:

nssm.exe install [ServiceName]

On the NSSM window, enter the following info

Application

Path: C:\path\to\file.exe
Startup directory: C:\path\to\
Arguments: arg1 arg2

Details

Display name: [ServiceName]
Description: [A Description]

I/O

Output: C:\path\to\stdout.log
Error: C:\path\to\stderr.log

To start your service

net start [ServiceName]

Uninstall service

net stop [ServiceName]
nssm remove [ServiceName]

OS X

Create a Launch daemon

sudo nano  /Library/LaunchDaemons/org.yourdaemon.plist

Paste your custom XML

<?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>Label</key>
                <string>org.yourdaemon.proxy</string>
                <key>RunAtLoad</key>
                <true/>
                <key>ProgramArguments</key>
                <array>
                        <string>/path/to/bin/file</string>
                        <string>arg1</string>
                        <string>arg2</string>
                        <string>arg3</string>
                </array>
                <key>RunAtLoad</key>
                <true/>
                <key>KeepAlive</key>
                <false/>
                <key>WorkingDirectory</key>
                <string>/path/to/working/directory/</string>
                <key>StandardErrorPath</key>
                <string>/path/to/err.log</string>
                <key>StandardOutPath</key>
                <string>/path/to/out.log</string>
        </dict>
</plist>

Change permissions, load and start

sudo /usr/sbin/chown root:wheel /Library/LaunchDaemons/org.yourdaemon.plist
sudo /bin/launchctl load /Library/LaunchDaemons/org.yourdaemon.plist
sudo /bin/launchctl start org.yourdaemon

Stop and Remove

sudo /bin/launchctl stop org.yourdaemon
sudo /bin/launchctl unload /Library/LaunchDaemons/org.yourdaemon.plist
sudo rm /Library/LaunchDaemons/org.yourdaemon.plist
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.