• Contribution: systemd startup file

    From Karloch@VERT to All on Sun Dec 11 14:37:40 2016
    Hi *.*,

    I spent this weekend performing maintenance tasks on my Synchronet based BBS, among them upgrading the distro to Ubuntu 16.04, which uses systemd as startup system. I had to upgrade from my SysV init scripts to this new model and I was not able to find a configuration file in the CVS repo.

    After browsing the wiki, I was able to find the article [1]. However, I though it lacks some features and I decided to improve it. The result is the following:

    ============ File: /lib/systemd/system/sbbs.service
    [Unit]
    Description=Synchronet BBS service
    Documentation=man:sbbs
    After=syslog.target network.target

    [Service]
    Environment=SBBSROOT=/sbbs SBBSCTRL=/sbbs/ctrl
    User=sbbs
    Group=sbbs
    PermissionsStartOnly=true
    ExecStartPre=/sbin/setcap 'cap_net_bind_service=+ep' /sbbs/src/sbbs3/gcc.linux.x64.exe.release/sbbs
    ExecStart=/sbbs/exec/sbbs nd syslog
    ExecReload=/bin/kill -HUP $MAINPID
    StandardInput=null
    StandardOutput=null
    Restart=on-failure
    RestartSec=30

    [Install]
    WantedBy=multi-user.target
    =============== EOF

    Some points in this config:
    * After. I'm using syslog with sbbs, so it was nice to put that requirement before systemd tries to launch sbbs.
    * Environment. In order to avoid having multiple files, I decided to put the environment variables inside the service file.
    * PermissionsStartOnly. This one tells systemd to execute ExecStartPre as root, but ExecStart as the user and group declared in User,Group.
    * ExecStartPre. For some weird reason I have not been able to trace, capabilities are frequently lost from the sbbs executable. This is really anoying, but I managed to mitigate the effect by running setcap just before everytime the daemon is ran. The binding won't fail anymore using this.
    * ExecStart. It's actually more useful to run sbbs without daemonize under systemd, in contrast to the SysV way, so the "nd" parameter is useful. However I didn't wanted this to prevent using the syslog, so I added the parameter and it is logging perfectly. Thanks Rob for implementing this! Please, note you can't point a symlink here, so modify the architecture directory to the right path (gcc.linux.x64.exe.release or gcc.linux.exe.release).
    * StandardInput/StandardOutput. For some reason, systemd was displaying control characters from the sbbs logging, making the logs anoying to read and systemd reporting "blob data". I discovered that it had something to do with the I/O treatment systemd does to the logging. Disabling it led me to sbbs logging playing nice with systemd journal, so null to them.
    * RestartSec. It's advisable to wait some secs before attempting restarting in case of failure, just to give some time for binding release.

    Installation instructions:
    1. Put this file in /lib/systemd/system/
    2. Run "systemctl enable sbbs"
    3. sbbs will be executed at startup and systemd will follow his execution

    It would be nice if this script can be uploaded to CVS repo. I'll contribute this to the wiki also.

    Thank you so much for your work with Synchronet!

    [1] http://wiki.synchro.net/es:howto:systemd
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net
  • From Digital Man@VERT to Karloch on Sun Dec 11 19:04:14 2016
    Re: Contribution: systemd startup file
    By: Karloch to All on Sun Dec 11 2016 02:37 pm

    It would be nice if this script can be uploaded to CVS repo. I'll contribute this to the wiki also.

    Yes, I agree. Can you email it to me (rob {at} synchro {dot} net) or just upload to vert?

    Right now, there's a few startup scripts under install/init.d:

    rswindell@cvs:~/sbbs/install$ ll init.d
    total 16
    drwxr-xr-x 2 rswindell sbbs 4096 Dec 11 19:03 CVS
    -rw-r--r-- 1 rswindell sbbs 2589 Feb 22 2005 sbbs
    -rw-r--r-- 1 rswindell sbbs 2494 Oct 17 2011 sbbs.debian
    -rw-r--r-- 1 rswindell sbbs 836 Oct 5 2013 sbbs.gentoo

    I'm assuming this new script should go under install/systemd or something similar?

    digital man

    Synchronet/BBS Terminology Definition #17:
    DSL = Digital Subscriber Line
    Norco, CA WX: 59.3øF, 85.0% humidity, 0 mph SE wind, 0.00 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net
  • From Karloch@VERT to Digital Man on Mon Dec 12 11:43:39 2016
    Re: Contribution: systemd startup file
    By: Digital Man to Karloch on Sun Dec 11 2016 07:04 pm

    Yes, I agree. Can you email it to me (rob {at} synchro {dot} net) or just upload to vert?

    Sure, I'll email I'll do both just in case.

    I'm assuming this new script should go under install/systemd or something similar?

    For the convenience of the user, I'll add setup instructions as comments in the file. Usually the file is placed in /lib/systemd/system/ and afterwards "$ sudo systemctl daemon-reload" and finally "$ sudo systemctl enable sbbs".

    To be honest, I think systemd is quite cumbersome, running at PID 1 and duplicating functionality of some daemons (cron, syslog, etc...). But like it or hate it, it looks like it is here to stay as major Linux distros already adopted it (Debian, Ubuntu, Redhat, etc...).

    Greets,
    Carlos
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net
  • From Karloch@VERT/HISPAMSX to Digital Man on Thu Dec 15 21:23:49 2016
    Re: Contribution: systemd startup file
    By: Digital Man to Karloch on Sun Dec 11 2016 19:04:14

    Yes, I agree. Can you email it to me (rob {at} synchro {dot} net) or just upload to vert?

    I have uploaded the file at the Synchronet 3rd Party file area in VERT, the name is sbbssysd.zip.

    I have applied the corrections according to the problems I was facing. The final file looks like this:

    ======== sbbs.service
    [Unit]
    Description=Synchronet BBS service
    Documentation=man:sbbs
    After=syslog.target network.target

    [Service]
    Type=forking
    Environment=SBBSROOT=/sbbs SBBSCTRL=/sbbs/ctrl
    User=sbbs
    Group=sbbs
    PermissionsStartOnly=true
    ExecStartPre=/sbin/setcap 'cap_net_bind_service=+ep' /sbbs/src/sbbs3/gcc.linux.x64.exe.release/sbbs
    ExecStart=/sbbs/exec/sbbs d
    ExecReload=/bin/kill -HUP $MAINPID
    Restart=on-failure
    RestartSec=30

    [Install]
    WantedBy=multi-user.target
    =========== EOF

    Thank you so much!
    Carlos

    ---
    þ Synchronet þ HISPAMSX BBS - The 8-bit MSX computers BBS - 2:345/111@fidonet
  • From Digital Man@VERT to Karloch on Thu Dec 15 18:16:34 2016
    Re: Contribution: systemd startup file
    By: Karloch to Digital Man on Thu Dec 15 2016 09:23 pm

    Re: Contribution: systemd startup file
    By: Digital Man to Karloch on Sun Dec 11 2016 19:04:14

    Yes, I agree. Can you email it to me (rob {at} synchro {dot} net) or just upload to vert?

    I have uploaded the file at the Synchronet 3rd Party file area in VERT, the name is sbbssysd.zip.

    Okay, thanks. I committed it to CVS.

    I have applied the corrections according to the problems I was facing. The final file looks like this:

    ======== sbbs.service
    [Unit]
    Description=Synchronet BBS service
    Documentation=man:sbbs
    After=syslog.target network.target

    [Service]
    Type=forking
    Environment=SBBSROOT=/sbbs SBBSCTRL=/sbbs/ctrl
    User=sbbs
    Group=sbbs
    PermissionsStartOnly=true
    ExecStartPre=/sbin/setcap 'cap_net_bind_service=+ep' /sbbs/src/sbbs3/gcc.linux.x64.exe.release/sbbs

    Any particular reason you need that abosolute path (above)? That's a very system specific element that makes this file require modification by most/many sysops to be utilized.

    digital man

    Synchronet "Real Fact" #47:
    The Synchronet Museum is online at http://wiki.synchro.net/history:museum: Norco, CA WX: 59.2øF, 86.0% humidity, 3 mph ESE wind, 0.00 inches rain/24hrs ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net
  • From Karloch@VERT/HISPAMSX to Digital Man on Fri Dec 16 10:55:53 2016
    Re: Contribution: systemd startup file
    By: Digital Man to Karloch on Thu Dec 15 2016 18:16:34

    Any particular reason you need that abosolute path (above)? That's a very system specific element that makes this file require modification by most/many sysops to be utilized.

    I know it is not convenient, but setcap doesn't support symlinks:

    $ setcap --help
    usage: setcap [-q] [-v] (-r|-|<caps>) <filename> [ ... (-r|-|<capsN>) <filenameN> ]

    Note <filename> must be a regular (non-symlink) file.

    Regards,
    Carlos

    ---
    þ Synchronet þ HISPAMSX BBS - The 8-bit MSX computers BBS - 2:345/111@fidonet
  • From Digital Man@VERT to Karloch on Fri Dec 16 17:33:18 2016
    Re: Contribution: systemd startup file
    By: Karloch to Digital Man on Fri Dec 16 2016 10:55 am

    Re: Contribution: systemd startup file
    By: Digital Man to Karloch on Thu Dec 15 2016 18:16:34

    Any particular reason you need that abosolute path (above)? That's a very system specific element that makes this file require modification by most/many sysops to be utilized.

    I know it is not convenient, but setcap doesn't support symlinks:

    $ setcap --help
    usage: setcap [-q] [-v] (-r|-|<caps>) <filename> [ ... (-r|-|<capsN>) <filenameN> ]

    Note <filename> must be a regular (non-symlink) file.

    I haven't tried, but wouldn't something like this work:
    ExecStartPre=readlink $SBBSROOT/exec/sbbs | xargs /sbin/setcap 'cap_net_bind_service=+ep'

    readlink dereferences the symlink and puts the output in stdout, the | redirects the stdout of readlinkt to the stdin of xargs which then executes the setcap with the last argument being replaced with the input from stdin.

    And of course, you'd have to initialize the SBBSROOT environment variable in their somewhere, but only have to specify the (potentially system-specific) path in one place would be preferable.

    digital man

    Synchronet "Real Fact" #20:
    Michael Swindell was directly responsible for Synchronet's commercial success. Norco, CA WX: 52.1øF, 76.0% humidity, 5 mph E wind, 0.71 inches rain/24hrs
    ---
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net
  • From Nicholas Boel@VERT to Digital Man on Fri Dec 16 19:50:20 2016
    Hello Digital,

    On Fri, 16 Dec 2016 17:33:18 -0800, Digital Man -> Karloch wrote:

    readlink dereferences the symlink and puts the output in stdout, the | redirects the stdout of readlinkt to the stdin of xargs which then
    executes the
    setcap with the last argument being replaced with the input from stdin.

    And of course, you'd have to initialize the SBBSROOT environment variable
    in
    their somewhere, but only have to specify the (potentially
    system-specific)
    path in one place would be preferable.

    I'm beginning to wonder if people are looking way too far into this. Service files for systemd are supposed to be easy, and not like the old sysvinit stuff.
    This is what I use here without any issues whatsoever:

    --[ /ets/systemd/system/sbbs.service ]--

    [Unit]
    Description=Synchronet BBS Software
    After=network.target

    [Service]
    EnvironmentFile=/etc/sysconfig/sbbs
    Type=forking
    ExecStart=/sbbs/exec/sbbs d
    ExecReload=/bin/kill -HUP $MAINPID
    Restart=always

    [Install]
    WantedBy=multi-user.target

    --[ End ]--

    And /etc/sysconfig/sbbs:

    --[ /etc/sysconfig/sbbs ]--

    SBBSCTRL=/sbbs/ctrl
    SBBSNODE=/sbbs/node1
    PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/sbbs/exec
    TERM=ansi-bbs

    --[ End ]--

    Haven't had an issue with it yet, and keeping it simple makes for a lot less headaches.

    Regards,
    Nick

    --- slrn/1.0.3 (Linux)
    * Origin: thePharcyde_ distribution system (1:154/10)
    þ Synchronet þ Vertrauen þ Home of Synchronet þ telnet://vert.synchro.net
  • From Ragnarok@docksud.com.ar to Nicholas Boel on Sun Dec 18 23:35:07 2016
    El 16/12/16 a las 22:50, Nicholas Boel escribió:
    Hello Digital,

    On Fri, 16 Dec 2016 17:33:18 -0800, Digital Man -> Karloch wrote:

    readlink dereferences the symlink and puts the output in stdout, the | redirects the stdout of readlinkt to the stdin of xargs which then
    executes the
    setcap with the last argument being replaced with the input from stdin.

    And of course, you'd have to initialize the SBBSROOT environment variable
    in
    their somewhere, but only have to specify the (potentially
    system-specific)
    path in one place would be preferable.

    I'm beginning to wonder if people are looking way too far into this. Service files for systemd are supposed to be easy, and not like the old sysvinit stuff.
    This is what I use here without any issues whatsoever:

    --[ /ets/systemd/system/sbbs.service ]--

    [Unit]
    Description=Synchronet BBS Software
    After=network.target

    [Service]
    EnvironmentFile=/etc/sysconfig/sbbs
    Type=forking
    ExecStart=/sbbs/exec/sbbs d
    ExecReload=/bin/kill -HUP $MAINPID
    Restart=always

    [Install]
    WantedBy=multi-user.target

    --[ End ]--

    And /etc/sysconfig/sbbs:

    --[ /etc/sysconfig/sbbs ]--

    SBBSCTRL=/sbbs/ctrl
    SBBSNODE=/sbbs/node1
    PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/sbbs/exec
    TERM=ansi-bbs

    --[ End ]--

    Haven't had an issue with it yet, and keeping it simple makes for a lot less headaches.

    Regards,
    Nick

    I agree, i use the settings for debian that had paste in the sbbs wiki.
    Simple and clean.