I am working to create a service that triggers a script upon boot. The script then installs and activates a piece software. I only want this service to run once so that it installs the software on initial boot. This is being built into an AMI for standard deployment in an enterprise.
I currently have the following:
/etc/systemd/system/startup.service (executable using chmod +x; enabled using "systemctl enable startup.service")
/var/tmp/LinuxDeploymentScript.sh
The service contains:
[Unit]
After=remote-fs.target
[Service]
Type=oneshot
User=root
ExecStart=/var/tmp/LinuxDeploymentScript.sh
[Install]
WantedBy=multi-user.target
When I test the service by using systemctl start startup.service it runs successfully, but when I leave it enabled and reboot the system, it fails to activate:
Screenshot of failure log
Any help would be great. I have a thought that it could be my After= setting may not be far enough into the computer spinning up to be successful.
Related
telnet is necessary in order to maintain compatibility with older software in this case. I'm working with the Yocto Rocko 2.4.2 distribution. when I try to telnet to the board I'm getting the oh so detailed message "connection refused".
Using the method here and the options here I modified the busybox configuration per suggestion. When the board is booted up and logged in, if you execute: telnet, it spits out usage info and a quick directory check shows that telnet is installed to /usr/bin/telnet. My guess is that the telnet client is installed but the telnet server is not running?
I need to get telnetd to start manually at least so I know it will work with an init script in place. The second reference link there suggests that 'telnetd will not be started automatically though...' and that there will need to be an init script. How can I start telnetd manually for testing?
systemctl enable telnetd
returns: Unit telnetd.service could not be found
UPDATE
telnetd in located in /usr/sbin/telnetd. I was able to manually start the telnetd service for testing from there. After manually starting the service telnet login now works. looking into writing a systemd init script to auto start the telnetd service, so I suppose this issue is closed. unless anyone would like to offer up detailed telnet busybox configuration and setup steps as an answer to 'How to configure telnet service for yocto image'
update
Perhaps there is something more? I created a unit file that looks like this:
[Unit]
Description=auto start telnetd
[Service]
ExecStart=/usr/sbin/telnetd
[Install]
WantedBy=multi-user.target
on reboot, systemd indicates the process executed and succeeded:
systemctl status telnetd
.
.
.
Process: 466 ExecStart=/usr/sbin/telnetd (code=exited, status=0/SUCCESS)
.
.
.
The service is not running however. netstat -l does not list it and telnet login fails. Something I'm missing?
last update...i think
so following this post, I managed to get telnet.socket service to startup on reboot.
systemctl status telnet.socket
shows that it is running and listening on 23. Now however, when I try to remote in with telnet I'm getting
Connection closed by foreign host
Everything I've read so far has been talking about xinetd service (which I do not have...). What is confusing is that, if I just navigate to /usr/sbin/ and execute telnetd, the server is up and running and I can telnet into the board, so I do not believe I'm missing any utilities or services (like the above mentioned xinetd), but something is still not being configured correctly. any ideas?
I just downloaded jbpm server from JBPM.
it starts by running "jbpm-server/bin/standalone.sh" this. But i want to start jbpm as ubuntu's service like---> systemctl start jbpm.
can anyone provide me details to create startup script for this.
You should create a file in your systemd directory, for example /etc/systemd/system/change_me.service and fill it with a basic setup like:
[Unit]
Description=Your service's description
[Service]
ExecStart=/path/to/executable.sh
[Install]
WantedBy=multi-user.target
Then you should reload your systemd configuration in order to update it with the new service via
sudo systemctl daemon-reload
And then start it
sudo systemctl start change_me
If you want a more granular control over your systemd's service file you should read the man page via:
man systemd.service
I have created a service(name- develop) using systemd. Following is the content of my develop unit file -
Description=Develop Manager Service
[Service]
Type=forking
PIDFile = /home/nayasa/data/var/run/developPid
User=root
Group=root
ExecStartPre = /bin/bash /home/nayasa/control_scripts/develop_startPre.sh
ExecStart =/bin/bash /home/nayasa/control_scripts/develop_start.sh
ExecStop =/bin/bash /home/nayasa/control_scripts/develop_stop.sh
[Install]
WantedBy=multi-user.target
My develop.service forks multiple processes during runtime.
Whenever I run systemctl stop develop.service , systemd stops all processs in the CGroup of my develop service whereas the develop_stop script that I have provided only kills the main process using pid from pidfile. I want to stop only the main process. It seems to me that systemd is not using my stop script. How do I force systemd to execute my stop script to stop the service and not kill all processes of the Cgroup? FYI- I know that using KillMode option I can direct systemd to kill only main process and leave other processes, but I want to know why is my script not being executed?
It's a little weird to expect orphaned processes to persist after stopping a service. You would be left with a system that's in an unknown state. What would happen if you started the service again?
I think what you probably want is more complicated than a single service.
Let's say you wanted develop.service to launch proc1 and proc2. You want systemctl stop develop.service to kill proc1 but not proc2. In this case, you still need something to manage proc2 otherwise you have a rogue orphaned unmanaged and monitored process. The answer is to use another service.
Instead, try making two services. develop.service would launch proc1, possibly using your scripts. Then add a Wants=proc2.service to your [Unit] section. proc2.service would be responsible for proc2.
This means systemctl start develop.service will launch proc1 and proc2. Meanwhile systemctl stop develop.service will only kill proc1. proc2 can still be stopped/monitored by inspecting proc2.service.
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.
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