disable logging of a service to journald altogether - service

I have a service which logs unnecessary messages to journald.
Can this be switched off completely?
I tried to get it done with log4j.properties that belongs to the service, but that did not help
Regards Hans

StandardOutput and StandardError is connected to the journal by default. But you can customize this in your [Service] section and redirect both to /dev/null:
[Service]
...
StandardOutput=null
StandardError=null

Related

Yocto Syslog will not create folder

I have a Yocto build that utilises syslog and logrotate. I have configured my syslog to place any DEBUG messages into a log stored in a hidden folder. This will allow my team to retrieve in field logs without exposing them to the end user.
Syslog logs anything not DEBUG to /var/log as expected. The DEBUG logs go to /home/root/.hidden_logs.
My issue is, if the .hidden_logs folder is deleted, syslog stops logging DEBUG messages. When I run cat /etc/passwd I do not see a syslog user. Is there a way to tell syslog to create /home/root/.hidden_logs if it does not already exist? If not, my plan is to have my application check if the folder exists on boot, if not, create it.

systemd (new style) daemon in C/C++

On the Internet there are multiple code example which explains how to write the old style daemon in pure C or even in C++.
However, there is no such thing for a "new style" (or systemd one).
Is there a basic "simple daemon" code I can re-use to write a "new style" systemd daemon in C/C++?
I have many examples in my Snap! C++ environment. Look for the *.service files under the snapwebsites/debian directory to find the projects that act as a daemon.
More or less, you write a tool that opens a port to listen on and handle the messages you receive. The rest is taken care of by systemd.
Here is an example used by the snapfirewall daemon:
# Documentation available at:
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
[Unit]
Description=Snap! Websites snapfirewall daemon
After=snapbase.service snapcommunicator.service snapdbproxy.service
Before=fail2ban.service
[Service]
Type=simple
WorkingDirectory=~
ProtectHome=true
# snapfirewall needs to run iplock which setuid to root so we can't set
# this parameter to true
NoNewPrivileges=false
ExecStart=/usr/sbin/snapfirewall
ExecStop=/usr/bin/snapstop --service "$MAINPID"
Restart=on-failure
RestartSec=1min
User=snapwebsites
Group=snapwebsites
LimitNPROC=1000
# For developers and administrators to get console output
#StandardOutput=tty
#StandardError=tty
#TTYPath=/dev/console
# Enter a size to get a core dump in case of a crash
#LimitCORE=10G
[Install]
WantedBy=multi-user.target
# vim: syntax=dosini
As mentioned at the top, the service unit documentation is found on freedesktop.
In this one, I have a NoNewPrivileges=false parameter. This means the suid will work as expected. Otherwise my tool could not add/remove rules to the firewall since the snapfirewall runs as the snapwebsites user, which can't run iptables at all.
That's pretty much all there is to it.
Note: The advantage of using a debian directory and building your own package is that it will automatically generate all the necessary scripts to start/enable/stop your service as expected. The only trick on this one is that the debian/rules must include the --with systemd command line option. But outside of that, it's going to be a breeze. (Update: on newer systems, at least Ubuntu 22.04+, the --with systemd is the default and as such is not required anymore)

Setup rsyslog to send log to remote syslogserver but not to messages/syslog

I am running an ELK-Stack as a central syslogserver and I set up rsyslog to send logfiles, which are not logging into /var/lib/messages by default, to it.
The setup is working very well but since I made the configuration the external logfiles actually show up in the messages file, which is blowing it out of proportion and makes debugging normal systemlogs difficult.
I want the logs to be send to the syslogserver but not into the messages file.
This is my current configuration:
111-elk-syslog.conf:
*.* ##IP_OF_THE_SYSLOGSERVER:514
101-external-log.conf
$ModLoad imfile
$InputFileName PATH_TO_LOGFILE
$InputFileTag FILE_TAG
$InputFileStateFile FILE_TAG
$InputFileFacility local3
$InputRunFileMonitor
I know, using filebeat, I could circumvent this but rsyslog is working very well in my enviroment and this application is the only one logging so much, that this is an actual problem.
I don't understand in detail your setup, but it may help to know that in general in rsyslogd if you don't want further handling of a message that you have matched, you simply repeat the filter on the next line by using &, and the action stop. For example, you might try
*.* ##IP_OF_THE_SYSLOGSERVER:514
& stop

DBus how to start service

I am curious how to start my own service for DBus.
On official site I have found a lot of information regarding working with DBus services from client point of view, but how to start and develop service not enough:
1) Where should be located interface file ServiceName.xml
2) Where should be located service file ServiceName.service
3) How to launch service manually, not on start of system.
Can anybody help me or provide some usefull links ?
Make a service that is started by the service manager of the OS (initd, systemd,etc). In that program instantiate the server-side object using the dbus library.
Normally, you'll configure to start the service on boot, but with systemd it's also possible to configure it to start when something connects to specific socket or when something tries to use specific device object. It's called 'socket activation' and 'dbus activation' (see current systemd docs).
If you want to start service manually - then do systemctl disable <service-name> to disable start on boot. To start a service manually: systemctl start <service-name>.
The *.xml files aren't obligatory. Maybe look into other packages to see where they put these files.
The *.systemd files should be in some usual place (see systemd docs) like /usr/lib/systemd/system.

how to stop syslog messages to write console on solaris

how to stop syslog messages to write console on solaris ?
you can edit the entries in the /etc/syslog.conf to direct to another file eg /var/log/syslog instead of /dev/console. After that, issue kill -HUP <pid of syslog daemon> to "reinitialize" the config
it should be
svcadm disable svc:/system/system-log:default
svcadm disable svc:/system/system-log:default turned syslog off you need to also run svcadm enable svc:/system/system-log:default to turn it back on, after you made the right changes to /etc/syslog.conf so it does what you want. You can probably just comment out the line as it is also logged to file in /var/adm/messages.log
Turning syslog off is not a good idea.