180

The following example is inspired by this link, which actually does not mention all steps and is listed just to credit the source: http://patrakov.blogspot.com/2011/01/writing-systemd-service-files.html Step 1: I created this file (note location) which essentially fires a bash process with an extended argument. You could fire your own command which could be ...


165

Ubuntu calls the service ssh, not sshd. service ssh restart The service is also controlled by upstart, and not sysvinit. So you'll find it at /etc/init/ssh.conf instead of /etc/init.d/ssh.


122

There are currently 3 main init systems used by linux. A few years ago, there was just one, SysVinit. But SysVinit was seriously lacking in capabilities such as service dependency graphing, so it's been deprecated in most distros by now. Currently most distros are switching to systemd. Though there is also upstart. But here's the answer to your question for ...


84

Since Ubuntu has recently switched over to systemd, some services will be listed by upstart. service --status-all and others, by systemd systemctl -l --type service --all or as root systemctl -r --type service --all However software still using the init system will likely be listed in /etc/init.d Looking through all of those will yield most services ...


68

The problem is service strips all environment variables but TERM, PATH and LANG which is a good thing. If you are executing the script directly nothing removes the environment variables so everything works. You don't want to rely on external environment variables because at startup the environment variable probably isn't present and your init system ...


67

On Debian jessie try: service --status-all. It is in the sysvinit-utils package.


57

Figures that I'd figure this out on my own. The clue was here, in the user service output: Dec 23 19:43:27 redmine systemd[613]: Reached target Default. My unit was asking to be loaded with multi-user.target, but there is no such target in the user systemd. I changed this to default.target in the unit file, disabled and re-enabled the service, and it now ...


54

Ubuntu is a systemd system, where the service status command actually calls systemctl status, and systemctl has a --no-pager option that does exactly what you're looking for. So you may be better off using the straight systemctl command in your script. sudo systemctl --no-pager status supervisor EDIT: env var SYSTEMD_PAGER Another way, as pointed out by ...


51

Wheezy uses SysV init, and all the services are controlled with special shell scripts in /etc/init.d, so ls /etc/init.d will list them. These files also contain a description of the service at the top, and the directory contains a README. Some but not all of them have a .sh suffix, you should leave that off when using, eg., update-rc.d.


48

I don't know about raspbian, but since it is derived from Debian, I assume nohup will be available too. Instead of running a process as, $ proc & try to use: $ nohup proc & The nohup will prevent the process from being terminated when the terminal disconnects. HTH.


47

You shouldn't need to restart NFS every time you make a change to /etc/exports. All that's required is to issue the appropriate command after editing the /etc/exports file: $ exportfs -ra Excerpt from the official Red Hat documentation titled: 21.7. The /etc/exports Configuration File. excerpt When issued manually, the /usr/sbin/exportfs command allows ...


47

The notion of daemon is attached to processes, not files. For this reason, there is no sense in "finding daemons on the filesystem". Just to make the notion a little clearer : a program is an executable file (visible in the output of ls) ; a process is an instance of that program (visible in the output of ps). Now, if we use the information that I gave in ...


44

Your question was a little lacking in details, so I'm assuming that you mean that you typed the command to start your server on the console of your Pi, and it executed in the foreground. If this is the case, you have five options, ordered by complexity to implement: Use @f-tussel's answer. Since you're new to GNU/Linux, the & symbol tells the shell ...


39

Just add all needed commands to sudoers separately: %webteam cms051=/usr/bin/systemctl restart httpd.service %webteam cms051=/usr/bin/systemctl stop httpd.service %webteam cms051=/usr/bin/systemctl start httpd.service %webteam cms051=/usr/bin/systemctl status httpd.service


37

As others have noted, the answer is all about runlevels which are basically the modes of operation of an operating system. On Linux, these are usually: ID Name Description 0 Halt Shuts down the system. 1 Single-user Mode Mode for administrative tasks. 2 Multi-user Mode ...


34

Have you tried acpipowerbutton from this command set? VBoxManage controlvm <uuid>|<name> pause|resume|reset|poweroff|savestate| acpipowerbutton|acpisleepbutton| Edit after reading the comments: You can use acpid or other acpi utilities to make it graceful. Also, can you provide ...


34

less will normally turn its pager mode off if it detects that its output is not a terminal. So you could try making your command's output not-a-terminal by running something like: sudo service supervisor status | cat


29

I would start with the Systemd manual pages. They represent a comprehensive resource of the system and services. There is also the freedesktop Systemd FAQs.


29

If you'd like to reuse your code sample, it could look something like: #!/bin/bash case "$1" in start) /path/to/hit.sh & echo $!>/var/run/hit.pid ;; stop) kill `cat /var/run/hit.pid` rm /var/run/hit.pid ;; restart) $0 stop $0 start ;; status) if [ -e /var/run/hit.pid ]; then echo hit.sh is running, pid=`cat /var/...


28

@jofel's answer was exactly what I needed to get a working setup. POsting this for anyone else stumbling on this question. I needed a way to have capistrano restart my Ruby application after deploying from my local machine. That means I needed passwordless access to restarting systemd services. THIS is what I have and it works wonderfully! Note: my user and ...


27

A background-job (ie. started with &) still has it's stdin, stdout and stderr connected to the terminal it was started in. It may suddenly write (eg. error-messages) to the terminal ("disturbing" the job in the foreground) or pause waiting for input from the keyboard (you must first put it in the foreground). You may of course redirect stdout and ...


24

I believe CentOS 7 and above uses systemd. If that is the case for your system, try the following: Place the script commands you wish to run in /usr/bin/myscript. Remember to make the script executable with chmod +x. Create the following file: /usr/lib/systemd/system/my.service [Unit] Description=My Script [Service] Type=forking ExecStart=/usr/bin/...


23

These are runlevels and are a System V-style initiation used by most *NIX systems (with the notable exception of systemd-based systems). When booting the kernel/user decides what runlevel should it run and execute only that runlevel. Meaning that depending the runlevel you can boot up with a different set of programs. There are runlevels for halt and reboot ...


22

You need to create two files: one for service, other for timer with same name. example: /etc/systemd/system/test.service [Unit] Description=test job [Service] Type=oneshot ExecStart=/bin/bash /tmp/1.sh /etc/systemd/system/test.timer [Unit] Description=test [Timer] OnUnitActiveSec=10s OnBootSec=10s [Install] WantedBy=timers.target after that reload ...


18

as I mentioned in the comment: as Wikipedia link mention: In Windows NT operating systems, a Windows service is a computer program that operates in the background.[1] It is similar in concept to a Unix daemon. A daemon is a type of program on Unix-like operating systems that runs unobtrusively in the background, rather than under the direct control of a ...


16

Rather than code this up yourself, consider using Vagrant, which is built to instantiate and control virtualbox instances. The documentation is excellent and I suggest that you check it out rather than attempting to roll your own. The long and short of it is that you create a simple control file and then run vagrant up to start as many VirtualBox instances ...


16

From man systemctl: ENVIRONMENT ... $SYSTEMD_PAGER Pager to use when --no-pager is not given; overrides $PAGER. Setting this to an empty string or the value "cat" is equivalent to passing --no-pager. $SYSTEMD_LESS Override the default options passed to less ("FRSXMK"). So, somewhere in your environment initialization, set:...


16

Nmap’s Ncat can do this, with its -c or -e options: nc -l -c bc will listen on the default port (31337) and, when a connection is established, run bc with its standard input and output connected to the socket. nc localhost 31337 will then connect to a “remote” bc and you can then enter bc expressions and see their result. socat can do this too (thanks ...


15

You can use cron if your version has the @reboot feature. From man 5 crontab: Instead of the first five fields, one of eight special strings may appear: string meaning ------ ------- @reboot Run once, at startup. … You can edit a user-local crontab with the command crontab -e without root privileges. Then add the ...


15

It seems you are running a system with systemd yet you are using sysV commands. Did you create a sysV init script or a systemd unit file? State active (exited) means that systemd has successfully run the commands but that it does not know there is a daemon to monitor. If there is you must define it in the unit file by configuring the Type and ExecStart ...


Only top voted, non community-wiki answers of a minimum length are eligible