Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to follow the ArchWiki guide for writing a custom service file to launch DavMail as a system-wide daemon. Previously I had a line in my ~/.xinitrc that read

nohup /usr/bin/davmail /etc/conf.d/davmail.properties

as per the DavMail instructions (where /usr/bin/davmail is a symlink to /usr/share/java/davmail/davmail.sh). Now that I've made the computer into a headless server, I'd like the auto-launcher to be independent of an X session.

All the guides I've seen online for a DavMail initscript assume that the distro is using sysvinit, not systemd. My attempt at a custom systemd service file is

[Unit]
Description=DavMail Exchange Gateway
Requires=network.target
After=network.target

[Service]
Type=forking
RemainAfterExit=yes
ExecStart=/usr/bin/davmail /etc/conf.d/davmail.properties
ExecStop=killall davmail

[Install]
WantedBy=multi-user.target

which fails to fork properly. Prepending the ExecStart command with /usr/bin/nohup is no help, because systemd complains about an invalid argument (preferring to take control of the daemonization itself, if I'm correctly understanding previous forum answers). Changing the Service Type to oneshot or simple also fails.

I think an issue here is that DavMail requires a Java interpreter to run, and systemd service files aren't as flexible as shell scripts in handing off the job to a Java interpreter. But maybe there's a much simpler explanation. Has anyone successfully written a systemd service file for DavMail that they'd be willing to share?

share|improve this question
    
Following the steps in don_crissti's answer to a related query, I wrote a systemd service file that calls a shell script in /usr/lib/systemd/scripts/ , and now the DavMail daemon will launch without any problems. –  biqu Apr 2 '13 at 20:50
1  
If it's working, please feel free to post the script for other people! –  Wieland Apr 3 '13 at 10:13

2 Answers 2

You must define it as a simple service (the forking is for process that finishes when the daemon is already started). For it's working like a charm in Arch

[Unit]
Description=DavMail Exchange Gateway
Requires=network.target
After=network.target

[Service]
Type=simple
RemainAfterExit=no
ExecStart=/usr/bin/davmail /etc/conf.d/davmail.properties
ExecStop=killall davmail

[Install]
WantedBy=multi-user.target
share|improve this answer

For those that don't have a debian or a distro based on it and downloaded the generic Linux (other) package (that includes the davmail.sh), the following worked for me:

[Unit]
Description=DavMail Exchange Gateway
Requires=network.target
After=network.target

[Service]
Type=forking
PIDFile=/opt/davmail/davmail.pid
ExecStart=/opt/davmail/davmail.sh /opt/davmail/davmail.properties

[Install]
WantedBy=multi-user.target
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.