When I try to start the apache web server it throws an exception that says that it doesn't recognize the variables in envvars
I included an image for you to see, I believe my envvars file is fine.
sorry if this is a newbie's question but I am a newbie in apache.
this is the image, top part is the exception, bottom part is the envvars file
Could you check if "/var/run/apache2" folder is not missing?
If yes, you can try creating the folder:
mkdir /var/run/apache2
After that, please run the following command:
source /etc/apache2/envvars
Lastly, you can restart your apache:
sudo systemctl stop apache2
sudo systemctl start apache2
or
sudo systemctl restart apache2
Related
Im trying to run my Hello World application using a service in the systend file. the steps i followed
mkdir ~/HelloWorld
cd ~/HelloWorld
dotnet new console
sudo mkdir /srv/HelloWorld # Create directory /srv/HelloWorld
sudo chown yourusername /srv/HelloWorld # Assign ownership to yourself of the directory
dotnet publish -c Release -o /srv/HelloWorld
/srv/HelloWorld/HelloWorld # it outputs'Hello World!'
I then create the HelloWorld.service file:
[Unit]
Description=Hello World console application
[Service]
ExecStart=/srv/HelloWorld/HelloWorld
SyslogIdentifier=HelloWorld
User=admin
[Install]
WantedBy=multi-user.target
I then copy the file to systemd
sudo cp HelloWorld.service /etc/systemd/system/HelloWorld.service
sudo systemctl daemon-reload
sudo systemctl start HelloWorld
sudo systemctl status HelloWorld
##When runing status it gives me
Acrive failed (Result:exit-code)
Process ExecStart=/srv/HelloWorld/HelloWorld (code=exited, status=203/EXEC)
(When i run my Heloworld using "/srv/HelloWorld/HelloWorld " in the console it does log Hello WOrld )
I'm assuming you were following my blog post on running console apps on Linux (RHEL), based on the commands and comments that are matching. Thank you for reading and sorry you ran into issues. I happen to be refreshing this blog post and ran into the same issue as you, which is why I started Googling and found your question.
Unfortunately, RHEL and dotnet made some changes and the original instructions don't work anymore. Luckily, I was able to resolve it by making some modifications to the service file:
[Unit]
Description=Hello World console application
[Service]
# systemd will run this executable to start the service
ExecStart=/usr/bin/dotnet /srv/HelloWorld/HelloWorld.dll
# to query logs using journalctl, set a logical name here
SyslogIdentifier=HelloWorld
# Use your username to keep things simple.
# If you pick a different user, make sure dotnet and all permissions are set correctly to run the app
# To update permissions, use 'chown yourusername -R /srv/HelloWorld' to take ownership of the folder and files,
# Use 'chmod +x /srv/HelloWorld/HelloWorld' to allow execution of the executable file
User=admin
# This environment variable is necessary when dotnet isn't loaded for the specified user.
# To figure out this value, run 'env | grep DOTNET_ROOT' when dotnet has been loaded into your shell.
Environment=DOTNET_ROOT=/usr/lib64/dotnet
[Install]
WantedBy=multi-user.target
Specifically, pay attention to how I'm invoking the dotnet executable and passing the path to the HelloWorld.dll as an argument. This is also what the HelloWorld executable file is supposed to do, but for some reason, no longer works.
I'm not sure if you're using RHEL or how you installed .NET, so you may want to replace the path to the dotnet executable (/usr/bin/dotnet), to the path where your dotnet executable is loaded.
The easiest way to find this path is by running which dotnet.
Alternatively, you can find the path by running dotnet --info to figure out where the SDK is installed, and start digging for the dotnet executable.
Also, the DOTNET_ROOT env variable had to be set in the service for me. I used the env | grep DOTNET_ROOT command to find the correct value for the env variable.
Next time, feel free to message me, so I can be notified and update my content more quickly. Let me know if this works!
I have a simple script
#!/usr/bin/env python
# coding: utf-8
i=0
while (True):
print(i)
i=i+1
I want this script to run in background
If the server crashes, I want it to automatically restart an pick where the program left of
How do I do that
You have tu run your script as a service:
The file must have .service extension under /lib/systemd/system/ directory.
Now Your system service has been added to your service. Let’s reload the systemctl daemon to read new file. You need to reload this deamon each time after making any changes in in .service file.
sudo systemctl daemon-reload
Now enable the service to start on system boot, also start the service using the following commands.
sudo systemctl enable dummy.service
sudo systemctl start dummy.service
I personally use supervisord to handle processes. To make your script start where it left off you need some kind of persistence, like a file or a database where you can put the last state of your script and read at the restart.
I have followed some posts and tutorials as well to create a script to start meteor project when server restart. i have followed answer mentioned in : How to run meteor on startup on Ubuntu server
Then I gave executable permission to script with "chmod +x meteor-server.sh".
I have tried to put this script in /etc/init.d and /etc/init folders but meteor project does not start at the reboot. I'm using ubuntu 16.04.
I would be grateful if you can show me the fault that i have done. Following code is my "meteor.server.sh" script file.
# meteorjs - meteorjs job file
description "MeteorJS"
author "Jc"
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect fork
# Run before process
pre-start script
cd /home/me/projects/cricket
echo ""
end script
# Start the process
exec meteor run -p 4000 --help -- production
First of all, there's already a very good tool mupx that allows you to deploy meteor projects to your own architecture, so there's really no need to do it by yourself unless you have a very good.
If you really need to deploy manually, this will take several steps. I am not going to cover all the details because you're specifically asking about the startup script and the remaining instruction should be easily accessible in the Internet.
1. Prepare your server
Install MongoDB unless you are planning to use a remote database.
Install NodeJS.
Install reverse proxy server, e.g. Nginx, or haproxy.
Install Meteor, which we will use as the build tool only.
2. Build your app
I am assuming here that you already have the source code of your app put on the server to which you're planning to deploy. Go to your project root and run the following command:
meteor build /path/to/your/build --directory
Please note that if /path/to/your/build exists it will be recursively deleted first, so be careful with that.
3. Install app dependencies
Go to /path/to/your/build/bundle/programs/server and run:
npm install
4. Prepare a run.sh script
The file can be of the following form:
export MONGO_URL="mongodb://127.0.0.1:27017/appName"
export ROOT_URL="http://myapp.example.com"
export PORT=3000
export METEOR_SETTINGS="{}"
/usr/bin/env node /path/to/your/build/bundle/main.js
I will assume you put it in /path/to/your/run.sh. A couple of notes here:
This form of MONGO_URL assumes you have MongoDB installed locally.
You will need to instruct your reverse proxy server to point your app trafic to port 3000.
METEOR_SETTINGS should be the output of JSON.stringify(settings) of whatever settings object you may have.
5. Prepare upstart script
With all the preparations we've made so far, the script can be as simple as
description "node.js server"
start on (net-device-up and local-filesystems and runlevel [2345])
stop on runlevel [016]
respawn
script
exec /path/to/your/run.sh
end script
This file should go to /etc/init/appName.conf.
Finally i got it to work. I have used following 2 scripts to run meteor on the startup.
First i put this service file(meteor.service) in /etc/systemd/system
[Unit]
Description = My Meteor Application
[Service]
ExecStart=/etc/init.d/meteor.sh
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=meteor
[Install]
WantedBy=multi-user.target
I have called a scipt using this service. I put this following script(meteor.sh) in /etc/init.d
#!/bin/sh -
description "Meteor Projects"
author "Janitha"
#start service on following run levels
start on runlevel [2345]
#stop service on following run levels
stop on runlevel [016]
#restart service if crashed
respawn
#set user/group to run as
setuid janitha
setgid janitha
chdir /home/janitha/projects/cricket_app
#export HOME (for meteor), change dir to plex requests dir, and run meteor
script
export HOME=/home/janitha
exec meteor
end script
I make both these file executable by using
chmod +x meteor.service
chmod +x meteor.sh
And i have used following two commands to enable the service
systemctl daemon-reload
systemctl enable meteor.service
I used this configurations successfully
In /etc/init.d add a file called meteor.sh
#!/bin/sh
export HOME="/home/user"
cd /home/user/meteor/sparql-fedquest
meteor --allow-superuser
You must give executions permissions to meteor.sh
sudo chmod 644 meteor.sh
Also you must create meteor.service in /etc/systemd/system
[Unit]
Description =Portal of bibliographic resources of University of Cuenca
Author = Freddy Sumba
[Service]
ExecStart=/etc/init.d/meteor.sh
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=meteor
[Install]
WantedBy=multi-user.target
Also you must give permissions to meteor.service
$ sudo chmod 644 meteor.service
Then, we need add the service to this start each time that the server reboot
$ systemctl enable meteor.service
And finally start the service
$ service meteor start
I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.
ERROR:
dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
Side note:
Node also stopped working on my machine around the same time that I got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
Any help would be much appreciated!
This should work to ensure that the directory is set up in the right place so that Mongo can find it:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
You need to create the directory on root /data/db or set any other path with the following command :
mongod --dbpath /srv/mongodb/
See the example link
I solved the problem with :
sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongod start
I solve the same problem with this.
Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:
sudo systemctl enable mongodb
sudo systemctl start mongodb
or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:
sudo service mongodb enable
sudo service mongodb start
If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:
rc-update add mongodb default
/etc/init.d/mongodb start
In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):
add the following line to /etc/rc.conf:
mongod_enable="YES"
then:
sudo service mongod start
After starting the service, an unpriveleged user can use mongo, and each user will have separate data.
I also got the error that "The file /data/db doesn't exist" when I tried to save my file using the "mkdir -p /data/db" command(using both with and without sudo command). But later on one site, a person named Emil answered that the path "/data/db" no longer works on Mac, so use "~/data/db" instead
i.e., use the command
mkdir -p ~/data/db
instead of previous command.
Moreover, use
mongod --dbpath ~/data/db
to run mongod
It worked for me, hope it work for others too facing the same problem
I have a linux server that contains many websites under vhosts, once I deleted an alt site the apache2 coud not be restarted indecating this message in the error log:
#eror log
(2)No such file or directory: apache2: could not open error log file /var/www/vhosts/deleted_Site/logs/error.log.
Unable to open logs
How can I stop that so I can start my apache2
You should modify your apache configuration, for instance in conf.d/, all configuration related to your old website, especially for error logs (look for access logs and errors logs directives specification, somewhere in your conf files, apache2.conf, httpd.conf, sites-enabled, mods or what/wherever it is).
To resolve this error, you need to stop other process using same port. In some of cases it is nginx. you can stop it
sudo /etc/init.d/nginx stop
Turn off any servers using the same port. For example to turn off nginx try this:
sudo systemctl stop nginx