How to port an RPM package consist of SysV init script to systemd? - linux

I have created an RPM package for my daemon which on installation create service init script under /etc/init.d/
Now I wanted to port this RPM package for CentOS7.1 and use systemd framework for service startup through boot as well as by admin through start/stop command.
I couldn't find any tutorial. Please help.
EDIT:
I tried the suggestion given by msuchy.
I tried and here is my observation
On sysV based framework (CentOS6.5)
[root#adil work]# /etc/init.d/daemon_script status
Service daemon: Stopped
[root#adil work]# /etc/init.d/daemon_script start
Starting daemon: Initializing daemon... [ OK ]
[root#adil work]#
[root#adil work]# /etc/init.d/daemon_script status
Service daemon: Running
[root#adil work]#
[root#adil work]# /etc/init.d/daemon_script stop
Shutting down parent daemon: [ OK ]
[root#adil work]# /etc/init.d/daemon_script status
Service daemon: Stopped
[root#adil work]#
===========
On systemd based framework, I install the same RPM on CentOS7.1
[root#localhost x86_64]# /etc/init.d/daemon_script
Usage: /etc/init.d/daemon_script {start|stop|restart|status}
[root#localhost x86_64]# /etc/init.d/daemon_script start
Starting daemon_script (via systemctl): Warning: Unit file of daemon_script.service changed on disk, 'systemctl daemon-reload' recommended.
Job for daemon_script.service failed. See 'systemctl status daemon_script.service' and 'journalctl -xn' for details.
[FAILED]
[root#localhost x86_64]# systemctl daemon-reload
[root#localhost x86_64]# systemctl status daemon_script.service
daemon_script.service - SYSV: start and stop Test daemon service.
Loaded: loaded (/etc/rc.d/init.d/daemon_script)
Active: failed (Result: exit-code) since Fri 2015-09-11 15:30:44 IST; 32s ago
Sep 11 15:30:44 localhost.localdomain systemd[1]: Starting SYSV: start and st...
Sep 11 15:30:44 localhost.localdomain systemd[1]: daemon_script.service: cont...
Sep 11 15:30:44 localhost.localdomain systemd[1]: Failed to start SYSV: start...
Sep 11 15:30:44 localhost.localdomain systemd[1]: Unit daemon_script.service ...
Hint: Some lines were ellipsized, use -l to show in full.
[root#localhost x86_64]# systemctl status daemon_script.service -l
daemon_script.service - SYSV: start and stop Test daemon service.
Loaded: loaded (/etc/rc.d/init.d/daemon_script)
Active: failed (Result: exit-code) since Fri 2015-09-11 15:30:44 IST; 46s ago
Sep 11 15:30:44 localhost.localdomain systemd[1]: Starting SYSV: start and stop Test daemon service....
Sep 11 15:30:44 localhost.localdomain systemd[1]: daemon_script.service: control process exited, code=exited status=203
Sep 11 15:30:44 localhost.localdomain systemd[1]: Failed to start SYSV: start and stop Test daemon service..
Sep 11 15:30:44 localhost.localdomain systemd[1]: Unit daemon_script.service entered failed state.
[root#localhost x86_64]#
output of journalctl -xn
-- Logs begin at Fri 2015-09-11 14:50:35 IST, end at Fri 2015-09-11 15:40:01 IST. --
Sep 11 15:31:03 localhost.localdomain systemd[1]: [/usr/lib/systemd/system/dm-event.socket:10] Unknown lvalue 'RemoveOnStop' in section 'Socket'
Sep 11 15:39:33 localhost.localdomain systemd[1]: Starting SYSV: start and stop Test daemon service....
-- Subject: Unit daemon_script.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit daemon_script.service has begun starting up.
Sep 11 15:39:33 localhost.localdomain systemd[8509]: Failed at step EXEC spawning /etc/rc.d/init.d/daemon_script: Exec format error
-- Subject: Process /etc/rc.d/init.d/daemon_script could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /etc/rc.d/init.d/daemon_script could not be executed and failed.
--
-- The error number returned while executing this process is 8.
Sep 11 15:39:33 localhost.localdomain systemd[1]: daemon_script.service: control process exited, code=exited status=203
Sep 11 15:39:33 localhost.localdomain systemd[1]: Failed to start SYSV: start and stop Test daemon service..
-- Subject: Unit daemon_script.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit daemon_script.service has failed.
--
-- The result is failed.
Sep 11 15:39:33 localhost.localdomain systemd[1]: Unit daemon_script.service entered failed state.
Sep 11 15:40:01 localhost.localdomain systemd[1]: Created slice user-0.slice.
-- Subject: Unit user-0.slice has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit user-0.slice has finished starting up.
--
-- The start-up result is done.
Sep 11 15:40:01 localhost.localdomain systemd[1]: Starting Session 7 of user root.
-- Subject: Unit session-7.scope has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-7.scope has begun starting up.
Sep 11 15:40:01 localhost.localdomain systemd[1]: Started Session 7 of user root.
-- Subject: Unit session-7.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-7.scope has finished starting up.
--
-- The start-up result is done.
Sep 11 15:40:01 localhost.localdomain CROND[8528]: (root) CMD (/usr/lib64/sa/sa1 1 1)
[root#localhost x86_64]#

You do not need to migrate your scripts.
It is probably better and you can utilize some interesting functions of Systemd, your files will be smaller. But you do not need to migrate. Systemd works correctly with SysV init files too.
You can not locate any SysV init files on CentOS 7 installation because Red Hat packagers (who created CentOS) put an effort into packaging and migrated all SysV files to unit files. But you do not need to.
The is only one task you need to do. Once you place new SysV file, you must reload the systemd manager configuration using
# systemctl daemon-reload
That is all.
I give you small example
# cat /etc/init.d/foo
#!/usr/bin/sh
echo ahoy
# chmod a+x /etc/init.d/foo
# systemctl start foo
Failed to start foo.service: Unit foo.service failed to load: No such file or directory.
# systemctl daemon-reload
# systemctl start foo
# journalctl -xn
-- Subject: Unit foo.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit foo.service has finished starting up.
--
-- The start-up result is done.
# service foo start
ahoy
So you can use all command (chkconfig, service) as you are used to from CentOS 6. And when you have time, you can study man systemd.unit(5) and bunch of other man pages (see "SEE ALSO" of that man page).

Related

Error installing docker on Arch Linux: error initializing graphdriver: loopback attach failed

So I stupidly got a laptop with the latest and greatest hardware, so I had to install ArchLinux (version 5.19.13-arch1-1) instead of debian. I'm only vaguely familiar with linux, my fiance has been helping but this has him stumped too so here we are.
I followed the wiki instructions for installing docker, but consistently get the following error when attempting to start the service:
sudo journalctl --since "5 minutes ago" -xeu docker.service
Oct 26 14:37:34 werk systemd[1]: docker.service: Start request repeated too quickly.
Oct 26 14:37:34 werk systemd[1]: docker.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit docker.service has entered the 'failed' state with result 'exit-code'.
Oct 26 14:37:34 werk systemd[1]: Failed to start Docker Application Container Engine.
░░ Subject: A start job for unit docker.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit docker.service has finished with a failure.
░░
░░ The job identifier is 10988 and the job result is failed.
lines 334-369/369 (END)
sudo journalctl --since "5 minutes ago" -ru docker.service
Oct 26 14:37:34 werk systemd[1]: Failed to start Docker Application Container Engine.
Oct 26 14:37:34 werk systemd[1]: docker.service: Failed with result 'exit-code'.
Oct 26 14:37:34 werk systemd[1]: docker.service: Start request repeated too quickly.
Oct 26 14:37:34 werk systemd[1]: Stopped Docker Application Container Engine.
Oct 26 14:37:34 werk systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Oct 26 14:37:34 werk systemd[1]: Failed to start Docker Application Container Engine.
Oct 26 14:37:34 werk systemd[1]: docker.service: Failed with result 'exit-code'.
Oct 26 14:37:34 werk systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Oct 26 14:37:34 werk dockerd[71427]: failed to start daemon: error initializing graphdriver: loopback attach failed
I don't really understand loopback devices, but the result of losetup -f seemed sus:
losetup -f
losetup: cannot find an unused loop device: Permission denied
[me#werk ~]$ sudo losetup -f
losetup: cannot find an unused loop device: No such device
We also theorized that the docker user didn't have sufficient permissions to do what it needed to do, but could not find any user specified in the docker.service file (located at /etc/systemd/system/multi-user.target.wants/docker.service). We tried to run the ExecStart command line specified in the docker.service file as root, but got the following error:
[me#werk ~]$ sudo /usr/bin/dockerd -H fd://
[sudo] password for me:
INFO[2022-10-26T14:56:00.483059782-06:00] Starting up
failed to load listeners: no sockets found via socket activation: make sure the service was started by systemd
So that was a bit of a bust.
To be extra clear, installation was as follows:
pacman -Syu docker
systemctl enable docker.service
systemctl start docker.service
And in case it matters, I'm on a Framework laptop with 12th gen Intel core processors.

Not able to start redhat httpd service

When I try to start the httpd service it is failing with the error :
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.
output of journalctl -xe
The result is failed.
Dec 08 04:09:49 uls-**** systemd[1]: Unit httpd.service entered failed state.
Dec 08 04:09:49 uls-******** systemd[1]: httpd.service failed.
Dec 08 04:09:49 uls-******** sudo[67525]: pam_unix(sudo:session): session closed for user root
Dec 08 04:09:49 uls-******** polkitd[854]: Unregistered Authentication Agent for unix-process:67526:3062933569 (system bus name :1.159161, object path /org/
Dec 08 04:10:01 uls-******** systemd[1]: Started Session 78106 of user root.
-- Subject: Unit session-78106.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-78106.scope has finished starting up.
--
-- The start-up result is done.
Dec 08 04:10:01 uls-******** systemd[1]: Started Session 78107 of user root.
-- Subject: Unit session-78107.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-78107.scope has finished starting up.
--
-- The start-up result is done.
Dec 08 04:10:01 uls-******** CROND[67561]: (root) CMD (/usr/share/spamassassin/sa-update.cron 2>&1 | tee -a /var/log/sa-update.log)
Dec 08 04:10:01 uls-******** CROND[67562]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Dec 08 04:20:01 uls-******** systemd[1]: Started Session 78109 of user root.
-- Subject: Unit session-78109.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-78109.scope has finished starting up.
--
-- The start-up result is done.
Dec 08 04:20:01 uls-******** systemd[1]: Started Session 78108 of user root.
-- Subject: Unit session-78108.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-78108.scope has finished starting up.
--
-- The start-up result is done
.
output of systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2021-12-08 04:26:51 PST; 53s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 68719 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
Main PID: 68719 (code=exited, status=1/FAILURE)
I tried to change the port number in httpd.conf file. But I got the same error. Can anyone please help?
try check your config, validate from command apachectl configtest

How to add MACs and KEX algorithms in /etc/ssh/sshd_config on Ubuntu 18.04 on GCP

I added following MACs to /etc/ssh/sshd_config of Ubuntu 18.04 compute instance on GCP. But after updating the file ssh is not restarting and journalctl -xe shows /etc/ssh/sshd_config line 130: Bad SSH2 mac spec.
MACs hmac-sha1-512-etm#openssh.com,hmac-sha1-512-etm#openssh.com,umac-128-etm#openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128#openssh.com
I see following error when I try to restart ssh:
$ sudo systemctl restart ssh
Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.
$ journalctl -xe
--
-- Unit ssh.service has begun starting up.
Aug 02 11:37:17 ubuntu1804 sshd[23779]: /etc/ssh/sshd_config line 130: Bad SSH2 mac spec 'hmac-sha1-512-etm#openssh.com,hmac-sha1-512-etm#openssh.com,umac-128-etm#open
Aug 02 11:37:17 ubuntu1804 systemd[1]: ssh.service: Control process exited, code=exited status=255
Aug 02 11:37:17 ubuntu1804 systemd[1]: ssh.service: Failed with result 'exit-code'.
Aug 02 11:37:17 ubuntu1804 systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit ssh.service has failed.
--
-- The result is RESULT.
Aug 02 11:37:17 ubuntu1804 systemd[1]: ssh.service: Service hold-off time over, scheduling restart.
Aug 02 11:37:17 ubuntu1804 systemd[1]: ssh.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Automatic restarting of the unit ssh.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Aug 02 11:37:17 ubuntu1804 systemd[1]: Stopped OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has finished shutting down
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit ssh.service has finished shutting down.
Aug 02 11:37:17 ubuntu1804 systemd[1]: ssh.service: Start request repeated too quickly.
Aug 02 11:37:17 ubuntu1804 systemd[1]: ssh.service: Failed with result 'exit-code'.
Aug 02 11:37:17 ubuntu1804 systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit ssh.service has failed.
--
-- The result is RESULT.
Following is the error received when I try to connect after logoff from the existing ssh session.
ubuntu1804> gcloud compute ssh ubuntu1804 --zone us-east1-b
ssh: connect to host 35.237.57.183 port 22: Connection refused
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
I did not find a single clue about this in google cloud documentation. I can fix the server but I would like to know what is the right way to add such configuration in sshd_config on a Ubuntu linux on GCP.
Verify acceptable values for MACs with ssh -Q mac. I'd assume hmac-sha1-512-etm#openssh.com and hmac-sha1-512-etm#openssh.com won't be there.

How do I run a Node.js app as a systemd service?

So I have a node.js app that I am trying to deploy and run as a systemd service.
Here's the .service file:
[Unit]
Description=My app
[Service]
ExecStart=/usr/local/bin/node /var/www/html/schema.js
Restart=always
User=root
Group=nogroup
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/www/html
[Install]
WantedBy=multi-user.target
Unfortunately, it just does not work.... I keep getting an error:
Feb 12 09:56:49 myswerth systemd[1]: Started my-app app.
-- Subject: Unit my-app.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit my-app.service has finished starting up.
--
-- The start-up result is done.
Feb 12 09:56:49 my-server systemd[23765]: Failed at step GROUP spawning /usr/local/bin/node: No such process
-- Subject: Process /usr/local/bin/node could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/local/bin/node could not be executed and failed.
--
-- The error number returned by this process is 3.
Feb 12 09:56:49 myswerth systemd[1]: my-app.service: main process exited, code=exited, status=216/GROUP
Feb 12 09:56:49 myswerth systemd[1]: Unit my-app.service entered failed state.
Feb 12 09:56:49 myswerth systemd[1]: my-app.service failed.
Feb 12 09:56:49 myswerth systemd[1]: my-app.service holdoff time over, scheduling restart.
Feb 12 09:56:49 myswerth systemd[1]: Stopped My app app.
-- Subject: Unit my-app.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit my-app.service has finished shutting down.
I'm not really sure why it is kicking up this error. I have tried to access the file manually and can confirm it is located in /usr/local/bin/node and furthermore that I can open node by running it (which I can?) so I have no clue why it cant execute? I have also checked the execute permissions. All user groups can execute so ya.... I'm at a loss here...
Make sure node is in the path by running which node
Try the following:
in your schema.js file add the following line at the top
#!/usr/bin/env node
this will remove the need to specify the node in the ExecStart
Also make sure to
chmod +x /var/www/html/schema.js
Additional options worth considering adding to the Service definition:
PIDFile=/tmp/your-app-name.pid
KillSignal=SIGQUIT
WorkingDirectory=/var/www/html/
Try to fix to use:
Group=root

Puppet Server not starting up in Centos7

I have recently installed puppet5 in Centos7 (Running in VirtualBox). After installation I tried starting it which thrown the below message.
Is there anything should I do with configuration?
[root#puppet ~]# systemctl status puppetserver -l
● puppetserver.service - puppetserver Service
Loaded: loaded (/usr/lib/systemd/system/puppetserver.service; enabled; vendor preset: disabled)
Active: activating (start) since Thu 2018-01-25 13:59:44 IST; 32s ago
Control: 10284 (bash)
CGroup: /system.slice/puppetserver.service
├─10284 bash /opt/puppetlabs/server/apps/puppetserver/cli/apps/start
├─10291 java -Xms2g -Xmx2g -XX:MaxPermSize=256m -Djava.security.egd=/dev/urandom -XX:OnOutOfMemoryError=kill -9 %p -cp /opt/puppetlabs/server/apps/puppetserver/puppet-server-release.jar:/opt/puppetlabs/server/apps/puppetserver/jruby-1_7.jar:/opt/puppetlabs/server/data/puppetserver/jars/* clojure.main -m puppetlabs.trapperkeeper.main --config /etc/puppetlabs/puppetserver/conf.d --bootstrap-config /etc/puppetlabs/puppetserver/services.d/,/opt/puppetlabs/server/apps/puppetserver/config/services.d/ --restart-file /opt/puppetlabs/server/data/puppetserver/restartcounter
└─10366 sleep 1
Jan 25 13:59:44 puppet systemd[1]: Starting puppetserver Service...
Journal Logs:
Jan 25 14:01:29 puppet puppetserver[10419]: Background process 10426 exited before start had completed
Jan 25 14:01:29 puppet systemd[1]: puppetserver.service: control process exited, code=exited status=1
Jan 25 14:01:29 puppet systemd[1]: Failed to start puppetserver Service.
-- Subject: Unit puppetserver.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit puppetserver.service has failed.
--
-- The result is failed.
It looks like the VM has insufficient memory to run the server.
Edit the file /etc/default/puppetserver and lower the values of
JAVA_ARGS=" -Xms2g -Xmx2g ...
to:
JAVA_ARGS="-Xms1g -Xmx1g ...
The VM must have at least 1GB RAM configured with the edited settings.

Resources