respawn service Debian Jessie without inittab - service

I've installed the last stable version of Debian (Jessie) and /etc/inittab doesn't exist. I have read the new init system is called Sysv.
I need to launch a service with parameter, I used to add a line in inittab like
u1:23:respawn:/etc/init.d/my_service foreground
I'm trying to add this one with sysvrc-conf -p but I don't know how...
How can I do that without inittab?
Thank you so much.

Found this question by google, maybe someone else finds this usefull: The new init system for Debian Jessie is systemd. The old way in Debian Wheezy was Sysv with /etc/inittab.
To create a respawn service with systemd just create a file in /etc/systemd/system/ i.e. mplayer2.service
[Unit]
Desription=mplayer with systemd, respawn
After=network.target
[Service]
ExecStart=/usr/bin/mplayer -nolirc -ao alsa -vo null -really-quiet http://stream.sunshine-live.de/hq/mp3-128/Facebook-og-audio-tag/
Restart=always
[Install]
WantedBy=multi-user.target
and activate it
systemctl enable mplayer2.service
reboot or start it manually
systemctl daemon-reload
systemctl start mplayer2.service
If you reboot or kill the process, it will be restarted automatically some seconds later.

Related

Can't see my dbus object when program run from systemctl service

I have a cpp application which broadcasts an object and its methods on the dbus. I try to run this program at startup with the following service file:
[Unit]
Description=Running dbus program
After=network.target
[Service]
Type=simple
ExecStart=/home/my_name/Documents/dbus/build/my_app
StandardOutput=console+journal
StandardError=console+journal
[Install]
WantedBy=multi-user.target
After reloading:
systemctl daemon-reload
and running it:
sudo systemctl start my_service.service
I got no error in the journal, but I cant see anything on the dbus (running d-feet, and browsing for my object, I cant find anything)
Running the exact same ExecStart:
/home/my_name/Documents/dbus/build/my_app
in the console works fine.
What am I missing? Thanks!
As you want your service to run on the session bus you will need to use:
sudo systemctl --user start my_service.service
Putting the file into /etc/systemd/user/ location will make it available to all users still.

Centos 7.6 emacsclient can't find socket

I followed the instructions
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-managing_services_with_systemd-unit_files
create a emacs.service under /etc/systemd/system/like this
Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
[Service]
Type=forking
ExecStart=/home/hye/bin/emacs --fg-daemon
ExecStop=/home/hye/bin/emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=always
[Install]
WantedBy=default.target
then I execute:
systemctl daemon-reload
systemctl start emacs.service
the emacs.service launched successfully
However when I run emacsclient -t in terminal, it shows:
emacsclient: can't find socket; have you started the server?
I find that if I switch to root and run emacsclient -t in terminal, it works well.
In fact, host name is /tmp/emacs0/server,
but I can't access it since it's owner is root.
emacsclient -t -s /tmp/emacs0/server
emacsclient: can't stat /tmp/emacs0/server: Permission denied
emacsclient: error accessing socket "/tmp/emacs0/server"
I have tried to add User option in emacs.service, like this
[Service]
User=hye
Group=hye
Type=forking
but systemctl can't start this service, it is always failed.
I have also tried to put emacs.service under ~/.config/systemd/user/
but centos 7 doesn't support systemctl --user.
system information:
Centos 7.6
Emacs-26.1 manually installed
Any advice would be appreciated!
I had the same problem....
..it came down to I was using emacs-snapshot for emacs in
update-alternatives --display emacs
..and a different version for emacsclient
Set it to the same version and then Good Things happened.
sudo update-alternatives --set emacsclient /usr/bin/emacsclient-snapshot

systemd service start fails: no service.mount unit

I wrote a program (node js, on Raspberry Pi) that I can start manually, but not as a systemd service:
pi#blueberry ~ $ systemd --version
systemd 215
+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
pi#blueberry ~ $ sudo systemctl daemon-reload
pi#blueberry ~ $ sudo systemctl start /etc/systemd/system/rfxtrx.service
Failed to start etc-systemd-system-rfxtrx.service.mount: Unit etc-systemd-system-rfxtrx.service.mount failed to load: No such file or directory.
pi#blueberry ~ $
The error message complains that there is no rfxtrx.service.mount unit. Correct. Should there be such unit? The most common suggestion is to daemon-reload; this doid not help. Or as per https://github.com/systemd/systemd/issues/5375 this could be a bug in systemd that was fixed but only in a later systemd version than the one in raspbian (raspbian has version 215).
Is there any other solution than trying to update to a version not supported by the raspbian maintainers?
Well the first problem here is that you're running to start the service name rfxtrx.service however systemd is expecting etc-systemd-system-rfxtrx.service.mount.
If you are trying to have a systemd mount configuration then your file name should follow the following rule:
Mount units must be named after the mount point directories they
control. Example: the mount point /home/lennart must be configured in
a unit file home-lennart.mount.
So if you were wanting to create a mount point at say /dir/to/rfxtrx then the systemd mount file needs to be named dir-to-rfxtrx.mount, and it's recommended that it sits in either /usr/lib/systemd/system/ or /etc/systemd/system/ with the latter directory taking precedence.
If you just wanted to have a service file then enable the unit systemctl enable rfxtrx.service. systemctl daemon-reload is used when the unit has already been registered with systemd and requires a reload.
You can check if the service exists with systemd by using the command systemctl list-units or systemctl status rfxtrx.service.
The error you have is that you're doing sudo systemctl start /etc/systemd/system/rfxtrx.service instead of sudo systemctl start rfxtrx.service.

Best way to run a pyramid pserve server as daemon

I used to run my pyramid server as a daemon with the pserve --daemon command.
Given that it's deprecated, I'm looking for the best replacement. This link recommends to run it with screen or tmux, but it seems too heavy to just run a web server. Another idea would be to launch it with setsid.
What would be a good way to run it ?
Create a service file in /etc/systemd/system. Here a example (pyramid.service):
[Unit]
Description=pyramid_development
After=network.target
[Service]
# your Working dir
WorkingDirectory=/srv/www/webgis/htdocs/app
# your pserve path with ini
ExecStart=/srv/www/app/env/bin/pserve /srv/www/app/development.ini
[Install]
WantedBy=multi-user.target
Enable the service:
systemctl enable pyramid.service
Start/Stop/Restart the service with:
systemctl start pyramid.service
systemctl restart pyramid.service
systemctl stop pyramid.service
The simplest option is to install supervisord and setup a conf file for the service. The program would just be env/bin/pserve production.ini. There are countless examples online of how to do this.
The best option is to integrate with your system's process manager (systemd usually, but maybe also upstart or sysvinit or openrc). It is very easy to write a systemd unit file for starting pserve and then it will be started/stopped along with the rest of your system. Log files are even handled automatically in these cases.

systemctl enable works but systemctl --user enable does not

I have a DO droplet running Ubuntu 16.04.1x64 and I'm trying to run IPFS as a systemd service. I've gone ahead and created a user "connor" and installed IPFS following the instructions here. I'm storing the service as "ipfs.service" in ~/.config/systemd/user/ipfs.service which looks like this:
[Unit]
Description=IPFS Daemon
[Service]
Type=simple
ExecStart=/usr/local/bin/ipfs daemon
ExecStop=/usr/bin/pkill ipfs
Restart=always
User=Connor
[Install]
WantedBy=default.target
What's odd is that if I run systemctl --user start ipfs it starts up just fine. However, running systemctl --user daemon-reload and then
systemctl --user enable ipfs I get the error:
Failed to execute operation: No such file or directory
However, if I run systemctl enable /home/connor/.config/systemd/user/ipfs.service -f it runs just fine. I can reboot and run IPFS commands just fine. I'd like to run it as a user though, and would also like to understand what I'm doing wrong.
Please, check that you are executing the commands with connor user, you may run whoami to see the user executing the command. (running the command with sudo changes the user to root)
In addition, I see that the user in the service file is capitalized (Connor instead of connor), this could bring other problems, and it is not needed, as a simple configuration like the one proposed by Arch Linux wiki works for user daemons.
Please find bellow the configuration I used for my ipfs daemon, (without User= and with a different Restart=, since Restart=always gave me problems while starting the daemon):
[Unit]
Description=IPFS daemon
After=network.target
[Service]
ExecStart=/usr/local/bin/ipfs daemon
Restart=on-failure
[Install]
WantedBy=default.target